| 1 | # syntax=docker/dockerfile:1 |
| 2 | # Build context: repo root |
| 3 | # docker build -f apps/web/Dockerfile -t struxa-web . |
| 4 | |
| 5 | # ── builder: install + compile (Bun for install, next build via Bun) ───────── |
| 6 | FROM oven/bun:1.3.5-alpine AS builder |
| 7 | WORKDIR /repo |
| 8 | |
| 9 | # Install deps — layer cached until lockfile or any package.json changes |
| 10 | COPY bun.lock package.json ./ |
| 11 | COPY apps/web/package.json ./apps/web/ |
| 12 | COPY apps/watchkeeper/package.json ./apps/watchkeeper/ |
| 13 | COPY packages/db/package.json ./packages/db/ |
| 14 | COPY packages/api/package.json ./packages/api/ |
| 15 | COPY packages/auth/package.json ./packages/auth/ |
| 16 | COPY packages/env/package.json ./packages/env/ |
| 17 | COPY packages/ui/package.json ./packages/ui/ |
| 18 | COPY packages/config/package.json ./packages/config/ |
| 19 | COPY packages/payments/package.json ./packages/payments/ |
| 20 | RUN bun install --frozen-lockfile |
| 21 | |
| 22 | # Copy source after install to maximise cache hits |
| 23 | COPY apps/web/ ./apps/web/ |
| 24 | COPY packages/db/src/ ./packages/db/src/ |
| 25 | COPY packages/db/package.json ./packages/db/package.json |
| 26 | COPY packages/api/src/ ./packages/api/src/ |
| 27 | COPY packages/api/package.json ./packages/api/package.json |
| 28 | COPY packages/auth/src/ ./packages/auth/src/ |
| 29 | COPY packages/auth/package.json ./packages/auth/package.json |
| 30 | COPY packages/env/src/ ./packages/env/src/ |
| 31 | COPY packages/env/package.json ./packages/env/package.json |
| 32 | COPY packages/ui/src/ ./packages/ui/src/ |
| 33 | COPY packages/ui/package.json ./packages/ui/package.json |
| 34 | COPY packages/config/ ./packages/config/ |
| 35 | COPY packages/payments/src/ ./packages/payments/src/ |
| 36 | COPY packages/payments/package.json ./packages/payments/package.json |
| 37 | COPY package.json tsconfig.json ./ |
| 38 | |
| 39 | ENV NEXT_TELEMETRY_DISABLED=1 |
| 40 | ENV NODE_ENV=production |
| 41 | # Prevents @t3-oss/env-core from failing during build without runtime secrets |
| 42 | ENV SKIP_ENV_VALIDATION=1 |
| 43 | |
| 44 | ARG APP_VERSION="" |
| 45 | ARG COMMIT_SHA="" |
| 46 | ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION |
| 47 | ENV NEXT_PUBLIC_COMMIT_SHA=$COMMIT_SHA |
| 48 | |
| 49 | RUN cd apps/web && bun run build |
| 50 | |
| 51 | # ── runner: minimal Node image for standalone Next.js ──────────────────────── |
| 52 | FROM node:22-alpine AS runner |
| 53 | WORKDIR /app |
| 54 | |
| 55 | ENV NODE_ENV=production |
| 56 | ENV NEXT_TELEMETRY_DISABLED=1 |
| 57 | |
| 58 | RUN addgroup --system --gid 1001 nodejs && \ |
| 59 | adduser --system --uid 1001 nextjs |
| 60 | |
| 61 | COPY --from=builder --chown=nextjs:nodejs /repo/apps/web/.next/standalone ./ |
| 62 | COPY --from=builder --chown=nextjs:nodejs /repo/apps/web/.next/static ./apps/web/.next/static |
| 63 | COPY --from=builder --chown=nextjs:nodejs /repo/apps/web/public ./apps/web/public |
| 64 | |
| 65 | USER nextjs |
| 66 | EXPOSE 3001 |
| 67 | ENV PORT=3001 |
| 68 | ENV HOSTNAME=0.0.0.0 |
| 69 | |
| 70 | CMD ["node", "apps/web/server.js"] |