|
1 | 1 | # Get NPM packages
|
2 | | -FROM node:14-alpine AS dependencies |
| 2 | +FROM node:14-alpine AS builder |
3 | 3 | RUN apk add --no-cache libc6-compat
|
4 | | -WORKDIR /app |
5 | | -COPY package.json package-lock.json ./ |
6 | | -RUN npm ci --only=production |
7 | 4 |
|
8 | | -# Rebuild the source code only when needed |
9 | | -FROM node:14-alpine AS builder |
10 | 5 | WORKDIR /app
|
| 6 | +COPY package.json package-lock.json ./ |
11 | 7 | COPY . .
|
12 | | -COPY --from=dependencies /app/node_modules ./node_modules |
13 | | -RUN npm run build |
| 8 | + |
| 9 | +RUN npm ci --only=production && npm run build |
14 | 10 |
|
15 | 11 | # Production image, copy all the files and run next
|
16 | 12 | FROM node:14-alpine AS runner
|
17 | 13 | WORKDIR /app
|
18 | | - |
19 | 14 | ENV NODE_ENV production
|
20 | 15 |
|
21 | | -RUN addgroup -g 1001 -S nodejs |
22 | | -RUN adduser -S nextjs -u 1001 |
23 | | - |
24 | | -COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next |
25 | | -COPY --from=builder /app/node_modules ./node_modules |
26 | | -COPY --from=builder /app/package.json ./package.json |
| 16 | +RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 |
| 17 | +COPY --from=builder --chown=nextjs:nodejs /app . |
27 | 18 |
|
28 | 19 | USER nextjs
|
29 | 20 | EXPOSE 3000
|
|
0 commit comments