refactor: entrypoint with WWWUSER/WWWGROUP for FPM UID/GID mapping
- Entrypoint remaps www-data to host UID/GID via WWWUSER/WWWGROUP env vars - Moves composer install, storage setup, migrate into entrypoint - Removes inline command from docker-compose - Defaults to 1000:1000, configurable via .env
This commit is contained in:
parent
3832aaa9d8
commit
04ef0b08c8
|
|
@ -84,3 +84,7 @@ UPLOAD_TEMP_DIR=/tmp
|
||||||
# TestData
|
# TestData
|
||||||
TEST_CTS_USERNAME=
|
TEST_CTS_USERNAME=
|
||||||
TEST_CTS_PASSWORD=
|
TEST_CTS_PASSWORD=
|
||||||
|
|
||||||
|
# Docker: map FPM worker to host user (run `id -u` and `id -g`)
|
||||||
|
WWWUSER=1000
|
||||||
|
WWWGROUP=1000
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,13 @@ WORKDIR /app
|
||||||
COPY build/fpm-healthcheck.conf /usr/local/etc/php-fpm.d/zz-healthcheck.conf
|
COPY build/fpm-healthcheck.conf /usr/local/etc/php-fpm.d/zz-healthcheck.conf
|
||||||
COPY build/php-error-logging.conf /usr/local/etc/php-fpm.d/zz-error-logging.conf
|
COPY build/php-error-logging.conf /usr/local/etc/php-fpm.d/zz-error-logging.conf
|
||||||
COPY build/php-errors.ini /usr/local/etc/php/conf.d/errors.ini
|
COPY build/php-errors.ini /usr/local/etc/php/conf.d/errors.ini
|
||||||
|
COPY build/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 9000
|
EXPOSE 9000
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
||||||
CMD SCRIPT_NAME=/ping SCRIPT_FILENAME=/ping REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000 | grep -q pong || exit 1
|
CMD SCRIPT_NAME=/ping SCRIPT_FILENAME=/ping REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000 | grep -q pong || exit 1
|
||||||
|
|
||||||
|
ENTRYPOINT ["entrypoint.sh"]
|
||||||
CMD ["php-fpm"]
|
CMD ["php-fpm"]
|
||||||
|
|
|
||||||
20
build/entrypoint.sh
Executable file
20
build/entrypoint.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -n "$WWWUSER" ] && [ "$WWWUSER" != "0" ]; then
|
||||||
|
deluser www-data 2>/dev/null || true
|
||||||
|
adduser -D -u "$WWWUSER" -G www-data www-data 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$WWWGROUP" ] && [ "$WWWGROUP" != "0" ]; then
|
||||||
|
delgroup www-data 2>/dev/null || true
|
||||||
|
addgroup -g "$WWWGROUP" www-data 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
composer install --no-interaction
|
||||||
|
mkdir -p storage/logs storage/framework/views storage/framework/cache storage/framework/sessions
|
||||||
|
chown -R www-data:www-data storage bootstrap/cache
|
||||||
|
chmod -R 775 storage bootstrap/cache
|
||||||
|
php artisan migrate --force
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
|
|
@ -6,14 +6,9 @@ services:
|
||||||
container_name: pp-planer-app
|
container_name: pp-planer-app
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
command: >-
|
|
||||||
sh -c "composer install --no-interaction
|
|
||||||
&& mkdir -p storage/logs storage/framework/views storage/framework/cache
|
|
||||||
&& chown -R www-data:www-data storage bootstrap/cache
|
|
||||||
&& chmod -R 775 storage bootstrap/cache
|
|
||||||
&& php artisan migrate --force
|
|
||||||
&& php-fpm"
|
|
||||||
environment:
|
environment:
|
||||||
|
- WWWUSER=${WWWUSER:-1000}
|
||||||
|
- WWWGROUP=${WWWGROUP:-1000}
|
||||||
- APP_ENV=${APP_ENV}
|
- APP_ENV=${APP_ENV}
|
||||||
- APP_DEBUG=${APP_DEBUG}
|
- APP_DEBUG=${APP_DEBUG}
|
||||||
- APP_KEY=${APP_KEY}
|
- APP_KEY=${APP_KEY}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue