-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
447 lines (384 loc) · 16 KB
/
Dockerfile
File metadata and controls
447 lines (384 loc) · 16 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
ARG PHP_VERSION="latest"
ARG COMPOSER_VERSION="latest"
ARG FRANKENPHP_VERSION="latest"
ARG RR_VERSION="latest"
ARG MAGO_VERSION="latest"
ARG NODE_VERSION="latest"
ARG DENO_VERSION="latest"
ARG BUN_VERSION="latest"
ARG S6_VERSION="latest"
### Only add images here that can be set with versions via Build Arguments.
### The purpose of this block is to cache these images when building the
### main image at the very beginning of that GitHub Actions Workflow.
# Common images start
FROM composer:${COMPOSER_VERSION} AS composer-image
FROM node:${NODE_VERSION} AS node-image
FROM dunglas/frankenphp:${FRANKENPHP_VERSION} AS frankenphp-image
FROM ghcr.io/roadrunner-server/roadrunner:${RR_VERSION} AS roadrunner-image
FROM denoland/deno:${DENO_VERSION} AS deno-image
FROM oven/bun:${BUN_VERSION} AS bun-image
FROM ghcr.io/carthage-software/mago:${MAGO_VERSION} AS mago-image
# Common images end
FROM php:${PHP_VERSION}
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
ENV USER_PWD="developer"
ENV USER="developer"
ENV USER_ID=1000
ENV GROUP_ID=1000
ENV HOME="/home/$USER"
ENV PROJECT_PATH="/app"
ARG PHP_BASE_EXTENSIONS="opcache pdo_mysql pdo_pgsql mongodb redis intl bcmath zip xdebug sockets"
ARG PHP_EXTENSIONS=""
ENV PHP_RUNTIME_EXTENSIONS=""
ARG MYSQL_VERSION="latest"
ARG MARIADB_VERSION="latest"
ARG POSTGRESQL_VERSION="latest"
ARG MONGODB_VERSION="latest"
ENV COMPOSER_HOME="/composer"
ENV COMPOSER_CACHE_DIR="$COMPOSER_HOME/cache"
ENV COMPOSER_BIN_DIR="$COMPOSER_HOME/bin"
ENV COMPOSER_PACKAGES="laravel/installer laravel-zero/installer vildanbina/composer-upgrader ion-bazan/composer-diff laravel/pail rector/rector ergebnis/composer-normalize maglnet/composer-require-checker icanhazstring/composer-unused psy/psysh deptrac/deptrac halleck45/ast-metrics"
ENV COMPOSER_RUNTIME_PACKAGES=""
ENV PATH=$PATH:$COMPOSER_BIN_DIR:$COMPOSER_HOME/vendor/bin
ARG S6-VERSION="latest"
# Allow S6 to keep the environment variables.
ENV S6_KEEP_ENV=1
#
#--------------------------------------------------------------------------
# Default CLI interpreter
#--------------------------------------------------------------------------
#
SHELL ["/bin/bash", "-c"]
#
#--------------------------------------------------------------------------
# Common fixes
#--------------------------------------------------------------------------
#
# Fix APT for newer Debian > 10
RUN \
DEBIAN_VERSION_MAJOR=$(cat /etc/debian_version | cut -d'.' -f1) && \
if [ "$DEBIAN_VERSION_MAJOR" -gt 11 ]; then \
echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99custom && \
echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99custom && \
echo "Acquire::atp::No-Cache true;" >> /etc/apt/apt.conf.d/99custom && \
echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/99custom; \
fi
#
#--------------------------------------------------------------------------
# Install from layers
#--------------------------------------------------------------------------
#
# We're going to install all these utilities to the "/usr/local/bin" path
# because this is the place for manually installed command utilities.
#
# The rest of the tools only need a single binary to be copied
COPY --from=frankenphp-image /usr/local/bin/frankenphp /usr/local/bin/frankenphp
COPY --from=roadrunner-image /usr/bin/rr /usr/local/bin/rr
COPY --from=deno-image /usr/bin/deno /usr/local/bin/deno
COPY --from=bun-image /usr/local/bin/bun /usr/local/bin/bun
COPY --from=composer-image /usr/bin/composer /usr/local/bin/composer
COPY --from=mago-image /usr/local/bin/mago /usr/local/bin/mago
#
#--------------------------------------------------------------------------
# Package Manager - Switch to reachable repository
#--------------------------------------------------------------------------
#
COPY ./fixes/set_old_repository.sh /var/fixes/set_old_repository.sh
RUN /var/fixes/set_old_repository.sh
#
#--------------------------------------------------------------------------
# Package Manager - Install Base Software
#--------------------------------------------------------------------------
#
RUN \
echo "Setting base utilities for the container" > /dev/stdout && \
apt-get update && apt-get upgrade -y && \
# Add a retry logic on install (up to 3 times) \
for attempt in 1 2 3; do \
apt-get install -y --no-install-recommends --fix-missing \
curl \
ca-certificates \
dnsutils \
ffmpeg \
git \
gnupg \
gosu \
htop \
jq \
libcap2-bin \
libpng-dev \
librsvg2-bin \
lsb-release \
nano \
openssh-server \
python3 \
sudo \
unzip \
xz-utils \
zip && break || \
if [ "$attempt" -lt 3 ]; then \
echo "Attempt $attempt failed! Retrying..."; \
sleep 2; \
else \
echo "Final attempt failed. Exiting."; \
exit 1; \
fi; \
done && \
# Check if YQ is available. If not, don't install it. \
if apt-get install --dry-run yq &> /dev/null; then \
apt-get install -y --no-install-recommends yq; \
fi && \
# Check if FSWATCH is available. If not, don't install it. \
if apt-get install --dry-run fswatch &> /dev/null; then \
apt-get install -y --no-install-recommends fswatch; \
fi && \
# Clean installation leftovers \
apt-get -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#
#--------------------------------------------------------------------------
# Package Manager - Install Database CLI and Node via external repositories
#--------------------------------------------------------------------------
#
COPY ./fixes/install_repositories_and_packages.sh /var/fixes/install_repositories_and_packages.sh
RUN /var/fixes/install_repositories_and_packages.sh
#
#--------------------------------------------------------------------------
# Package Manager - Install PHP base Extensions
#--------------------------------------------------------------------------
#
# Add the PHP Extension installer
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN set -e; \
for EXT in $PHP_BASE_EXTENSIONS; do \
echo "Attempting to install $EXT..."; \
# Try the base extension first \
if install-php-extensions "$EXT"; then \
echo "✅ $EXT installed successfully."; \
else \
# Check if the failing extension is 'swoole' \
if [ "$EXT" = "swoole" ]; then \
echo "⚠️ Standard install failed for $EXT. Trying pre-release suffixes..."; \
\
FOUND=false; \
for SUFFIX in "-rc" "-beta" "-alpha" "-devel" "-snapshot"; do \
echo "Testing $EXT$SUFFIX..."; \
if install-php-extensions "$EXT$SUFFIX"; then \
echo "✅ Successfully installed $EXT as $EXT$SUFFIX"; \
FOUND=true; \
break; \
fi; \
done; \
\
if [ "$FOUND" = false ]; then \
echo "❌ Could not install $EXT with any known suffix."; \
exit 1; \
fi; \
else \
# Fail immediately for any other extension \
echo "❌ Failed to install $EXT. Suffixes are only permitted for 'swoole'."; \
exit 1; \
fi; \
fi; \
done
#
#--------------------------------------------------------------------------
# Package Manager - Enable PHP base Extensions
#--------------------------------------------------------------------------
#
RUN echo "Enabling PCNTL"; \
docker-php-ext-install pcntl
#
#--------------------------------------------------------------------------
# Package Manager - Complete Node Runtime install
#--------------------------------------------------------------------------
#
RUN \
apt-get update && \
# Install Node \
echo 'Installing Node' > /dev/stdout && \
apt-get install -y --no-install-recommends nodejs && \
# Enable Corepack \
if [ -f '/usr/bin/corepack' ]; then \
# Update Corepack \
echo 'Update Corepack' > /dev/stdout && \
npm install --global corepack@latest && \
# Enable NPM \
echo 'Enabling Corepack' > /dev/stdout && \
corepack enable && \
# Enable NPM \
echo 'Installing NPM via Corepack' > /dev/stdout && \
corepack install --global npm && \
# Enable Yarn \
echo 'Installing Yarn via Corepack' > /dev/stdout && \
corepack install --global yarn && \
# Yarn smoke test \
yarn -v && \
# Enable PNPM \
echo 'Installing PNPM via Corepack' > /dev/stdout && \
corepack install --global pnpm && \
# PNPM smoke test \
pnpm -v; \
else \
echo 'This version of Debian does not support Node Corepack' > /dev/stdout; \
fi && \
# Clean installation leftovers \
apt-get -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#
#--------------------------------------------------------------------------
# Install S6 Overlay
#--------------------------------------------------------------------------
#
# @see https://github.com/just-containers/s6-overlay
#
COPY ./fixes/install_s6_overlay.sh /var/fixes/install_s6_overlay.sh
RUN /var/fixes/install_s6_overlay.sh
# Copy the S6 Configuration files to the container.
COPY etc /etc
# Copy the default entrypoint
COPY entrypoint.sh /entrypoint.sh
# Set the entrypoint to S6 OVerlay custom INIT.
ENTRYPOINT ["/entrypoint.sh"]
#
#--------------------------------------------------------------------------
# User - Configuration
#--------------------------------------------------------------------------
#
COPY ./fixes/set_user.sh /var/fixes/set_user.sh
RUN /var/fixes/set_user.sh
#
#--------------------------------------------------------------------------
# SSH - Configuration
#--------------------------------------------------------------------------
#
RUN \
echo "Ensuring SSH directory can be accessed by ${USER}" > /dev/stdout && \
# Ensure SSH directories are permissive \
mkdir -p /ssh/sshd_config /ssh/sshd_keys && \
# Copy the SSH keys generated by OpenSSH Server \
cp /etc/ssh/ssh_host_{rsa,ecdsa,ed25519}_key /ssh/sshd_keys/ && \
chown -R ${USER_ID}:${GROUP_ID} /ssh && \
mkdir -p /run/sshd
#
#--------------------------------------------------------------------------
# Project - Configuration
#--------------------------------------------------------------------------
#
COPY ./fixes/set_symlinks.sh /var/fixes/set_symlinks.sh
RUN /var/fixes/set_symlinks.sh
#
#--------------------------------------------------------------------------
# Add PHP Extensions
#--------------------------------------------------------------------------
#
# We are going to install all the developer's PHP extensions as the last
# step. This will avoid running previous layers again, which will add
# to the build time, if an extension installation throws an error.
#
RUN \
echo "Installing additional PHP Extensions: $PHP_EXTENSIONS" > /dev/stdout && \
install-php-extensions $PHP_EXTENSIONS
#
#--------------------------------------------------------------------------
# Add PHPantom
#--------------------------------------------------------------------------
#
RUN \
curl -fsSL "https://github.com/AJenbo/phpantom_lsp/releases/latest/download/phpantom_lsp-x86_64-unknown-linux-gnu.tar.gz" | \
tar -xzf - -C /usr/local/bin && \
chown $USER_ID:$GROUP_ID /usr/local/bin/phpantom_lsp
#
#--------------------------------------------------------------------------
# Configure Composer
#--------------------------------------------------------------------------
#
# Ensure the Composer directories exists and are accessible.
RUN \
echo "Ensure Composer directory is '$COMPOSER_HOME' and the cache is '$COMPOSER_CACHE_DIR'" > /dev/stdout && \
mkdir ${COMPOSER_HOME} ${COMPOSER_CACHE_DIR} && \
chown ${USER_ID}:${GROUP_ID} -R /composer
# If we're using Composer on a non-supported PHP version, downgrade to LTS.
RUN \
if php -r "exit(version_compare(PHP_VERSION, '7.2.5', '<') ? 0 : 1);" ; then \
echo 'Downgrading Composer to version 2.2...'; \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --2.2; \
fi
# Enable plugins. It's a Docker Container, so it will only affect the container.
RUN \
echo 'Enabling plugins in Composer...' > /dev/stdout && \
sudo -E -u $USER /usr/local/bin/composer global config --no-plugins allow-plugins true
# Allow for dev packages but prefer stable
RUN \
echo 'Enabling dev packages with stable preferred...' > /dev/stdout && \
sudo -E -u $USER /usr/local/bin/composer global config --no-plugins minimum-stability dev && \
sudo -E -u $USER /usr/local/bin/composer global config --no-plugins prefer-stable true
# Let's also add some common composer utilities globally.
RUN \
# Separate Pail from the rest to avoid global failure on PHP 8.1 \
MAIN_PACKAGES="" && \
INSTALL_PAIL=false && \
for PKG in $COMPOSER_PACKAGES; do \
if [ "$PKG" = "laravel/pail" ]; then \
INSTALL_PAIL=true; \
else \
MAIN_PACKAGES="$MAIN_PACKAGES ${PKG}:*"; \
fi \
done && \
\
# 1. Install the compatible packages \
echo "Installing global packages: $MAIN_PACKAGES" > /dev/stdout && \
sudo -E -u $USER /usr/local/bin/composer global require --no-cache --prefer-stable --with-all-dependencies $MAIN_PACKAGES && \
\
# 2. Conditional install for Pail (only if PHP >= 8.2) \
if [ "$INSTALL_PAIL" = true ]; then \
echo "Checking PHP version for laravel/pail..." > /dev/stdout && \
if php -r "exit(version_compare(PHP_VERSION, '8.2.0', '>=') ? 0 : 1);"; then \
echo "PHP 8.2+ detected. Installing laravel/pail..." > /dev/stdout && \
sudo -E -u $USER /usr/local/bin/composer global require --no-cache --prefer-stable laravel/pail; \
else \
echo "Skipping laravel/pail: PHP version $(php -r 'echo PHP_VERSION;') is too old." > /dev/stderr; \
fi \
fi && \
\
# 3. Clean up \
sudo -E -u $USER /usr/local/bin/composer clear-cache
#
#--------------------------------------------------------------------------
# Runtime Fixes
#--------------------------------------------------------------------------
#
# Ensure all runtimes have access to privileged ports below 1024 (like 22, 80 or 443)
# Old Node sometimes installs itself as "nodejs", so use that if "node" doesn't exist.
RUN \
# Define the list of binaries to update \
BINARIES="/usr/sbin/sshd /usr/local/bin/rr /usr/local/bin/bun /usr/local/bin/php /usr/local/bin/deno /usr/local/bin/mago /usr/local/bin/composer /usr/local/bin/frankenphp /usr/local/bin/chromedriver" && \
\
# Handle the Node.js naming variance separately \
if [ -f /usr/bin/node ]; then BINARIES="$BINARIES /usr/bin/node"; \
elif [ -f /usr/bin/nodejs ]; then BINARIES="$BINARIES /usr/bin/nodejs"; fi && \
\
# Loop through the variable and apply capabilities if the file exists \
for bin in $BINARIES; do \
if [ -f "$bin" ]; then \
echo "Setting capabilities for $bin"; \
setcap "cap_net_bind_service=+ep" "$bin" || echo "Warning: Failed to set cap on $bin"; \
fi; \
done
#
#--------------------------------------------------------------------------
# Common fixes
#--------------------------------------------------------------------------
#
COPY ./fixes/set_timezone.sh /var/fixes/set_timezone.sh
RUN /var/fixes/set_timezone.sh
#
#--------------------------------------------------------------------------
# Make the container ready to use
#--------------------------------------------------------------------------
#
WORKDIR /app
CMD []