-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
119 lines (94 loc) · 3.67 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# ===============================================
FROM registry.access.redhat.com/ubi9/nodejs-20 AS appbase
# ===============================================
# install yarn
USER root
RUN curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
RUN yum -y install yarn
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 our node environment, either development or production
# defaults to production, compose overrides this to development on build and run
ARG NODE_ENV=${NODE_ENV:-"production"}
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.22
RUN yarn policies set-version ${YARN_VERSION}
# Copy package.json and package-lock.json/yarn.lock files
COPY --chown=default:root package*.json *yarn* ./
# Install npm dependencies
ENV PATH /app/node_modules/.bin:$PATH
RUN yarn && yarn cache clean --force
# =============================
FROM appbase AS development
# =============================
# Set NODE_ENV to development in the development container
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV
# Enable hot reload by default by polling for file changes.
#
# NOTE: Can be disabled by setting CHOKIDAR_USEPOLLING=false in file `.env`
# if hot reload works on your system without polling to save CPU time.
ARG CHOKIDAR_USEPOLLING=true
ENV CHOKIDAR_USEPOLLING=${CHOKIDAR_USEPOLLING}
# copy in our source code last, as it changes the most
COPY --chown=default:root . .
# Bake package.json start command into the image
CMD ["yarn", "start", "--no-open", "--host"]
# ===================================
FROM appbase AS staticbuilder
# ===================================
ARG VITE_API_URI
ARG VITE_OIDC_SERVER_TYPE
ARG VITE_OIDC_RETURN_TYPE
ARG VITE_OIDC_AUTHORITY
ARG VITE_OIDC_CLIENT_ID
ARG VITE_OIDC_KUKKUU_API_CLIENT_ID
ARG VITE_OIDC_SCOPE
ARG VITE_OIDC_AUDIENCES
ARG VITE_OIDC_AUTOMATIC_SILENT_RENEW_ENABLED
ARG VITE_OIDC_SESSION_POLLING_INTERVAL_MS
ARG VITE_KUKKUU_API_OIDC_SCOPE
ARG VITE_ENVIRONMENT
ARG VITE_SENTRY_DSN
ARG VITE_IS_TEST_ENVIRONMENT
ARG VITE_FEATURE_FLAG_EXTERNAL_TICKET_SYSTEM_SUPPORT
ARG VITE_BUILDTIME
ARG VITE_RELEASE
ARG VITE_COMMITHASH
ARG VITE_IDLE_TIMEOUT_IN_MS
ARG NODE_OPTIONS
# Fix FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed -
# JavaScript heap out of memory: https://github.com/vitejs/vite/issues/2433.
ENV NODE_OPTIONS=${NODE_OPTIONS}
# Use template and inject the environment variables into .prod/nginx.conf
ENV VITE_BUILDTIME=${VITE_BUILDTIME:-""}
ENV VITE_RELEASE=${VITE_RELEASE:-""}
ENV VITE_COMMITHASH=${VITE_COMMITHASH:-""}
COPY .prod/nginx.conf.template /tmp/.prod/nginx.conf.template
RUN export APP_VERSION=$(yarn --silent app:version) && \
envsubst '${APP_VERSION},${VITE_BUILDTIME},${VITE_RELEASE},${VITE_COMMITHASH}' < \
"/tmp/.prod/nginx.conf.template" > \
"/tmp/.prod/nginx.conf"
COPY . /app
RUN yarn build
# =============================
FROM registry.access.redhat.com/ubi9/nginx-122 AS production
# =============================
# Add application sources to a directory that the assemble script expects them
# and set permissions so that the container runs without root access
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/build /usr/share/nginx/html
# Copy nginx config
COPY --from=staticbuilder /tmp/.prod/nginx.conf /etc/nginx/nginx.conf
USER 1001
# Run script uses standard ways to run the application
CMD ["/bin/bash", "-c", "nginx -g \"daemon off;\""]
EXPOSE 8080