From 6f5aac9734b8aa28e7b716456fad4af7a38b4ac5 Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Wed, 6 Aug 2025 21:41:00 +0000 Subject: [PATCH] feat: deployments --- .github/workflows/deploy.yml | 47 ++++++++++++++++++++++++++++++++++++ Dockerfile | 32 ++++++++++++++++++++++++ package.json | 4 --- src/index.ts | 2 -- 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..2044db2 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,47 @@ +name: Publish Docker image + +on: + push: + branches: + - main + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: srizan10/flight-slack + tags: latest + + - name: Build and push Docker image + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Emit a webhook to the server + env: + AUTH_HEADER: ${{ secrets.WHSERVER_TOKEN }} + run: | + curl -X POST \ + -H "Authorization: $AUTH_HEADER" \ + https://webhooks.srizan.dev/hooks/flight-slack \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29083db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM oven/bun:alpine AS builder + +WORKDIR /app + +COPY package.json bun.lock ./ + +RUN bun install --frozen-lockfile + +COPY . . + +RUN bunx prisma generate + +FROM oven/bun:alpine AS production + +WORKDIR /app + +RUN addgroup -g 1001 -S bunjs && \ + adduser -S bunjs -u 1001 + +COPY package.json bun.lock ./ + +RUN bun install --frozen-lockfile --production && \ + bun pm cache rm + +COPY --from=builder /app/src ./src +COPY --from=builder /app/prisma ./prisma +COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma + +RUN chown -R bunjs:bunjs /app +USER bunjs + +CMD ["bun", "run", "src/index.ts"] \ No newline at end of file diff --git a/package.json b/package.json index b89f112..b6d4764 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,10 @@ "typescript": "^5" }, "dependencies": { - "@keyv/sqlite": "^4.0.5", "@prisma/client": "^6.11.1", - "@samocodes/bun-cache": "^1.0.9", "@slack/bolt": "^4.4.0", - "chrono-node": "^2.8.3", "dayjs": "^1.11.13", "geo-tz": "^8.1.4", - "keyv": "^5.3.4", "ky": "^1.8.1" } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 79b9e5e..71a45a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import { PrismaClient } from '@prisma/client'; -import BunCache from '@samocodes/bun-cache'; import { App } from '@slack/bolt'; import { OpenskyService } from './util/opensky'; import { FlightAware, type ScheduledDeparture } from './util/flightAware'; @@ -18,7 +17,6 @@ export const app = new App({ export const db = new PrismaClient(); export const airports = new Airports(); -export const cache = new BunCache(); export const openSky = new OpenskyService(); export const flightAware = new FlightAware(); export const adsbDb = new AdsBDB();