Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Successful in 11s
Podman Rootless Demo / build-backend (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Failing after 57s
Podman Rootless Demo / deploy-prod (push) Has been skipped
58 lines
1.5 KiB
Docker
58 lines
1.5 KiB
Docker
# ---------- build ----------
|
|
FROM docker.io/node:20-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
# Clean any existing cache before starting
|
|
RUN npm cache clean --force
|
|
|
|
# install deps (needs dev deps for build)
|
|
COPY package*.json ./
|
|
RUN npm cache clean --force && npm install --prefer-offline --no-audit --no-fund && npm cache clean --force
|
|
|
|
# app source
|
|
COPY . .
|
|
|
|
# disable telemetry; let Next control NODE_ENV during build
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Build-time environment variables for Next.js public config
|
|
ARG NEXT_PUBLIC_API_HOST=127.0.0.1
|
|
ARG NEXT_PUBLIC_API_PORT=3001
|
|
ENV NEXT_PUBLIC_API_HOST=${NEXT_PUBLIC_API_HOST}
|
|
ENV NEXT_PUBLIC_API_PORT=${NEXT_PUBLIC_API_PORT}
|
|
|
|
RUN npm run build
|
|
# Clean up unnecessary files to save space after build
|
|
RUN rm -rf node_modules .next/cache
|
|
|
|
# ---------- runner (standalone) ----------
|
|
FROM docker.io/node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
# runtime env
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=127.0.0.1
|
|
|
|
# minimal probe tool
|
|
RUN apk add --no-cache wget
|
|
|
|
# copy standalone artifacts
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
|
|
# non-root (optional)
|
|
RUN addgroup --system --gid 1001 nodejs \
|
|
&& adduser --system --uid 1001 nextjs \
|
|
&& chown -R nextjs:nodejs /app
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
# healthcheck (no /api prefix)
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget -qO- http://127.0.0.1:${PORT}/ >/dev/null 2>&1 || exit 1
|
|
|
|
CMD ["node", "server.js"]
|