1
mirror of https://github.com/xitanggg/open-resume synced 2024-11-03 09:19:21 +01:00

update Docker build to optimize image size

This commit is contained in:
Andrei Mahalean 2023-06-27 09:58:31 +12:00 committed by Xitang Zhao
parent 005342d968
commit 5666e1f405
3 changed files with 10 additions and 30 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
node_modules
.next
.vscode
.git

View File

@ -1,39 +1,14 @@
FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat
FROM node:18-alpine as builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Rebuild the source code only when needed
FROM node:18-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
ENV NEXT_TELEMETRY_DISABLED 1
RUN npm install --include=dev
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/.next/standalone .
COPY --from=builder /app/public ./public
USER nextjs
COPY --from=builder /app/.next/static ./.next/static
EXPOSE 3000
ENV PORT 3000
CMD ["npm", "start"]
CMD ["node", "server.js"]

View File

@ -5,6 +5,7 @@ const nextConfig = {
// building the app. Since pdfjs-dist is only used on client side, we disable
// the canvas package for webpack
// https://github.com/mozilla/pdf.js/issues/16214
output: 'standalone',
webpack: (config) => {
// Setting resolve.alias to false tells webpack to ignore a module
// https://webpack.js.org/configuration/resolve/#resolvealias