-
Notifications
You must be signed in to change notification settings - Fork 11
/
Dockerfile
57 lines (40 loc) · 1.31 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Dockerfile that produce Lightweight runtime images
# Inspired by https://github.com/zeit/next.js/issues/121#issuecomment-541399420
# -- BASE STAGE --------------------------------
FROM node:16-alpine AS base
WORKDIR /src
COPY package*.json ./
RUN npm ci --no-audit
# -- CHECK STAGE --------------------------------
FROM base AS check
ARG CI
ENV CI $CI
COPY . .
RUN npm run lint
RUN npm test
# -- BUILD STAGE --------------------------------
FROM base AS build
# Define build arguments & map them to environment variables
ARG GTM_CONTAINER_ID
ENV GTM_CONTAINER_ID $GTM_CONTAINER_ID
ARG SITE_URL
ENV SITE_URL $SITE_URL
# Build the project and then dispose files not necessary to run the project
# This will make the runtime image as small as possible
COPY . .
RUN npx next telemetry disable > /dev/null
RUN npm run build
RUN npm prune --production --no-audit
RUN rm -rf .next/cache
# -- RUNTIME STAGE --------------------------------
FROM node:16-alpine AS runtime
WORKDIR /usr/app
COPY --from=build /src/package.json ./package.json
COPY --from=build /src/node_modules ./node_modules
COPY --from=build /src/.next ./.next
COPY --from=build /src/intl/index.js ./intl/index.js
COPY --from=build /src/public ./public
COPY --from=build /src/next.config.js ./next.config.js
ENV PORT 3000
EXPOSE $PORT
CMD npm start -- -p $PORT