|
1 | | -# Build image |
2 | | -FROM node:12.22-alpine AS build |
3 | | -ARG BASE_PATH |
4 | | -ARG DATABASE_TYPE |
| 1 | +# Install dependencies only when needed |
| 2 | +FROM node:16-alpine AS deps |
| 3 | +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. |
| 4 | +RUN apk add --no-cache libc6-compat |
| 5 | +WORKDIR /app |
| 6 | +COPY package.json yarn.lock ./ |
| 7 | +RUN yarn install --frozen-lockfile |
5 | 8 |
|
| 9 | +# Rebuild the source code only when needed |
| 10 | +FROM node:16-alpine AS builder |
6 | 11 | ENV BASE_PATH=$BASE_PATH |
7 | 12 | ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" |
8 | 13 | ENV DATABASE_TYPE=$DATABASE_TYPE |
| 14 | +WORKDIR /app |
| 15 | +COPY --from=deps /app/node_modules ./node_modules |
| 16 | +COPY . . |
9 | 17 |
|
10 | | -WORKDIR /build |
11 | | - |
12 | | -RUN yarn config set --home enableTelemetry 0 |
13 | | -COPY package.json yarn.lock /build/ |
14 | | - |
15 | | -# Install only the production dependencies |
16 | | -RUN yarn install --production --frozen-lockfile |
17 | | - |
18 | | -# Cache these modules for production |
19 | | -RUN cp -R node_modules/ prod_node_modules/ |
20 | | - |
21 | | -# Install development dependencies |
22 | | -RUN yarn install --frozen-lockfile |
| 18 | +# Next.js collects completely anonymous telemetry data about general usage. |
| 19 | +# Learn more here: https://nextjs.org/telemetry |
| 20 | +# Uncomment the following line in case you want to disable telemetry during the build. |
| 21 | +ENV NEXT_TELEMETRY_DISABLED 1 |
23 | 22 |
|
24 | | -COPY . /build |
25 | | -RUN yarn next telemetry disable |
26 | 23 | RUN yarn build |
27 | 24 |
|
28 | | -# Production image |
29 | | -FROM node:12.22-alpine AS production |
| 25 | +# Production image, copy all the files and run next |
| 26 | +FROM node:16-alpine AS runner |
30 | 27 | WORKDIR /app |
31 | 28 |
|
32 | | -# Copy cached dependencies |
33 | | -COPY --from=build /build/prod_node_modules ./node_modules |
| 29 | +ENV NODE_ENV production |
| 30 | +# Uncomment the following line in case you want to disable telemetry during runtime. |
| 31 | +ENV NEXT_TELEMETRY_DISABLED 1 |
| 32 | + |
| 33 | +RUN addgroup --system --gid 1001 nodejs |
| 34 | +RUN adduser --system --uid 1001 nextjs |
34 | 35 |
|
35 | | -# Copy generated Prisma client |
36 | | -COPY --from=build /build/node_modules/.prisma/ ./node_modules/.prisma/ |
| 36 | +# You only need to copy next.config.js if you are NOT using the default configuration |
| 37 | +COPY --from=builder /app/next.config.js ./ |
| 38 | +COPY --from=builder /app/public ./public |
| 39 | +COPY --from=builder /app/package.json ./package.json |
37 | 40 |
|
38 | | -COPY --from=build /build/yarn.lock /build/package.json ./ |
39 | | -COPY --from=build /build/.next ./.next |
40 | | -COPY --from=build /build/public ./public |
| 41 | +# Automatically leverage output traces to reduce image size |
| 42 | +# https://nextjs.org/docs/advanced-features/output-file-tracing |
| 43 | +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ |
| 44 | +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static |
41 | 45 |
|
42 | | -USER node |
| 46 | +USER nextjs |
43 | 47 |
|
44 | 48 | EXPOSE 3000 |
45 | | -CMD ["yarn", "start"] |
| 49 | + |
| 50 | +ENV PORT 3000 |
| 51 | + |
| 52 | +CMD ["node", "server.js"] |
0 commit comments