generated from notiz-dev/nestjs-prisma-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
227 lines (200 loc) · 6.15 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# syntax=docker/dockerfile:experimental
FROM node:16-bullseye-slim as builder_base
WORKDIR /app
COPY package*.json yarn.lock ./
FROM builder_base as builder_development
ENV NODE_ENV development
RUN \
# This is for the yarn cache. We have to use different caches otherwise both
# this and the production stage will use the same cache and clobber each
# other if they are run in parallel.
--mount=type=cache,id=builder_development_yarn,target=/usr/local/share/.cache/yarn \
# This is to keep the node_modules dir around between builds otherwise yarn
# has to do a fresh install + build whenever the lock file changes.
--mount=type=cache,id=builder_development_node_modules,target=/app/node_modules \
# Defaults to installing all (prod + dev) packages.
yarn --no-progress && \
# The node_modules dir ceases to exist after the build so unless it's copied
# off it can't be copied into the below stages.
cp -r /app/node_modules /app/node_modules.sav
# This is used for both staging and production builds so we can't solely rely
# on the NODE_ENV env var.
# FROM builder_base as builder_production
#
# ENV NODE_ENV production
#
# RUN \
# --mount=type=cache,id=builder_production_yarn,target=/usr/local/share/.cache/yarn \
# --mount=type=cache,id=builder_production_node_modules,target=/app/node_modules \
# yarn --prod --no-progress && \
# cp -r /app/node_modules /app/node_modules.sav
FROM node:16-bullseye-slim as base
ARG UID=2000
ARG USER=apiuser
RUN useradd -m --uid ${UID} --shell /bin/bash ${USER}
ENV PATH /app/node_modules/.bin:$PATH
# FROM base as test_watch
#
# ENV NODE_ENV test
#
# WORKDIR /app
#
# USER ${USER}
#
# # tsc outputs all files on each compilation but let's just watch *.test.js
# # files specifically anyway.
# CMD ["nodemon", "--delay", "1", "--watch", "/app/build", "-e", "js", "--exec", "tap --no-check-coverage build/test/**/*.test.js"]
# FROM base as tsc_watch
#
# ENV NODE_ENV development
#
# WORKDIR /app
#
# USER ${USER}
#
# # Not using tsc's actual watch command here because it clears the screen.
# # CMD ["nodemon", "--watch", "/app/src/server", "--watch", "/app/src/test", "-e", "ts,js", "--exec", "tsc -p tsconfig.development.json"]
# CMD ["tsc", "-w", "--preserveWatchOutput", "-p", "tsconfig.development.json"]
FROM base as development
# Needed for the Nest watch command.
RUN set -eux; \
apt-get update && \
apt-get install -y \
procps && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV NODE_ENV development
USER ${USER}
CMD [ "yarn", "run", "start:dev" ]
# FROM base as webpack_build
#
# # For this stage, this can be either production or staging.
# ARG NODE_ENV=production
#
# ENV NODE_ENV ${NODE_ENV}
#
# ENV PATH /app/node_modules/.bin:$PATH
#
# WORKDIR /app
#
# # This stage only needs to read this stuff. No sense in copying it into the
# # image. This saves quite a bit of disk space.
# RUN \
# --mount=type=bind,source=/app/node_modules.sav,target=node_modules,from=builder_development \
# --mount=type=bind,source=package.json,target=package.json \
# --mount=type=bind,source=lib,target=lib \
# --mount=type=bind,source=public/img,target=public/img \
# --mount=type=bind,source=src/client,target=src/client \
# --mount=type=bind,source=src/shared,target=src/shared \
# --mount=type=bind,source=webpack.config.js,target=webpack.config.js \
# webpack
#
#
# FROM base as tsc_production
#
# ENV NODE_ENV production
#
# USER ${USER}
#
# WORKDIR /app
#
# RUN \
# --mount=type=bind,source=/app/node_modules.sav,target=node_modules,from=builder_development \
# --mount=type=bind,source=package.json,target=package.json \
# --mount=type=bind,source=src,target=src \
# --mount=type=bind,source=tsconfig.base.json,target=tsconfig.base.json \
# --mount=type=bind,source=tsconfig.production.json,target=tsconfig.production.json \
# tsc -p tsconfig.production.json && \
# # Have to save off the files for later copy.
# cp -a build/ build.sav/
#
#
# FROM base as test
#
# ENV NODE_ENV test
#
# WORKDIR /app
#
# RUN mkdir webpack_stats && echo {} > webpack_stats/webpack_stats.json
#
# USER ngapps
#
# RUN \
# --mount=type=bind,source=/app/build.sav,target=build,from=tsc_production \
# --mount=type=bind,source=/app/node_modules.sav,target=node_modules,from=builder_development \
# --mount=type=bind,source=lib,target=lib \
# --mount=type=bind,source=package.json,target=package.json \
# --mount=type=bind,source=src,target=src \
# --mount=type=bind,source=tsconfig.base.json,target=tsconfig.base.json \
# --mount=type=bind,source=tsconfig.production.json,target=tsconfig.production.json \
# ts-standard -vp tsconfig.production.json src && \
# tap --no-cov build/test/**/*.js && \
# rm -rf /app/.nyc_output
#
#
# FROM base as production
#
# EXPOSE 9000
#
# WORKDIR /app
#
# COPY --from=webpack_build /app/public/build/images public/build/images
#
# COPY --from=builder_production /app/node_modules.sav node_modules
#
# # Needed for the app itself.
# COPY package.json .
#
# COPY lib lib
#
# COPY public/alerts public/alerts
#
# COPY public/favicons public/favicons
#
# COPY public/img public/img
#
# COPY public/launch-screens public/launch-screens
#
# COPY public/loops public/loops
#
# COPY public/music public/music
#
# COPY public/pwa public/pwa
#
# COPY public/soundfx public/soundfx
#
# COPY src/client/img/icons/favicon-ng.ico src/client/img/icons/favicon-ng.ico
#
# COPY --from=tsc_production /app/build/server build/server
#
# COPY --from=tsc_production /app/build/shared build/shared
#
# COPY manifests manifests
#
# COPY templates templates
#
# COPY views-chat views-chat
#
# COPY views-radio views-radio
#
# COPY --from=webpack_build /app/public/build/css public/build/css
#
# COPY --from=webpack_build /app/public/build/js public/build/js
#
# COPY --from=webpack_build /app/public/build/service-worker.js \
# public/build/service-worker.js
#
# COPY --from=webpack_build /app/webpack_stats/webpack_stats.json \
# webpack_stats/webpack_stats.json
#
# RUN ln -s /app/public/build/service-worker.js /app/public/service-worker.js
#
# # Either staging or production.
# ARG NODE_ENV=production
#
# ENV NODE_ENV ${NODE_ENV}
#
# USER ${USER}
#
# CMD ["node", "build/server/app.js"]
#