From 43420e0b2837b4a7f25ddb9a8562a5c6151dfc13 Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Thu, 11 Dec 2025 19:14:13 +0100 Subject: [PATCH] build for prod --- web/.dockerignore | 9 +++++++ web/.gitea/workflows/build.yaml | 32 +++++++++++++++++++++++++ web/Dockerfile | 42 +++++++++++++++++++++++++++++++++ web/next.config.ts | 2 +- web/package.json | 2 +- 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 web/.dockerignore create mode 100644 web/.gitea/workflows/build.yaml create mode 100644 web/Dockerfile diff --git a/web/.dockerignore b/web/.dockerignore new file mode 100644 index 0000000..67b4656 --- /dev/null +++ b/web/.dockerignore @@ -0,0 +1,9 @@ +Dockerfile +.dockerignore +node_modules +.next +.git +.gitignore +*.md +.env*.local +agent/ diff --git a/web/.gitea/workflows/build.yaml b/web/.gitea/workflows/build.yaml new file mode 100644 index 0000000..3dda8ec --- /dev/null +++ b/web/.gitea/workflows/build.yaml @@ -0,0 +1,32 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: git.seaturtle.pw + username: ${{ gitea.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: git.seaturtle.pw/cavepediav2/cavepediav2-web:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..490bb55 --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,42 @@ +FROM node:24-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY package.json package-lock.json* ./ +RUN npm ci --ignore-scripts + +# Build the application +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Skip agent installation in Docker +ENV SKIP_AGENT_INSTALL=true + +RUN npm run build + +# Production image +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/web/next.config.ts b/web/next.config.ts index e9ffa30..68a6c64 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", }; export default nextConfig; diff --git a/web/package.json b/web/package.json index 1f197bd..897e3a0 100644 --- a/web/package.json +++ b/web/package.json @@ -11,7 +11,7 @@ "start": "next start -H 127.0.0.1", "lint": "eslint .", "install:agent": "sh ./scripts/setup-agent.sh || scripts\\setup-agent.bat", - "postinstall": "npm run install:agent" + "postinstall": "if [ -z \"$SKIP_AGENT_INSTALL\" ]; then npm run install:agent; fi" }, "dependencies": { "@ag-ui/client": "^0.0.42",