-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDockerfile
94 lines (67 loc) · 2.32 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
94
# ===============================================
FROM node:18-slim AS appbase
# ===============================================
RUN groupadd -g 1001 appuser \
&& useradd --create-home --no-log-init -u 1001 -g 1001 appuser
RUN mkdir /app
RUN chown -R appuser:appuser /app
WORKDIR /app
# Offical image has npm log verbosity as info. More info - https://github.com/nodejs/docker-node#verbosity
ENV NPM_CONFIG_LOGLEVEL warn
# set node environment, either development or production
# use development to install devDependencies
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV
# Global npm deps in a non-root user directory
ENV NPM_CONFIG_PREFIX=/app/.npm-global
ENV PATH=$PATH:/app/.npm-global/bin
# Yarn
ENV YARN_VERSION 1.22.19
RUN yarn policies set-version $YARN_VERSION
# Use non-root user
USER appuser
# Copy package.json and package-lock.json/yarn.lock files
COPY package.json yarn.lock ./
# Install npm depepndencies
ENV PATH /app/node_modules/.bin:$PATH
USER root
RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential python3
USER appuser
RUN yarn config set network-timeout 300000
RUN yarn && yarn cache clean --force
USER root
RUN apt-get remove -y build-essential
RUN apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
RUN rm -rf /var/lib/apt/lists/*
RUN rm -rf /var/cache/apt/archives
# =============================
FROM appbase as development
# =============================
# Set NODE_ENV to development in the development container
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV
# copy in our source code last, as it changes the most
COPY --chown=appuser:appuser . .
# Bake package.json start command into the image
CMD ["react-scripts", "start"]
# ===================================
FROM appbase as staticbuilder
# ===================================
# Set NODE_ENV to production in the staticbuilder container
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV
COPY . /app
RUN yarn compile
# =============================
FROM registry.access.redhat.com/ubi8/nginx-120 as production
# =============================
USER root
RUN chgrp -R 0 /usr/share/nginx/html && \
chmod -R g=u /usr/share/nginx/html
# Copy static build
COPY --from=staticbuilder /app/dist /usr/share/nginx/html
# Copy nginx config
COPY .prod/nginx.conf /etc/nginx/
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]