-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
88 lines (70 loc) · 2.91 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
###################################################
# Stage: base
#
# This base stage ensures all other stages are using the same base image
# and provides common configuration for all stages, such as the working dir.
###################################################
FROM node:22-alpine AS base
WORKDIR /usr/local/app
################## CLIENT STAGES ##################
###################################################
# Stage: client-base
#
# This stage is used as the base for the client-dev and client-build stages,
# since there are common steps needed for each.
###################################################
FROM base AS client-base
COPY client/package.json client/yarn.lock ./
RUN --mount=type=cache,id=yarn,target=/usr/local/share/.cache/yarn \
yarn install
COPY client/eslint.config.js client/index.html client/vite.config.ts client/tsconfig.json client/tsconfig.node.json client/tsconfig.app.json ./
COPY client/public ./public
COPY client/src ./src
###################################################
#
# This stage is used for development of the client application. It sets
# the default command to start the Vite development server.
###################################################
FROM client-base AS client-dev
EXPOSE 5173
CMD ["yarn", "dev"]
###################################################
#Stage: client-build
# This stage builds the client application, producing static HTML, CSS, and
# JS files that can be served by the backend.
###################################################
FROM client-base AS client-build
RUN yarn build
###################################################
################ BACKEND STAGES #################
###################################################
###################################################
# Stage: backend-base
#
# This stage is used as the base for the backend-dev and test stages, since
# there are common steps needed for each.
###################################################
FROM base AS backend-dev
COPY backend/package.json backend/yarn.lock backend/tsconfig.json backend/nodemon.json ./
RUN --mount=type=cache,id=yarn,target=/usr/local/share/.cache/yarn \
yarn install --frozen-lockfile
COPY backend/src ./src
EXPOSE 3000
CMD ["yarn", "dev"]
##################################################
# Stage: final
#
# This stage is intended to be the final "production" image. It sets up the
# backend and copies the built client application from the client-build stage.
#
# It pulls the package.json and yarn.lock from the test stage to ensure that
# the tests run (without this, the test stage would simply be skipped).
###################################################
FROM base AS final
ENV NODE_ENV=production
RUN --mount=type=cache,id=yarn,target=/usr/local/share/.cache/yarn \
yarn install --production --frozen-lockfile
COPY backend/src ./src
COPY --from=client-build /usr/local/app/dist ./src/static
EXPOSE 3000
CMD ["node", "dist/index.js"]