forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.base
153 lines (127 loc) · 4.71 KB
/
Dockerfile.base
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
#### cache image
#### This image is not pushed to any repository and it shouldn't be used as base image for any other docker build.
#### Its main goal is to create a `/calypso/.cache` that can be copied over other images that can benefit from a warm cache.
FROM node:14.16.1-buster as cache
ARG node_memory=8192
WORKDIR /calypso
ENV YARN_CACHE_FOLDER=/calypso/.cache/yarn
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV PERSISTENT_CACHE=true
ENV PROFILE=true
ENV SKIP_TSC=true
ENV NVM_DIR=/calypso/.nvm
ENV CALYPSO_ENV=production
ENV BUILD_TRANSLATION_CHUNKS=true
ENV NODE_OPTIONS=--max-old-space-size=$node_memory
ENV HOME=/calypso
RUN git clone --branch v0.37.0 --depth 1 https://github.com/nvm-sh/nvm.git "$NVM_DIR" \
&& echo ". ${NVM_DIR}/nvm.sh" >> "${HOME}/.bashrc"
COPY . .
# Run nvm.sh in a different dir so it doesn't try to use the version specified in /calypso/.nvmrc.
# If not, it will fail the image generation.
RUN cd / \
&& . "$NVM_DIR/nvm.sh" \
&& cd $HOME \
&& nvm install \
# Prime yarn cache
&& yarn \
# Prime webpack caches
&& NODE_ENV=production yarn build-client-both
ENTRYPOINT [ "/bin/bash" ]
#### base image
#### This image can be used as a base image for other builds, or to uni test and build calypso.
FROM node:14.16.1-buster as base
ARG node_memory=8192
ARG user=calypso
ARG UID=1003
WORKDIR /calypso
ENV YARN_CACHE_FOLDER=/calypso/.cache/yarn
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV NVM_DIR=/calypso/.nvm
ENV NODE_OPTIONS=--max-old-space-size=$node_memory
ENV HOME=/calypso
ENV SKIP_TSC=true
ENV CHROMEDRIVER_SKIP_DOWNLOAD=true
ENV PUPPETEER_SKIP_DOWNLOAD=true
ENV PLAYWRIGHT_SKIP_DOWNLOAD=true
# Add user calypso with uid 1003, give it sudo permissions
RUN apt-get update \
&& apt-get install -y sudo zip jq \
&& adduser --uid $UID --disabled-password $user \
&& echo "$user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$user \
&& chmod 0440 /etc/sudoers.d/$user \
&& chown $UID /calypso \
&& rm -rf /var/lib/apt/lists/*
# Set bash as the default shell
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Copy nvm cache so we don't need to download it again
COPY --from=cache --chown=$UID /calypso/.nvm /calypso/.nvm
# Copy all other caches (webpack, babel, yarn...)
COPY --from=cache --chown=$UID /calypso/.cache /calypso/.cache
COPY --from=cache --chown=$UID /calypso/.bashrc /calypso/.bashrc
# Copy node_modules to reduce install time of future builds.
COPY --from=cache --chown=$UID /calypso/node_modules /calypso/node_modules
ENTRYPOINT [ "/bin/bash" ]
#### ci-desktop image
#### This image is used to run desktop tests.
FROM base as ci-desktop
ENV ELECTRON_BUILDER_ARGS='-c.linux.target=dir'
ENV USE_HARD_LINKS=false
ENV CHROMEDRIVER_SKIP_DOWNLOAD=false
ENV PUPPETEER_SKIP_DOWNLOAD=false
ENV PLAYWRIGHT_SKIP_DOWNLOAD=false
# This chrome image is the latest version supported by wp-desktop's chromedriver, declared in desktop/package.json.
ENV CHROME_VERSION="80.0.3987.163-1"
ENV DISPLAY=:99
RUN apt update \
&& apt-get install -y \
fonts-liberation \
git-restore-mtime \
gtk2-engines-pixbuf \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatspi2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnspr4 \
libnss3 \
libnss3 \
libsecret-1-dev \
libx11-xcb1 \
libxss1 \
libxss1 \
libxtst6 \
xdg-utils \
xfonts-100dpi \
xfonts-75dpi \
xfonts-base \
xfonts-cyrillic \
xfonts-scalable \
xvfb
RUN wget --no-verbose https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
&& apt-get install -y ./google-chrome-stable_${CHROME_VERSION}_amd64.deb \
&& rm ./google-chrome-stable_${CHROME_VERSION}_amd64.deb
ENTRYPOINT [ "/bin/bash" ]
#### ci-e2e image
#### This image is used to run e2e tests. The only difference with ci-desktop is the Chrome version.
FROM ci-desktop as ci-e2e
# test/e2e/test/mocha.env.js will install a compatible chromedriver.
ENV DETECT_CHROMEDRIVER_VERSION=true
RUN wget --no-verbose https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y ./google-chrome-stable_current_amd64.deb \
&& rm ./google-chrome-stable_current_amd64.deb
ENTRYPOINT [ "/bin/bash" ]
#### ci-wpcom image
#### This image is used to test and build WPCOM plugins in Calypso repo.
FROM base as ci-wpcom
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY --from=cache --chown=$UID /calypso/composer.* /calypso/
RUN apt update &&\
apt-get install -y apt-transport-https &&\
wget https://packages.sury.org/php/apt.gpg -O /etc/apt/trusted.gpg.d/php-sury.gpg &&\
echo "deb https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/php-sury.list &&\
apt update &&\
apt-get install -y php7.4-cli php7.4-xml php7.4-mbstring docker-compose &&\
composer install
ENTRYPOINT [ "/bin/bash" ]