From be4bdf7cbe5fd2cc58697e5308bfb34ba8af3242 Mon Sep 17 00:00:00 2001 From: Hector Ros Date: Mon, 19 Jan 2026 22:48:13 +0100 Subject: [PATCH] Add CI/CD: Dockerfile + Gitea Actions workflow - Multi-stage Dockerfile with Bun 1.3.6 - Gitea Actions workflow for auto-build - Push to git.fuq.tv container registry - Build cache optimization Co-Authored-By: Claude Sonnet 4.5 (1M context) --- .dockerignore | 11 ++++++++ .gitea/workflows/build.yml | 52 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 23 +++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/build.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..04985e3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +.git +.gitignore +.env +.env.* +!.env.example +*.log +dist +.DS_Store +README.md +.cursor diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..24a9ac8 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,52 @@ +name: Build and Push Backend + +on: + push: + branches: [main, develop] + tags: + - 'v*' + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: git.fuq.tv/admin/aiworker-backend + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Login to Gitea Registry + uses: docker/login-action@v3 + with: + registry: git.fuq.tv + username: admin + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=git.fuq.tv/admin/aiworker-backend:buildcache + cache-to: type=registry,ref=git.fuq.tv/admin/aiworker-backend:buildcache,mode=max + + - name: Image digest + run: echo ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e28f5e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# AiWorker Backend - Docker Image +FROM oven/bun:1.3.6-alpine AS base +WORKDIR /app + +# Install dependencies +FROM base AS install +RUN mkdir -p /temp/prod +COPY package.json bun.lockb /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# Copy source +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY . . + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ + CMD bun fetch http://localhost:3000/api/health || exit 1 + +# Run +USER bun +EXPOSE 3000 +ENTRYPOINT [ "bun", "src/index.ts" ]