generated from mission-apprentissage/template-apprentissage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
136 lines (98 loc) · 4.21 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Temporary solution freeze NodeJs version https://github.com/vercel/next.js/discussions/69326
# https://github.com/vercel/next.js/issues/69150
FROM node:22.6-slim AS builder_root
WORKDIR /app
RUN yarn set version 3.3.1
COPY .yarn /app/.yarn
COPY package.json package.json
COPY yarn.lock yarn.lock
COPY .yarnrc.yml .yarnrc.yml
COPY ui/package.json ui/package.json
COPY server/package.json server/package.json
COPY shared/package.json shared/package.json
COPY sdk/package.json sdk/package.json
RUN --mount=type=cache,target=/app/.yarn/cache yarn install --immutable
COPY . .
RUN yarn typecheck
FROM builder_root AS root
WORKDIR /app
##############################################################
###################### SERVER ##########################
##############################################################
# Rebuild the source code only when needed
FROM root AS builder_server
WORKDIR /app
RUN yarn workspace server build
# Removing dev dependencies
RUN --mount=type=cache,target=/app/.yarn/cache yarn workspaces focus --all --production
RUN mkdir -p /app/shared/node_modules && mkdir -p /app/sdk/node_modules && mkdir -p /app/server/node_modules
# Production image, copy all the files and run next
FROM node:22-slim AS server
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates curl && update-ca-certificates && apt-get clean
ENV NODE_ENV=production
ARG PUBLIC_PRODUCT_NAME
ENV PUBLIC_PRODUCT_NAME=$PUBLIC_PRODUCT_NAME
ARG PUBLIC_VERSION
ENV PUBLIC_VERSION=$PUBLIC_VERSION
COPY --from=builder_server /app/server ./server
COPY --from=builder_server /app/shared ./shared
COPY --from=builder_server /app/sdk ./sdk
COPY --from=builder_server /app/node_modules ./node_modules
COPY --from=builder_server /app/server/node_modules ./server/node_modules
COPY --from=builder_server /app/sdk/node_modules ./sdk/node_modules
COPY --from=builder_server /app/shared/node_modules ./shared/node_modules
COPY ./server/static /app/server/static
EXPOSE 5000
WORKDIR /app/server
ENV NODE_OPTIONS=--max_old_space_size=2048
CMD ["node", "dist/index.js", "start"]
##############################################################
###################### UI ##########################
##############################################################
# Rebuild the source code only when needed
FROM root AS builder_ui
WORKDIR /app
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1
ARG PUBLIC_REPO_NAME
ENV NEXT_PUBLIC_PRODUCT_REPO=$PUBLIC_REPO_NAME
ARG PUBLIC_PRODUCT_NAME
ENV NEXT_PUBLIC_PRODUCT_NAME=$PUBLIC_PRODUCT_NAME
ARG PUBLIC_VERSION
ENV NEXT_PUBLIC_VERSION=$PUBLIC_VERSION
ARG PUBLIC_ENV
ENV NEXT_PUBLIC_ENV=$PUBLIC_ENV
RUN yarn workspace ui build
# RUN --mount=type=cache,target=/app/ui/.next/cache yarn --cwd ui build
# Production image, copy all the files and run next
FROM node:22-slim AS ui
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates curl && update-ca-certificates && apt-get clean
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1
ARG PUBLIC_REPO_NAME
ENV NEXT_PUBLIC_PRODUCT_REPO=$PUBLIC_REPO_NAME
ARG PUBLIC_PRODUCT_NAME
ENV NEXT_PUBLIC_PRODUCT_NAME=$PUBLIC_PRODUCT_NAME
ARG PUBLIC_VERSION
ENV NEXT_PUBLIC_VERSION=$PUBLIC_VERSION
ARG PUBLIC_ENV
ENV NEXT_PUBLIC_ENV=$PUBLIC_ENV
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# You only need to copy next.config.mjs if you are NOT using the default configuration
COPY --from=builder_ui --chown=nextjs:nodejs /app/ui/next.config.mjs /app/
COPY --from=builder_ui --chown=nextjs:nodejs /app/ui/public /app/ui/public
COPY --from=builder_ui --chown=nextjs:nodejs /app/ui/package.json /app/ui/package.json
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder_ui --chown=nextjs:nodejs /app/ui/.next/standalone /app/
COPY --from=builder_ui --chown=nextjs:nodejs /app/ui/.next/static /app/ui/.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
CMD ["node", "ui/server"]