-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile-composerbuilder
268 lines (252 loc) · 8.61 KB
/
Dockerfile-composerbuilder
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# This Dockerfile builds the *composer-builder" image, which is the base for the `sitebuilder-base`
ARG PHP_VERSION
FROM php:${PHP_VERSION}
# *_VERSION are passed by Gitlab as an argument through the softwareVersions file
ARG COMPOSER_VERSION
ARG NGINX_VERSION
LABEL maintainer="Drupal Admins <[email protected]>" \
composer_version="$COMPOSER_VERSION"
# TODO: check if we need this, this might be unnecessary
RUN source /etc/os-release && \
ALPINE_VERSION=$(echo "$VERSION_ID" | cut -d. -f1-2) && \
echo "http://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/main" >> /etc/apk/repositories
# from https://www.drupal.org/docs/8/system-requirements/drupal-8-php-requirements
# from https://github.com/docker-library/docs/blob/master/php/README.md#supported-tags-and-respective-dockerfile-links
# install some utils
RUN apk --update add \
# Some composer packages need git
git \
patch \
curl \
gettext \
zip \
unzip \
mysql-client \
jq \
tzdata \
rsync \
icu-dev \
libcurl \
imagemagick-dev \
imagemagick \
php7-pecl-imagick \
bzip2-dev \
ldb-dev \
libldap \
openldap-dev \
libxml2-dev \
libxml2 \
libxslt-dev \
libxslt \
net-snmp \
net-snmp-dev \
php7-mbstring
# Fix for iconv library
# This must be present in the sitebuilder image,
# so that it can be used in runtime.
# ffi: https://gitlab.cern.ch/webservices/webframeworks-planning/-/issues/690
RUN apk add --update gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
# Configured timezone.
ENV TZ=Europe/Zurich
RUN touch /usr/share/zoneinfo/$TZ \
&& cp /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone && \
apk del tzdata \
&& rm -rf /var/cache/apk/*
# PHP FPM
RUN set -eux; \
\
apk add --no-cache --virtual .build-deps autoconf g++ make \
coreutils \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
mysql-client \
; \
\
# install redis
pecl install -o -f redis \
; \
rm -rf /tmp/pear \
; \
docker-php-ext-enable redis \
; \
\
# install imagick
pecl install -o -f imagick \
; \
\
docker-php-ext-enable imagick \
; \
\
# install igbinary
pecl install -o -f igbinary\
; \
\
docker-php-ext-enable igbinary\
; \
\
# install msgpack
pecl install -o -f msgpack\
; \
\
docker-php-ext-enable msgpack \
; \
\
docker-php-ext-configure gd \
--with-freetype=/usr/include \
--with-jpeg=/usr/include \
; \
\
docker-php-ext-install -j "$(nproc)" \
gd \
opcache \
pdo_mysql \
zip \
calendar \
bz2 \
dba \
exif \
intl \
ldap \
# Exists on the old infra, to deprecate?
#memcached \
mysqli \
# Exists on the old infra, to deprecate?
#odbc \
#pdo_odbc \
# recode \ Does no longer exist ?
shmop \
snmp \
soap \
sockets \
sysvmsg \
sysvsem \
sysvshm \
xml \
#wddx \ Does not exist for Drupal9/PHP7.4
xmlrpc \
xsl \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --virtual .drupal-phpexts-rundeps $runDeps; \
apk del .build-deps
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION}
# Install nginx on php-fpm. At this point in the Dockerfile PHP/composer is installed. Now we're also adding nginx.
# We add nginx in the same image to eliminate the need to copy the sitebuilder to an empty dir on pod startup.
#
# Copy from upstream
# ~~Ref: https://github.com/bkuhl/fpm-nginx/blob/master/Dockerfile~~ (this is inspiration for the "mix")
# Ref: https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine/Dockerfile
ARG NJS_VERSION
ENV PKG_RELEASE 1
RUN set -x \
# create nginx user/group first, to be consistent throughout docker variants
&& addgroup -g 101 -S nginx \
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
&& apkArch="$(cat /etc/apk/arch)" \
&& nginxPackages=" \
nginx=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-xslt=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-geoip=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-image-filter=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-r${PKG_RELEASE} \
" \
&& case "$apkArch" in \
x86_64|aarch64) \
# arches officially built by upstream
set -x \
&& KEY_SHA512="e7fa8303923d9b95db37a77ad46c68fd4755ff935d0a534d26eba83de193c76166c68bfe7f65471bf8881004ef4aa6df3e34689c305662750c0172fca5d8552a *stdin" \
&& apk add --no-cache --virtual .cert-deps \
openssl \
&& wget -O /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub \
&& if [ "$(openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout | openssl sha512 -r)" = "$KEY_SHA512" ]; then \
echo "key verification succeeded!"; \
mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/; \
else \
echo "key verification failed!"; \
exit 1; \
fi \
&& apk del .cert-deps \
&& apk add -X "https://nginx.org/packages/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages \
;; \
*) \
# we're on an architecture upstream doesn't officially build for
# let's build binaries from the published packaging sources
set -x \
&& tempDir="$(mktemp -d)" \
&& chown nobody:nobody $tempDir \
&& apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
bash \
alpine-sdk \
findutils \
&& su nobody -s /bin/sh -c " \
export HOME=${tempDir} \
&& cd ${tempDir} \
&& hg clone https://hg.nginx.org/pkg-oss \
&& cd pkg-oss \
&& hg up ${NGINX_VERSION}-${PKG_RELEASE} \
&& cd alpine \
&& make all \
&& apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
&& abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz \
" \
&& cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/ \
&& apk del .build-deps \
&& apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages \
;; \
esac \
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& if [ -n "$tempDir" ]; then rm -rf "$tempDir"; fi \
&& if [ -n "/etc/apk/keys/abuild-key.rsa.pub" ]; then rm -f /etc/apk/keys/abuild-key.rsa.pub; fi \
&& if [ -n "/etc/apk/keys/nginx_signing.rsa.pub" ]; then rm -f /etc/apk/keys/nginx_signing.rsa.pub; fi \
# Bring in gettext so we can get `envsubst`, then throw
# the rest away. To do this, we need to install `gettext`
# then move `envsubst` out of the way so `gettext` can
# be deleted completely, then move `envsubst` back.
&& apk add --no-cache --virtual .gettext gettext \
&& mv /usr/bin/envsubst /tmp/ \
\
&& runDeps="$( \
scanelf --needed --nobanner /tmp/envsubst \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --no-cache $runDeps \
&& apk del .gettext \
&& mv /tmp/envsubst /usr/local/bin/ \
# Bring in tzdata so users could set the timezones through the environment
# variables
&& apk add --no-cache tzdata \
# Bring in curl and ca-certificates to make registering on DNS SD easier
&& apk add --no-cache curl ca-certificates \
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Make the environment friendly for interactive use during development
WORKDIR /project
CMD ["/bin/sh"]