From 379b68f1ed8153adf72c61aa26562a3cf33b06c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=81uczak?= Date: Thu, 27 Jun 2024 09:57:02 +0200 Subject: [PATCH] Add CI and fix frequency calculation --- .github/workflows/docker-build.yaml | 49 +++++++++++++++++++++++++++++ Dockerfile | 4 +-- Taskfile.yml | 9 ++++++ src/index.ts | 4 +-- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker-build.yaml diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml new file mode 100644 index 0000000..2264c18 --- /dev/null +++ b/.github/workflows/docker-build.yaml @@ -0,0 +1,49 @@ +--- +name: Build and Push Docker Image + +on: + push: + branches: + - "master" + tags: + - "v*" + pull_request: + branches: + - "master" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: 🏧 Checkout Repository + uses: actions/checkout@v4 + + - name: 🛠️ Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: 📝 Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: thevops/youtube-tracker + tags: | + type=sha + type=semver,pattern={{raw}} + type=ref,event=branch + type=ref,event=pr + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 📦 Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/arm64 + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 12a3db1..bac7718 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:1.1.4-alpine as base +FROM oven/bun:1.1.4-alpine AS base # install dependencies into temp directory # this will cache them and speed up future builds @@ -12,7 +12,7 @@ RUN cd /temp/prod && bun install --frozen-lockfile --production # final image -FROM base as release +FROM base AS release RUN apk add -q --progress --update --no-cache dumb-init diff --git a/Taskfile.yml b/Taskfile.yml index 92b10d7..2c778b8 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -11,6 +11,15 @@ tasks: desc: Start the app cmds: - bun run src/index.ts config/production.yaml + env: + NODE_ENV: production + + run-script: + desc: Run a single script + cmds: + - bun {{.CLI_ARGS}} + env: + NODE_ENV: production # # Build diff --git a/src/index.ts b/src/index.ts index 9ec847e..a9738d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,9 +7,9 @@ async function main() { for (const feed of Config.feeds) { logger.debug(`Checking feed: ${feed.name}`); - // Get current time minus the frequency (minutes) plus a buffer of 5 minutes + // Get current time and subtract the frequency time (plus 5 minutes more as a buffer) in minutes const previous_check = new Date( - Date.now() - Config.frequency * 60000 + 5 * 60000, + Date.now() - (Config.frequency + 5) * 60000, ); logger.debug(`Previous check: ${previous_check.toISOString()}`);