CI installs via local Verdaccio and prefers Gitea copies of node/postgres/nginx so staging and prod can still ship when Docker Hub and npmjs are unreachable.
85 lines
3.0 KiB
Docker
85 lines
3.0 KiB
Docker
# CI passes Gitea-hosted dyolink-node (node + dumb-init). See seed-gitea-base-images.ps1.
|
|
ARG NODE_IMAGE=node:20-bookworm-slim
|
|
|
|
# Build stage — produces `.next/standalone` (see next.config.ts output: standalone)
|
|
FROM ${NODE_IMAGE} AS builder
|
|
|
|
# CI passes Verdaccio (http://host.docker.internal:4873). Default is official npm for laptop builds.
|
|
ARG NPM_REGISTRY=https://registry.npmjs.com
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package*.json ./
|
|
# Same as backend: rewrite lockfile hosts to NPM_REGISTRY for this build only.
|
|
ENV NODE_OPTIONS=--max-old-space-size=3072
|
|
RUN --mount=type=cache,target=/root/.npm \
|
|
npm config set registry "${NPM_REGISTRY}" \
|
|
&& npm config set fetch-retries 5 \
|
|
&& npm config set fetch-retry-maxtimeout 120000 \
|
|
&& npm config set maxsockets 5 \
|
|
&& sed -i \
|
|
-e "s|https://registry.npmmirror.com|${NPM_REGISTRY}|g" \
|
|
-e "s|https://registry.npmjs.org|${NPM_REGISTRY}|g" \
|
|
-e "s|https://registry.npmjs.com|${NPM_REGISTRY}|g" \
|
|
-e "s|http://host.docker.internal:4873|${NPM_REGISTRY}|g" \
|
|
package-lock.json \
|
|
&& npm ci --no-audit --no-fund \
|
|
&& test -e node_modules/.bin/next
|
|
|
|
COPY . .
|
|
|
|
ARG NEXT_PUBLIC_API_URL
|
|
ARG NEXT_PUBLIC_APP_URL
|
|
ARG NEXT_PUBLIC_APP_NAME
|
|
ARG NEXT_PUBLIC_SENTRY_DSN
|
|
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
|
|
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
|
ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
|
|
ENV NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME}
|
|
ENV NEXT_PUBLIC_SENTRY_DSN=${NEXT_PUBLIC_SENTRY_DSN}
|
|
ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=${NEXT_PUBLIC_SENTRY_ENVIRONMENT}
|
|
|
|
RUN npm run build
|
|
|
|
# Production — minimal runtime using Next.js standalone bundle
|
|
FROM ${NODE_IMAGE} AS runner
|
|
|
|
USER root
|
|
RUN if ! command -v dumb-init >/dev/null 2>&1; then \
|
|
apt-get update \
|
|
&& apt-get install -y --no-install-recommends dumb-init \
|
|
&& rm -rf /var/lib/apt/lists/*; \
|
|
fi
|
|
|
|
WORKDIR /app
|
|
|
|
RUN groupadd --system --gid 1001 nodejs \
|
|
&& useradd --system --uid 1001 --gid nodejs --home-dir /app --shell /usr/sbin/nologin dyolink
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=0.0.0.0
|
|
|
|
COPY --from=builder --chown=dyolink:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=dyolink:nodejs /app/.next/static ./.next/static
|
|
# Standalone does not include public/; catalog icons are <img src="/prosthesis-catalog/*.svg">.
|
|
COPY --from=builder --chown=dyolink:nodejs /app/public ./public
|
|
|
|
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
|
# Windows git/build context may use CRLF; strip before chmod (fixes dumb-init "No such file or directory").
|
|
RUN sed -i 's/\r$//' /usr/local/bin/docker-entrypoint.sh && chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
USER dyolink
|
|
|
|
EXPOSE 3000
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
|
|
CMD node -e "require('http').get('http://127.0.0.1:3000/', (r) => { process.exit(r.statusCode >= 200 && r.statusCode < 400 ? 0 : 1); }).on('error', () => process.exit(1))"
|
|
|
|
ENTRYPOINT ["dumb-init", "--", "docker-entrypoint.sh"]
|
|
|
|
CMD ["node", "server.js"]
|