-
Notifications
You must be signed in to change notification settings - Fork 1
/
DockerfileCache
143 lines (123 loc) · 4.84 KB
/
DockerfileCache
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
###################################################################
# Stage 1: Install all workspaces (dev)dependencies #
# and generates node_modules folder(s) #
# ----------------------------------------------------------------#
# Notes: #
# 1. this stage relies on buildkit features #
# 2. depend on .dockerignore, you must at least #
# ignore: all **/node_modules folders and .yarn/cache #
###################################################################
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
# install rsync (to fetch cached files)
RUN yum update -y && \
yum install -y rsync
WORKDIR /workspace-install
COPY --chown=default:root yarn.lock .yarnrc.yml ./
COPY --chown=default:root .yarn/ ./.yarn/
# Specific to monerepo's as docker COPY command is pretty limited
# we use buidkit to prepare all files that are necessary for install
# and that will be used to invalidate docker cache.
#
# Files are copied with rsync:
#
# - All package.json present in the host (root, apps/*, packages/*)
#
# Copy all files
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
#
# To speed up installations, we override the default yarn cache folder
# and mount it as a buildkit cache mount (builkit will rotate it if needed)
# This strategy allows to exclude the yarn cache in subsequent docker
# layers (size benefit) and reduce packages fetches.
#
# PS:
# 1. Cache mounts can be used in CI (github actions)
# 2. To manually clear the cache
# > docker builder prune --filter type=exec.cachemount
#
# Does not play well with buildkit on CI
# https://github.com/moby/buildkit/issues/1673
# mount type cache is not supported on current version (4.10.35) of OpenShift build
#RUN --mount=type=cache,target=/root/.yarn3-cache,id=yarn3-cache \
# YARN_CACHE_FOLDER=/root/.yarn3-cache \
# yarn install --immutable --inline-builds
###################################################################
# Build cache image #
# This is used to speedup OpenShift builds #
###################################################################
# Build cache layer
FROM registry.access.redhat.com/ubi9/nodejs-20 AS build_cache
# Build ARGS
ARG PROJECT
ARG CMS_ORIGIN
ARG SKIP_BUILD_STATIC_GENERATION=1
ARG FEDERATION_ROUTER_ENDPOINT
ARG LINKEDEVENTS_EVENT_ENDPOINT
ARG NEXT_PUBLIC_APP_ORIGIN
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
ARG NEXT_PUBLIC_ASKEM_API_KEY_FI
ARG NEXT_PUBLIC_ASKEM_API_KEY_EN
ARG NEXT_PUBLIC_ASKEM_API_KEY_SV
ARG NEXT_PUBLIC_ASKEM_ENABLED
ARG NEXT_PUBLIC_ALLOW_UNAUTHORIZED_REQUESTS
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
ARG NEXT_PUBLIC_SENTRY_DSN
ARG NEXT_PUBLIC_SENTRY_TRACE_SAMPLE_RATE
ARG NEXT_PUBLIC_SENTRY_REPLAY_SESSION_SAMPLE_RATE
ARG NEXT_PUBLIC_SENTRY_REPLAY_ON_ERROR_SAMPLE_RATE
ARG SENTRY_AUTH_TOKEN
ARG NEXT_PUBLIC_DEBUG
ARG NEXTJS_DISABLE_SENTRY
ARG NEXT_PUBLIC_IMAGE_PROXY_URL
ARG NEXT_PUBLIC_DEFAULT_ISR_REVALIDATE_SECONDS
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_HEADER_UNIVERSAL_BAR_MENU_NAME_FI
ARG NEXT_PUBLIC_CMS_HEADER_UNIVERSAL_BAR_MENU_NAME_EN
ARG NEXT_PUBLIC_CMS_HEADER_UNIVERSAL_BAR_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
ARG NEXT_PUBLIC_CMS_ARTICLES_CONTEXT_PATH
ARG NEXT_PUBLIC_CMS_PAGES_CONTEXT_PATH
ARG NEXT_PUBLIC_RELEASE
ARG NEXT_PUBLIC_COMMITHASH
WORKDIR /app
COPY --chown=default:root . .
COPY --from=deps --chown=default:root /workspace-install ./
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
USER default
# install cache
RUN yarn install --immutable --inline-builds
# Create cache image
FROM registry.access.redhat.com/ubi9/nodejs-20 AS cache
ARG PROJECT
WORKDIR /app/.yarn/cache/
COPY --from=build_cache --chown=default:root /app/.yarn/cache/ ./