-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
89 lines (84 loc) · 3.43 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# from https://nextjs.org/docs/deployment#docker-image
# 1. Install node dependencies only when needed
FROM node:alpine3.16 AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY yarn.lock .yarnrc.yml ./
COPY .yarn .yarn
RUN yarn fetch --immutable && yarn cache clean
# 2. Rebuild the source code only when needed
FROM node:alpine3.16 AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# cf https://github.com/webpack/webpack/issues/14532
ENV NODE_OPTIONS=--openssl-legacy-provider
ENV NODE_ENV=production
ARG NEXT_PUBLIC_SENTRY_DSN
ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=$NEXT_PUBLIC_SENTRY_ENVIRONMENT
ARG NEXT_PUBLIC_AGENT_HJID
ENV NEXT_PUBLIC_AGENT_HJID=$NEXT_PUBLIC_AGENT_HJID
ARG NEXT_PUBLIC_AGENT_HJSV
ENV NEXT_PUBLIC_AGENT_HJSV=$NEXT_PUBLIC_AGENT_HJSV
ARG NEXT_PUBLIC_FORMULAIRE_HJID
ENV NEXT_PUBLIC_FORMULAIRE_HJID=$NEXT_PUBLIC_FORMULAIRE_HJID
ARG NEXT_PUBLIC_FORMULAIRE_HJSV
ENV NEXT_PUBLIC_FORMULAIRE_HJSV=$NEXT_PUBLIC_FORMULAIRE_HJSV
ARG NEXT_PUBLIC_API_URL_SDP
ENV NEXT_PUBLIC_API_URL_SDP=$NEXT_PUBLIC_API_URL_SDP
ARG NEXT_PUBLIC_MATOMO_URL
ENV NEXT_PUBLIC_MATOMO_URL=$NEXT_PUBLIC_MATOMO_URL
ARG NEXT_PUBLIC_MATOMO_SITE_AGENT_ID
ENV NEXT_PUBLIC_MATOMO_SITE_AGENT_ID=$NEXT_PUBLIC_MATOMO_SITE_AGENT_ID
ARG NEXT_PUBLIC_MATOMO_SITE_FORMULAIRE_ID
ENV NEXT_PUBLIC_MATOMO_SITE_FORMULAIRE_ID=$NEXT_PUBLIC_MATOMO_SITE_FORMULAIRE_ID
ENV SENTRY_URL=https://sentry.fabrique.social.gouv.fr
ENV SENTRY_PROJECT=app-enfants-du-spectacle
ENV SENTRY_ORG=incubateur
RUN --mount=type=secret,id=sentry_auth_token export SENTRY_AUTH_TOKEN=$(cat /run/secrets/sentry_auth_token); \
npm run build
RUN yarn workspaces focus --production && yarn cache clean
# this should remove dev node module dependencies
RUN npx prisma generate
# Production image, copy all the files and run next
FROM node:alpine3.16 AS runner
RUN apk add --no-cache postgresql-client
WORKDIR /app
ENV NODE_ENV production
ENV NODE_OPTIONS=--openssl-legacy-provider
ENV NEXT_TELEMETRY_DISABLED 1
ARG NEXT_PUBLIC_SENTRY_DSN
ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=$NEXT_PUBLIC_SENTRY_ENVIRONMENT
ARG NEXT_PUBLIC_AGENT_HJID
ENV NEXT_PUBLIC_AGENT_HJID=$NEXT_PUBLIC_AGENT_HJID
ARG NEXT_PUBLIC_AGENT_HJSV
ENV NEXT_PUBLIC_AGENT_HJSV=$NEXT_PUBLIC_AGENT_HJSV
ARG NEXT_PUBLIC_FORMULAIRE_HJID
ENV NEXT_PUBLIC_FORMULAIRE_HJID=$NEXT_PUBLIC_FORMULAIRE_HJID
ARG NEXT_PUBLIC_FORMULAIRE_HJSV
ENV NEXT_PUBLIC_FORMULAIRE_HJSV=$NEXT_PUBLIC_FORMULAIRE_HJSV
ARG NEXT_PUBLIC_API_URL_SDP
ENV NEXT_PUBLIC_API_URL_SDP=$NEXT_PUBLIC_API_URL_SDP
ARG NEXT_PUBLIC_MATOMO_URL
ENV NEXT_PUBLIC_MATOMO_URL=$NEXT_PUBLIC_MATOMO_URL
ARG NEXT_PUBLIC_MATOMO_SITE_AGENT_ID
ENV NEXT_PUBLIC_MATOMO_SITE_AGENT_ID=$NEXT_PUBLIC_MATOMO_SITE_AGENT_ID
ARG NEXT_PUBLIC_MATOMO_SITE_FORMULAIRE_ID
ENV NEXT_PUBLIC_MATOMO_SITE_FORMULAIRE_ID=$NEXT_PUBLIC_MATOMO_SITE_FORMULAIRE_ID
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/next.config.js .
COPY --from=builder /app/package.json .
COPY --from=builder /app/src ./src
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
COPY --from=builder --chown=node:node /app/.next ./.next
USER 1000
EXPOSE 3000
ARG START_SCRIPT=start-prod
ENV START_SCRIPT=$START_SCRIPT
CMD ["sh", "-c", "yarn run $START_SCRIPT"]