-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (65 loc) · 2.59 KB
/
Dockerfile
File metadata and controls
84 lines (65 loc) · 2.59 KB
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
### Builder Container ###
FROM alpine:3.10 as build-stage
ARG REACT_APP_API_URL
# Do not use this environment
ENV REACT_APP_API_URL_=$REACT_APP_API_URL
RUN mkdir -p /usr/src/app && \
rm -rf /var/cache/apk/* \
&& rm -rf /tmp/* && \
apk update && \
apk add --update nodejs npm && \
npm install react-scripts@2.1.8 -g --silent
WORKDIR /usr/src/app
ENV PATH=/usr/src/app/node_modules/.bin:$PATH
# copy package.json first to avoid busting docker cache
COPY ./package.json /usr/src/app/package.json
COPY ./package-lock.json /usr/src/app/package-lock.json
# RUN npm install typescript --silent
RUN npm install --silent
# Copying all files will bust cache (i.e changes in docker-run.sh)
# Manually copy necessary files, allows for mounting volumes (like node_modules/build) for dev as well
COPY ./public /usr/src/app/public
COPY ./src /usr/src/app/src
COPY ./tsconfig.json /usr/src/app/tsconfig.json
COPY ./yarn.lock /usr/src/app/yarn.lock
# TODO: this should be prod, use build arg to include devtools but default to prod
RUN REACT_APP_API_URL=$REACT_APP_API_URL_ npm run build
### Main Container ###
### Because we're supporting the dev server here, not a huge benefit for multi-stage builds ###
FROM alpine:3.10
RUN rm -rf /var/cache/apk/* \
&& rm -rf /tmp/* && \
apk update && \
apk add --update nodejs npm nginx && \
npm install react-scripts@2.1.8 -g --silent && \
mkdir -p /usr/src/app && \
mkdir -p /usr/src/nginx && \
mkdir -p /run/nginx && \
mkdir -p /var/www/app && \
mkdir -p /etc/letsencrypt/live/codecomp.proxy.docker
# copy the entire source so we can run npm start (dev server)
COPY --from=build-stage /usr/src/app /usr/src/app
# copy just the build to the /var/www/directory
RUN cp -R /usr/src/app/build/* /var/www/app
WORKDIR /var/www/app
RUN chown -R nginx:nginx /var/www/app
# Environmnet Variables and Ports
EXPOSE 8080 8443 3000
# By default, the start script expects the api to be available
# If running the frontend without an API, set PROXY_ENABLED to 0 and it will not
# include the proxy configuration within nginx.
ENV PROXY_ENABLED="1" \
SERVER="nginx" \
SECURE_LISTEN_PORT="8443" \
INSECURE_LISTEN_PORT="8080" \
TLS_ENABLED="0" \
API_BACKEND_PROTO="http" \
API_BACKEND_HOST="backend" \
API_BACKEND_PORT="8080" \
DEBUG_CONF="0" \
TLS_DIR="/etc/letsencrypt/live/codecomp.proxy.docker" \
PATH=/var/www/app/node_modules/.bin:$PATH
# dynamically configure configs or user defaults to avoid mounts
COPY ./docker-run.sh /usr/bin/docker-run.sh
RUN chmod +x /usr/bin/docker-run.sh
ENTRYPOINT ["/usr/bin/docker-run.sh"]