-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
95 lines (66 loc) · 2.41 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
FROM node:20-bookworm-slim as base
# References:
# - https://www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker
# - https://snyk.io/blog/choosing-the-best-node-js-docker-image/
RUN apt-get update -y && \
apt-get install -y curl openssl && \
mkdir -p /home/node/app/client/node_modules && \
mkdir -p /home/node/app/server/node_modules && \
chown -R node:node /home/node/app
FROM base as build_client_prod
WORKDIR /home/node/app/client
COPY client/package*.json .
COPY client/yarn.lock .
USER node
RUN yarn install --frozen-lockfile
COPY client/public ./public
COPY client/src ./src
COPY client/index.html .
COPY client/tsconfig*.json .
COPY client/vite.config.mts .
RUN yarn run build
FROM base as build_server_prod
WORKDIR /home/node/app/server
COPY server/package*.json .
COPY server/yarn.lock .
# Prisma generates the Prisma client in its post-install script, so we need this directory around before running yarn
# install
COPY server/prisma ./prisma
USER node
RUN yarn install --frozen-lockfile
COPY server/src ./src
COPY server/tsconfig*.json .
COPY server/build.ts .
RUN yarn run build
COPY server/src/crontab.txt ./dist/crontab.txt
FROM base as run_server_prod
WORKDIR /home/node/app/server
COPY server/package*.json .
COPY server/yarn.lock .
# Prisma generates the Prisma client in its post-install script, so we need this directory around before running yarn
# install
COPY server/prisma ./prisma
USER node
RUN yarn install --frozen-lockfile --prod
FROM base as prod
WORKDIR /home/node/app
USER node
COPY --from=build_client_prod /home/node/app/client/dist ./client/dist
COPY --from=build_server_prod /home/node/app/server/dist ./server/dist
COPY --from=build_server_prod /home/node/app/server/prisma ./server/prisma
COPY --from=build_server_prod /home/node/app/server/package.json ./server/package.json
COPY --from=run_server_prod /home/node/app/server/node_modules ./server/node_modules
WORKDIR /home/node/app/server/settings
COPY --chown=node:node server/settings/*.example.json .
COPY --chown=node:node server/settings/*.example.txt .
WORKDIR /home/node/app/server/env
COPY --chown=node:node server/env/production.env.example .
WORKDIR /home/node/app/server
USER root
RUN chown -R node:node /home/node/app/server/settings && \
chown -R node:node /home/node/app/server/env
USER node
# TODO: Allow customizing TZ
ENV TZ="America/New_York"
EXPOSE 8080
CMD ["yarn", "start"]