Some checks failed
Build and Push Docker Images / docker (push) Failing after 1m56s
Problem: - NEXT_PUBLIC_* variables must be baked into Next.js build at BUILD TIME - Setting them in docker-compose is too late (bundle already built) - This caused "NEXT_PUBLIC_WREN_API_TOKEN is undefined" errors in production Solution: 1. Updated Dockerfile to accept ARG values for all NEXT_PUBLIC_* variables 2. Set ARGs as ENV variables before npm run build (lines 15-26) 3. Updated CI/CD workflow to pass build-args from Gitea secrets/vars 4. Variables are now baked into the image during build Next Steps: 1. Add these secrets to Gitea repository settings: - NEXT_PUBLIC_WREN_API_TOKEN - NEXT_PUBLIC_FORMSPREE_CONTACT_ID - NEXT_PUBLIC_FORMSPREE_OFFSET_ID - NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY 2. Add this variable to Gitea repository settings: - NEXT_PUBLIC_API_BASE_URL 3. Next push will build image with variables baked in 4. Can simplify docker-compose (remove NEXT_PUBLIC_* from web service) Files Changed: - Dockerfile: Added ARG and ENV declarations before build step - .gitea/workflows/build-deploy.yml: Added build-args to frontend image build 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.5 KiB
Docker
53 lines
1.5 KiB
Docker
# Build Stage
|
|
FROM node:20-alpine AS build
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files and install dependencies
|
|
COPY package*.json ./
|
|
RUN npm ci
|
|
|
|
# Copy the rest of the app
|
|
COPY . .
|
|
|
|
# Accept build arguments for NEXT_PUBLIC_ variables
|
|
# These MUST be provided at build time
|
|
ARG NEXT_PUBLIC_API_BASE_URL
|
|
ARG NEXT_PUBLIC_WREN_API_TOKEN
|
|
ARG NEXT_PUBLIC_FORMSPREE_CONTACT_ID
|
|
ARG NEXT_PUBLIC_FORMSPREE_OFFSET_ID
|
|
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
|
|
|
# Set as environment variables so Next.js can bake them into the build
|
|
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
|
|
ENV NEXT_PUBLIC_WREN_API_TOKEN=$NEXT_PUBLIC_WREN_API_TOKEN
|
|
ENV NEXT_PUBLIC_FORMSPREE_CONTACT_ID=$NEXT_PUBLIC_FORMSPREE_CONTACT_ID
|
|
ENV NEXT_PUBLIC_FORMSPREE_OFFSET_ID=$NEXT_PUBLIC_FORMSPREE_OFFSET_ID
|
|
ENV NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=$NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
|
|
|
# Build Next.js app (standalone mode)
|
|
# NEXT_PUBLIC_ variables are now baked in at build time
|
|
RUN npm run build
|
|
|
|
# Production Stage - Next.js standalone server
|
|
FROM node:20-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy standalone server files from build stage
|
|
COPY --from=build /app/.next/standalone ./
|
|
COPY --from=build /app/.next/static ./.next/static
|
|
COPY --from=build /app/public ./public
|
|
|
|
# Expose port 3000
|
|
EXPOSE 3000
|
|
|
|
# Set environment to production
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Start Next.js server
|
|
# Runtime environment variables (NEXT_PUBLIC_*) can be passed via docker-compose or -e flags
|
|
CMD ["node", "server.js"]
|