-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
158 lines (124 loc) · 4.36 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# =======================================
FROM registry.access.redhat.com/ubi9/nodejs-20 AS deps
# =======================================
# 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
RUN yum update -y && \
yum install -y rsync
WORKDIR /workspace-install
COPY --chown=default:root yarn.lock ./
WORKDIR /docker-context
COPY --chown=default:root . /docker-context
# mount type bind is not supported on current version (4.10.35) of OpenShift build
# RUN --mount=type=bind,source=./,target=/docker-context \
RUN rsync -amv \
--chown=default:root \
--exclude='node_modules' \
--exclude='*/node_modules' \
--include='package.json' \
--include='*/' --exclude='*' \
/docker-context/ /workspace-install/;
RUN chown -R default:root .
# remove rsync, unused dependencies, and clean yum cache
RUN yum remove -y rsync && \
yum autoremove -y && \
yum clean all && \
rm -rf /var/cache/yum
# =============================
FROM deps 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 WATCHPACK_POLLING=false in file `.env`
# if hot reload works on your system without polling to save CPU time.
ARG WATCHPACK_POLLING=true
ENV WATCHPACK_POLLING=${WATCHPACK_POLLING}
WORKDIR /app
# copy in our source code last, as it changes the most
COPY --chown=default:root . .
RUN yarn install --immutable --inline-builds
# Bake package.json start command into the image
CMD ["yarn", "dev"]
# ===================================
FROM deps AS staticbuilder
# ===================================
# Set environmental variables (when building image on GitLab CI)
# specified in gitlab-ci.yml file
ARG SKIP_BUILD_STATIC_GENERATION
ARG NEXT_PUBLIC_APP_ORIGIN
ARG NEXT_PUBLIC_API_BASE_URL
ARG NEXT_PUBLIC_UNIFIED_SEARCH_BASE_URL
ARG NEXT_PUBLIC_CMS_BASE_URL
ARG NEXT_PUBLIC_SENTRY_DSN
ARG NEXT_PUBLIC_ENVIRONMENT
ARG NEXT_PUBLIC_CAPTCHA_KEY
ARG NEXT_PUBLIC_LANGUAGE_CIMODE_VISIBLE
ARG NEXT_PUBLIC_HEADLESS_CMS_ENABLED
ARG NEXT_PUBLIC_FORMIK_PERSIST
ARG NEXT_PUBLIC_NEWSLETTER_ENABLED
ARG NEXT_PUBLIC_RELEASE
ARG NEXT_PUBLIC_COMMITHASH
# Set Matomo settings
ARG NEXT_PUBLIC_MATOMO_URL_BASE
ARG NEXT_PUBLIC_MATOMO_SITE_ID
ARG NEXT_PUBLIC_MATOMO_SRC_URL
ARG NEXT_PUBLIC_MATOMO_TRACKER_URL
ARG NEXT_PUBLIC_MATOMO_ENABLED
# CMS
ARG NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_FI
ARG NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_EN
ARG NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_SV
ARG NEXT_PUBLIC_CMS_HEADER_MENU_NAME_FI
ARG NEXT_PUBLIC_CMS_HEADER_MENU_NAME_EN
ARG NEXT_PUBLIC_CMS_HEADER_MENU_NAME_SV
ARG NEXT_PUBLIC_CMS_FOOTER_MENU_NAME_FI
ARG NEXT_PUBLIC_CMS_FOOTER_MENU_NAME_EN
ARG NEXT_PUBLIC_CMS_FOOTER_MENU_NAME_SV
WORKDIR /app
USER root
# copy all files
COPY --chown=default:root . .
COPY --from=deps --chown=default:root /workspace-install ./
RUN yarn install --immutable --inline-builds
# Build application
RUN yarn build
# ==========================================
FROM staticbuilder AS production
# ==========================================
USER default
ARG PORT
ARG NEXT_PUBLIC_CAPTCHA_KEY
ARG NEWSLETTER_BASE_URL
ARG NEWSLETTER_APIKEY
ENV NEWSLETTER_BASE_URL=$NEWSLETTER_BASE_URL
ENV NEWSLETTER_APIKEY=$NEWSLETTER_APIKEY
ENV PATH $PATH:/app/node_modules/.bin
ENV NODE_ENV production
ENV PORT $PORT
ENV NEXT_TELEMETRY_DISABLED 1
WORKDIR /app
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
# copy only the necessary files for a production deployment including select files in node_modules.
# Copy the configuration files to the apps/project root
COPY --from=staticbuilder --chown=default:root /app/next.config.js \
/app/next-i18next.config.js \
/app/package.json \
/app/yarn.lock \
/app/
COPY --from=staticbuilder --chown=default:root /app/.next/standalone .
COPY --from=staticbuilder --chown=default:root /app/.next/static ./.next/static
COPY --from=staticbuilder --chown=default:root /app/public ./public
# OpenShift write access to Next cache folder
USER root
RUN chgrp -R 0 /app/.next/server/pages && chmod g+w -R /app/.next/server/pages
USER default
# Expose port
EXPOSE $PORT
# Start nextjs server
CMD ["node", "/app/server.js"]