Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add health check for nginx and php fpm. Add dependencies. #704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,6 +52,7 @@ RUN apk update && \
# production dependencies
apk add --no-cache \
icu-libs \
fcgi \
libjpeg-turbo \
libpng \
libwebp \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion app/Console/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions docker/php/www.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions docker/s6-rc.d/laravel/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/command/with-contenv sh

# Exit on error
set -e

cd /var/www

php artisan migrate --force
Expand All @@ -14,3 +17,5 @@ php artisan view:cache
php artisan icons:cache

php artisan about

exit 0
10 changes: 10 additions & 0 deletions docker/s6-rc.d/nginx/data/check
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docker/s6-rc.d/nginx/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
php
1 change: 1 addition & 0 deletions docker/s6-rc.d/nginx/notification-fd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
5 changes: 3 additions & 2 deletions docker/s6-rc.d/nginx/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh -e

#!/command/execlineb -P
with-contenv
s6-notifyoncheck
nginx
2 changes: 2 additions & 0 deletions docker/s6-rc.d/php/data/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/command/with-contenv sh
FCGI_CONNECT=/run/php-fpm.sock php-fpm-healthcheck
1 change: 1 addition & 0 deletions docker/s6-rc.d/php/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
laravel
1 change: 1 addition & 0 deletions docker/s6-rc.d/php/notification-fd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
5 changes: 3 additions & 2 deletions docker/s6-rc.d/php/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/command/with-contenv sh

#!/command/execlineb -P
with-contenv
s6-notifyoncheck -d
php-fpm