-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
94 lines (64 loc) · 2.97 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
# This is a multi-stage build to reduce the size of the final image.
# The first stage is used to build the application. It installs all the dependencies and builds the app.
# This creates a temporary image of > 1 GB.
# The second stage is used to serve the app using nginx. It copies the build folder from the first stage
# and weighs only ~ 80 MB.
# Stage 1: Generate SSL certificate
FROM alpine AS cert-gen
RUN apk add --no-cache openssl
WORKDIR /certs
RUN openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
-subj "/C=US/ST=State/L=City/O=Organization/CN=localhost" \
-keyout server.key -out server.crt
# Stage 2: Build the wheel package for the converter part of the UI.
FROM python:3.11 AS wheel-builder
COPY src/libs/converter/ .
# Install Poetry and build the wheel package.
RUN pip install --no-cache-dir "poetry ~= 1.8.2" \
&& poetry build --format wheel --no-ansi
# Stage 3: Build the application.
FROM node:20 AS build
# Directory where the app is installed and run.
WORKDIR /usr/src/app
# Copy SSL certificate from the cert-gen stage
# First, copy package.json and package-lock.json to install dependencies.
COPY package.json package-lock.json ./
# Install app dependencies using npm ci as it is preferred for automated builds.
RUN npm ci
# Bundle app source.
COPY . .
# Set HOME to /usr/src/app.
# This is needed to make sure that the git config is stored in the correct directory.
# Otherwise, the git config is stored in the root directory, which is not allowed.
# Also, pip installs some packages using the --user option, which requires HOME to be set.
ENV HOME /usr/src/app
RUN git config --global --add safe.directory /usr/src/app
# Run the setup script to identify the git commit hash and write it to a file.
# This file is later used to display the commit hash in the UI.
RUN npm run identify
# Copy the wheel package for the converter library from the previous build stage.
# This library is used in the UI.
COPY --from=wheel-builder dist/*.whl public/libs/converter/dist/
# Default deployment type can be overwritten by docker build --build-arg DEPLOYMENT=dev ...
ARG DEPLOYMENT=prod
RUN echo "Deploying for ${DEPLOYMENT}"
# Build the app.
RUN npx cross-env REACT_APP_DEPLOYMENT=${DEPLOYMENT} npm run build
# The step below is a JavaScript module that fixes a bug
# related to the paths of static assets in a React application.
# The bug is caused by a known issue in the create-react-app package,
# which results in duplicate static/js entries in the paths of some chunk files.
RUN npm run fix-web-dev
# Stage 4: Serve the app using Nginx.
FROM nginx:alpine
# Remove the default Nginx configuration
RUN rm /etc/nginx/conf.d/default.conf
# Copy SSL certificate from the build stage
COPY --from=cert-gen /certs /etc/nginx/conf.d
# Copy the build folder from the build stage
COPY --from=build /usr/src/app/build /usr/share/nginx/html
# Copy the custom Nginx configuration
COPY nginx.conf /etc/nginx/conf.d/app.conf
EXPOSE 80
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]