diff --git a/Dockerfile b/Dockerfile index 857021cc..ee8a8580 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,13 +28,11 @@ RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp RUN tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz -ENTRYPOINT ["/init"] - COPY docker/openssl/openssl.cnf /etc/ssl/openssl.cnf COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf COPY docker/php/php.ini /usr/local/etc/php/php.ini COPY docker/php/www.conf /usr/local/etc/php-fpm.d/zz-docker.conf -COPY docker/s6-rc.d /etc/s6-overlay/s6-rc.d +COPY --chmod=755 docker/s6-rc.d /etc/s6-overlay/s6-rc.d RUN apk update && \ # build dependencies @@ -54,6 +52,7 @@ RUN apk update && \ # production dependencies apk add --no-cache \ icu-libs \ + fcgi \ libjpeg-turbo \ libpng \ libwebp \ @@ -84,6 +83,8 @@ RUN apk update && \ # cleanup apk del -f .build-deps +RUN curl -o /usr/local/bin/php-fpm-healthcheck https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/master/php-fpm-healthcheck && chmod +x /usr/local/bin/php-fpm-healthcheck + ENV COMPOSER_ALLOW_SUPERUSER 1 ENV COMPOSER_HOME /tmp ENV COMPOSER_CACHE_DIR /dev/null @@ -112,6 +113,6 @@ ENV LOG_CHANNEL stderr ENV WEBSITE_FACTORY_EDITION ong -ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME 0 - EXPOSE 80 + +ENTRYPOINT ["/init"] diff --git a/app/Console/Commands/SetupCommand.php b/app/Console/Commands/SetupCommand.php index df6ea14a..526f3f3a 100644 --- a/app/Console/Commands/SetupCommand.php +++ b/app/Console/Commands/SetupCommand.php @@ -144,7 +144,7 @@ private function loadData(string $file): Collection try { $content = json_decode( - File::get(database_path("seeders/data/${edition}/${file}.json")), + File::get(database_path("seeders/data/{$edition}/{$file}.json")), true ); } catch (Throwable $th) { diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index 99b12efc..7d13a3de 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -107,6 +107,11 @@ http { root /var/www/public; + location /ping { + add_header Content-Type text/plain; + return 200 "pong\n"; + } + location / { try_files $uri $uri/ /index.php?$query_string; } diff --git a/docker/php/www.conf b/docker/php/www.conf index fba8abc4..7c3eec3d 100644 --- a/docker/php/www.conf +++ b/docker/php/www.conf @@ -51,6 +51,9 @@ pm.max_children = 32 ; Default Value: 10s pm.process_idle_timeout = 3s; +; This is needed for s6 overlay check +pm.status_path = /status + ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. diff --git a/docker/s6-rc.d/laravel/init.sh b/docker/s6-rc.d/laravel/init.sh index e21099aa..e2f25337 100755 --- a/docker/s6-rc.d/laravel/init.sh +++ b/docker/s6-rc.d/laravel/init.sh @@ -1,5 +1,8 @@ #!/command/with-contenv sh +# Exit on error +set -e + cd /var/www php artisan migrate --force @@ -14,3 +17,5 @@ php artisan view:cache php artisan icons:cache php artisan about + +exit 0 diff --git a/docker/s6-rc.d/nginx/data/check b/docker/s6-rc.d/nginx/data/check new file mode 100644 index 00000000..4a3cae2d --- /dev/null +++ b/docker/s6-rc.d/nginx/data/check @@ -0,0 +1,10 @@ +#!/command/with-contenv sh +response=$(curl --location --insecure --silent http://localhost/ping) + +if [ "$response" = "pong" ]; then + exit 0 +else + echo "❌ There seems to be a failure in checking the web server + PHP-FPM. Here's the response:" + echo $response + exit 1 +fi diff --git a/docker/s6-rc.d/nginx/dependencies b/docker/s6-rc.d/nginx/dependencies new file mode 100644 index 00000000..2c0ea7b5 --- /dev/null +++ b/docker/s6-rc.d/nginx/dependencies @@ -0,0 +1 @@ +php diff --git a/docker/s6-rc.d/nginx/notification-fd b/docker/s6-rc.d/nginx/notification-fd new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/docker/s6-rc.d/nginx/notification-fd @@ -0,0 +1 @@ +3 diff --git a/docker/s6-rc.d/nginx/run b/docker/s6-rc.d/nginx/run index 24937a5b..64591121 100644 --- a/docker/s6-rc.d/nginx/run +++ b/docker/s6-rc.d/nginx/run @@ -1,3 +1,4 @@ -#!/bin/sh -e - +#!/command/execlineb -P +with-contenv +s6-notifyoncheck nginx diff --git a/docker/s6-rc.d/php/data/check b/docker/s6-rc.d/php/data/check new file mode 100644 index 00000000..bded5419 --- /dev/null +++ b/docker/s6-rc.d/php/data/check @@ -0,0 +1,2 @@ +#!/command/with-contenv sh +FCGI_CONNECT=/run/php-fpm.sock php-fpm-healthcheck diff --git a/docker/s6-rc.d/php/dependencies b/docker/s6-rc.d/php/dependencies new file mode 100644 index 00000000..ff3a7516 --- /dev/null +++ b/docker/s6-rc.d/php/dependencies @@ -0,0 +1 @@ +laravel diff --git a/docker/s6-rc.d/php/notification-fd b/docker/s6-rc.d/php/notification-fd new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/docker/s6-rc.d/php/notification-fd @@ -0,0 +1 @@ +3 diff --git a/docker/s6-rc.d/php/run b/docker/s6-rc.d/php/run index f215c3e6..e6b2600d 100644 --- a/docker/s6-rc.d/php/run +++ b/docker/s6-rc.d/php/run @@ -1,3 +1,4 @@ -#!/command/with-contenv sh - +#!/command/execlineb -P +with-contenv +s6-notifyoncheck -d php-fpm