53 lines
1.5 KiB
Docker
53 lines
1.5 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
|
|
FROM node:22-alpine AS dependencies
|
|
|
|
WORKDIR /app
|
|
|
|
# npm may build the native SQLite binding when no matching prebuild is available.
|
|
RUN apk add --no-cache python3 make g++
|
|
|
|
ARG NPM_REGISTRY=https://package-mirror.liara.ir/repository/npm/
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
COPY package.json package-lock.json ./
|
|
RUN --mount=type=cache,id=portfolio-npm-node22,target=/root/.npm,sharing=locked \
|
|
npm ci \
|
|
--registry="${NPM_REGISTRY}" \
|
|
--replace-registry-host=registry.npmjs.org \
|
|
--include=optional
|
|
|
|
FROM dependencies AS verification
|
|
|
|
COPY . .
|
|
RUN npm run lint
|
|
RUN npm run typecheck
|
|
RUN --mount=type=cache,id=portfolio-next-node22,target=/app/.next/cache,sharing=locked \
|
|
npm run build
|
|
RUN npm test
|
|
|
|
FROM node:22-alpine AS runtime
|
|
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production \
|
|
NEXT_TELEMETRY_DISABLED=1 \
|
|
HOSTNAME=0.0.0.0 \
|
|
PORT=3000 \
|
|
DATA_DIR=/data
|
|
|
|
RUN addgroup --system --gid 1001 nodejs \
|
|
&& adduser --system --uid 1001 nextjs
|
|
|
|
COPY --from=verification --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=verification --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
COPY --from=verification --chown=nextjs:nodejs /app/public ./public
|
|
RUN mkdir -p .next/cache /data && chown -R nextjs:nodejs .next/cache /data
|
|
|
|
USER nextjs
|
|
EXPOSE 3000
|
|
|
|
HEALTHCHECK --interval=2s --timeout=2s --start-period=3s --retries=30 \
|
|
CMD ["node", "-e", "fetch('http://127.0.0.1:3000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"]
|
|
|
|
CMD ["node", "server.js"]
|