-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
36 lines (25 loc) · 1.01 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
###multistage build
##stage 1. build the react app
FROM node:20-alpine AS builder
WORKDIR /opt/web
COPY package.json package-lock.json ./
RUN npm install
ENV PATH="./node_modules/.bin:$PATH"
COPY . ./
RUN npm run build
##stage 2. build the production (server) environment
FROM nginx:1.23.2-alpine
#install curl and envsubst
RUN apk --no-cache add curl
RUN apk --no-cache add bash
RUN curl -L https://github.com/a8m/envsubst/releases/download/v1.1.0/envsubst-`uname -s`-`uname -m` -o envsubst && \
chmod +x envsubst && \
mv envsubst /usr/local/bin
#copy config file over to the template
COPY ./nginx.config /etc/nginx/nginx.template
#set working directory to nginx folder
WORKDIR /usr/share/nginx/html
#substitute out default.conf file with nginx.template AND start the nginx server
CMD ["/bin/sh", "-c", "envsubst < /etc/nginx/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
# generate react Static Build files for nginx to use
COPY --from=builder /opt/web/build /usr/share/nginx/html