-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
116 lines (88 loc) · 3.45 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
FROM node:20-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
RUN --mount=type=cache,target=/app/.yarn/cache yarn install --immutable
FROM builder_root AS root
WORKDIR /app
##############################################################
###################### SERVER ##########################
##############################################################
# Rebuild the source code only when needed
FROM root AS builder_server
WORKDIR /app
COPY ./server ./server
COPY ./shared ./shared
RUN yarn --cwd server build
# Removing dev dependencies
RUN --mount=type=cache,target=/app/.yarn/cache yarn workspaces focus --all --production
# Production image, copy all the files and run next
FROM node:20-slim AS server
WORKDIR /app
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt/lists \
apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production
ARG PUBLIC_VERSION
ENV PUBLIC_VERSION=$PUBLIC_VERSION
ARG COMMIT_HASH
ENV COMMIT_HASH=$COMMIT_HASH
COPY --from=builder_server /app/server ./server
COPY --from=builder_server /app/shared ./shared
COPY --from=builder_server /app/node_modules ./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
COPY ./ui ./ui
COPY ./shared ./shared
# 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_VERSION
ENV NEXT_PUBLIC_VERSION=$PUBLIC_VERSION
ARG COMMIT_HASH
ENV COMMIT_HASH=$COMMIT_HASH
ARG PUBLIC_ENV
ENV NEXT_PUBLIC_ENV=$PUBLIC_ENV
RUN yarn --cwd 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:20-slim AS ui
WORKDIR /app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1
ARG PUBLIC_VERSION
ENV NEXT_PUBLIC_VERSION=$PUBLIC_VERSION
ARG COMMIT_HASH
ENV COMMIT_HASH=$COMMIT_HASH
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.js if you are NOT using the default configuration
COPY --from=builder_ui --chown=nextjs:nodejs /app/ui/next.config.js /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"]