forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
171 lines (141 loc) · 5.61 KB
/
Dockerfile
File metadata and controls
171 lines (141 loc) · 5.61 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# syntax=docker/dockerfile:1.20
ARG cache_mode=base
ARG node_version=22.9.0
ARG base_image=registry.a8c.com/calypso/base:latest
ARG cache_seed_image=registry.a8c.com/calypso/cache-seed:latest
###################
FROM node:${node_version}-bullseye-slim AS builder-cache-none
WORKDIR /calypso
ENV HOME=/calypso
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV PERSISTENT_CACHE=true
RUN mkdir -p /calypso/.cache /calypso/.yarn
###################
# This image contains a directory /calypso/.cache which includes caches
# for yarn, terser, css-loader and babel.
FROM ${base_image} AS builder-cache-base
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV PERSISTENT_CACHE=true
###################
FROM ${cache_seed_image} AS cache-seed-source
###################
FROM node:${node_version}-bullseye-slim AS builder-cache-seed
WORKDIR /calypso
ENV HOME=/calypso
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV PERSISTENT_CACHE=true
COPY --from=cache-seed-source /calypso/.cache /calypso/.cache
COPY --from=cache-seed-source /calypso/.yarn /calypso/.yarn
###################
# Dedicated dependency-install stage.
# By copying only manifests and the lockfile first, we can cache
# the slow yarn install and skip it when only source files change.
FROM builder-cache-${cache_mode} AS deps
WORKDIR /calypso
ENV PLAYWRIGHT_SKIP_DOWNLOAD=true
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
ENV SKIP_TSC=true
ENV SKIP_CALYPSO_POSTINSTALL=true
ENV SKIP_CALYPSO_PACKAGE_BUILDS=true
ENV CONTAINER=docker
ENV IS_CI=true
# For Sentry uploads
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
# Build a "base" layer
#
# This layer should never change unless env-config.sh
# changes. For local development this should always
# be an empty file and therefore this layer should
# cache well.
#
# env-config.sh
# used by systems to overwrite some defaults
# such as the apt and npm mirrors
COPY ./env-config.sh /tmp/env-config.sh
RUN bash /tmp/env-config.sh
# Copy dependency metadata only — manifests, lockfile, and Yarn config.
# The workspace COPY block below should stay in sync with the root
# workspaces in package.json. A CI check (`yarn check:docker-workspace-copy-globs`)
# will let you know if they drift apart.
COPY ./package.json ./yarn.lock ./.yarnrc.yml /calypso/
COPY ./.yarn/releases /calypso/.yarn/releases
COPY ./.yarn/patches /calypso/.yarn/patches
# BEGIN: workspace package manifests (must stay in sync with package.json workspaces)
COPY --parents \
./apps/*/package.json \
./packages/*/package.json \
./client/package.json \
./desktop/package.json \
./test/e2e/package.json \
/calypso/
# END: workspace package manifests
# We don't need the full postinstall (build-packages, husky) at this
# stage — just the bare install. SKIP_CALYPSO_POSTINSTALL lets us
# bypass it safely.
COPY ./bin/postinstall.sh /calypso/bin/postinstall.sh
RUN yarn install --immutable --check-cache --inline-builds
###################
FROM deps AS builder
# Make sure shell options, like pipefail, are set for the build.
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Information for Sentry Releases.
ARG manual_sentry_release=false
ARG is_default_branch=false
ARG sentry_auth_token=''
ENV MANUAL_SENTRY_RELEASE $manual_sentry_release
ENV IS_DEFAULT_BRANCH $is_default_branch
ENV SENTRY_AUTH_TOKEN $sentry_auth_token
ARG commit_sha="(unknown)"
ARG workers=4
ARG node_memory=8192
ARG profile=false
ENV CONTAINER 'docker'
ENV PROFILE=$profile
ENV COMMIT_SHA $commit_sha
ENV CALYPSO_ENV production
ENV WORKERS $workers
ENV BUILD_TRANSLATION_CHUNKS true
ENV NODE_OPTIONS --max-old-space-size=$node_memory
ENV IS_CI=true
WORKDIR /calypso
# Build a "source" layer
#
# This layer is populated with up-to-date files from
# Calypso development.
COPY . /calypso/
RUN yarn run build-packages:web
## Version debugging, temp uncomment if needed (Like working on a node upgrade)
## RUN node --version && yarn --version && npm --version
# Build the final layer
#
# This contains built environments of Calypso. It will
# change any time any of the Calypso source-code changes.
ENV NODE_ENV production
ARG generate_cache_image=false
# Delete sourcemaps in the same layer as the build so trunk's hidden-source-map
# artifacts do not have to be committed and then whiteouted in a later snapshot.
RUN GENERATE_CACHE_IMAGE=$generate_cache_image yarn run build 2>&1 | tee /tmp/build_log.txt \
&& find /calypso/build /calypso/public -name "*.*.map" -delete
# This will output a service message to TeamCity if the build cache was invalidated as seen in the build_log file.
RUN ./bin/check-log-for-cache-invalidation.sh /tmp/build_log.txt
###################
# A cache-only update can be generated with "docker build --target update-base-cache"
FROM ${base_image} AS update-base-cache
# Update webpack cache in the base image so that it can be re-used in future builds.
# We only copy this part of the cache to make --push faster, and because webpack
# is the main thing which will impact build performance when the cache invalidates.
COPY --from=builder /calypso/.cache/evergreen/webpack /calypso/.cache/evergreen/webpack
###################
FROM node:${node_version}-alpine AS app
ARG commit_sha="(unknown)"
ENV COMMIT_SHA $commit_sha
ENV NODE_ENV production
WORKDIR /calypso
RUN apk add --no-cache tini
COPY --from=builder --chown=nobody:nobody /calypso/build /calypso/build
COPY --from=builder --chown=nobody:nobody /calypso/public /calypso/public
COPY --from=builder --chown=nobody:nobody /calypso/config /calypso/config
COPY --from=builder --chown=nobody:nobody /calypso/package.json /calypso/package.json
USER nobody
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "--unhandled-rejections=warn", "build/server.js"]