-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
43 lines (34 loc) · 1.31 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
# Need a custom image here so that we can incorporate an npm build too
# Alpine is super light
FROM node:18-alpine as build
# Create directories
# /working is the build directory
# /static is the directory linked to nginx (serves static content)
RUN mkdir -p /var/www/membership/working && \
mkdir -p /var/www/membership/static && \
mkdir -p /var/www/membership/static/build
# Install the required packages to build the frontend
WORKDIR /var/www/membership/working
COPY package.json yarn.lock /var/www/membership/working/
RUN yarn install
# Copy the source files
COPY pages/ /var/www/membership/working/pages/
COPY src/ /var/www/membership/working/src/
COPY .babelrc *.js *.json /var/www/membership/working/
# build and copy files to server root
RUN yarn build && \
cp -rv pages/* ../static/ && \
cp -rv lib/build/* ../static/build/ && \
cp -rv lib/index.html ../static/index.html
# Use separate build stage to serve files. This reduces the image size drastically
FROM alpine:3.18
# add nginx
RUN apk add --no-cache nginx
# Copy the configuration file
RUN mkdir -p /run/nginx
COPY conf/ /etc/nginx/
# Copy the build files from the previous stage
WORKDIR /var/www/membership/static
COPY --from=build /var/www/membership/static /var/www/membership/static
# Run the server
CMD ["nginx", "-g", "daemon off;"]