This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
52 lines (40 loc) · 1.49 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
# Use an official Node runtime as a parent image.
# Use a specific version!
# See: https://github.com/goldbergyoni/nodebestpractices#-89-use-explicit-image-reference-avoid-latest-tag
FROM node:22 AS build
# Install node modules and cache them in 'build' image.
WORKDIR /app/frontend
COPY ./frontend/package.json ./frontend/package-lock.json ./
RUN npm clean-install
WORKDIR /app/backend
COPY ./backend/package.json ./backend/package-lock.json ./
RUN npm clean-install
# -------------------------------------------------------------
FROM node:22-alpine
# Setup a system group and user to run the webapp,
# in order to avoid the security risk of running
# the backend as root.
RUN addgroup --system webapp \
&& adduser --system webapp --ingroup webapp
# Set the working directory within the container to '/app',
# both backend and frontend will be hosted in this directory.
WORKDIR /app
# Copy both backend and frontend folders into the container.
COPY . .
# Build the frontend.
WORKDIR /app/frontend
# Copy the cached node_modules.
COPY --from=build /app/frontend/node_modules ./node_modules
# Build frontend.
RUN npm run build
WORKDIR /app/backend
# Copy the cached node_modules.
COPY --from=build /app/backend/node_modules ./node_modules
RUN chown -R root:webapp ./dist ./node_modules
RUN chmod -R 550 ./node_modules
RUN chmod -R 550 ./dist
EXPOSE 80
# TODO: Use other user rather than root!
# USER webapp
# Set the command to start the Node server and serve the React app.
CMD ["npm", "run", "start"]