Refactoring

This commit is contained in:
Jonatan Rek committed 2026-10-31 19:16:51 +01:00
1 parent 085ab7e9b8
commit 411f7be896
29 files changed
+219 -50

No files matched your search

+4 -6
View File
@@ -112,12 +112,10 @@ opcache.fast_shutdown=1" >> "$PHP_INI_DIR/conf.d/opcache.ini"
#SUPERVISORD #SUPERVISORD
RUN mkdir -p /var/log/supervisor RUN mkdir -p /var/log/supervisor
COPY ./supervisor/supervisord.conf /etc/supervisor/supervisord.conf COPY ./supervisor.d/ /etc/supervisor/conf.d/
COPY ./supervisor/conf.d/laravel-queues.conf /etc/supervisor/conf.d/laravel-queues.conf
# Setup Crone #ENTRYPOINTS
RUN mkdir -p /var/log/cron && \ COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/
echo "* * * * * www-data cd ${APP_ROOT} && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1" >> /etc/crontab
# Install composer # bun # Install composer # bun
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
@@ -126,7 +124,7 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf && \ RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf && \
sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf && \ sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf && \
sed -i 's/^exec /printenv > \/etc\/environment\n\nexec /' /usr/local/bin/apache2-foreground && \ sed -i 's/^exec /printenv > \/etc\/environment\n\nexec /' /usr/local/bin/apache2-foreground && \
sed -i 's/^exec /service cron start\n\nexec /' /usr/local/bin/apache2-foreground sed -i 's#^exec #for f in /etc/entrypoint.d/*.sh; do if [ -x "$f" ]; then "$f" || { echo "entrypoint script failed: $f" >\&2; exit 1; }; fi; done\n\nexec #' /usr/local/bin/apache2-foreground
#Cleaning #Cleaning
RUN apt-get clean && \ RUN apt-get clean && \
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
for ini in "${PHP_INI_DIR}"/conf.d/*opcache.ini; do
if [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" = "false" ]; then
sed -ri -e "s!opcache.validate_timestamps=.*!opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS:-1}!g" "$ini"
else
sed -ri -e 's!opcache.enable=1!opcache.enable=0!g' "$ini"
fi
done
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
# Composer dependencies
[ -f composer.json ] || exit 0
if [ "$init" = "true" ] || [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" = "true" ]; then
echo "Initial setup nebo debug mód - instalace Composeru s dev závislostmi"
composer install --prefer-dist --optimize-autoloader
else
echo "Produkční instalace - Composer bez dev závislostí"
composer install --prefer-dist --no-dev --optimize-autoloader
fi
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
# Prepares .env. When /config is mounted, .env is restored from /config/.env and saved there on first creation.
cd "${APP_ROOT:-/var/www/html}" || exit 0
[ -f artisan ] || exit 0
if [ -d /config ] && [ -f /config/.env ]; then
echo "Using existing /config/.env"
cp /config/.env .env
elif [ ! -f .env ] && [ -f .env.example ]; then
echo "Creating .env from example"
cp .env.example .env
chown "$(stat -c %u:%g .env.example)" .env
if [ -d /config ]; then
cp .env /config/.env
fi
fi
+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
# Generates APP_KEY only when none exists yet (env or .env), so an existing key is never rotated.
cd "${APP_ROOT:-/var/www/html}" || exit 0
[ -f artisan ] || exit 0
[ -f .env ] || exit 0
[ -n "$APP_KEY" ] && exit 0
if ! grep -Eq '^APP_KEY=.+' .env; then
echo "Generating application key"
php artisan key:generate --force --no-interaction
[ -d /config ] && cp .env /config/.env
fi
exit 0
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
# Clear Laravel caches
[ -f artisan ] || exit 0
echo "Clearing Laravel caches"
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
# SQLite database initialization
if { grep -iq "^DB_CONNECTION=sqlite" .env && [ "$DB_CONNECTION" = "sqlite" ]; } || [ "$DEPLOY_ENV" = "sqlite" ]; then
if [ ! -f database/database.sqlite ]; then
echo "Creating empty SQLite database"
touch database/database.sqlite
fi
fi
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
# Link storage and seed database if first init
[ -f artisan ] || exit 0
echo "Linking storage directory"
php artisan storage:link
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
# Migrate database
[ -f artisan ] || exit 0
echo "Running database migrations"
php artisan migrate --force --no-interaction
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
cat > /etc/supervisor/supervisord.conf <<'EOF'
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
[include]
files = /etc/supervisor/conf.d/*.conf
EOF
# nodaemon=true keeps supervisord in the foreground, so detach it here
supervisord -c /etc/supervisor/supervisord.conf &
@@ -0,0 +1,6 @@
[program:scheduler]
command=/usr/local/bin/php %(ENV_APP_ROOT)s/artisan schedule:work
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/scheduler.log
+8
View File
@@ -0,0 +1,8 @@
; Example only, not loaded (supervisor includes just *.conf).
; To enable it, copy it to /etc/supervisor/conf.d/reverb.conf (or rename it to reverb.conf in supervisor.d).
[program:reverb]
command=/usr/local/bin/php %(ENV_APP_ROOT)s/artisan reverb:start --host=0.0.0.0 --no-interaction --debug
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/reverb.log
-6
View File
@@ -1,6 +0,0 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
[include]
files = /etc/supervisor/conf.d/*.conf
+5 -15
View File
@@ -4,8 +4,6 @@ FROM php:8.4-fpm-alpine
ENV APP_ROOT="/var/www/html" ENV APP_ROOT="/var/www/html"
ENV TZ="Europe/Prague" \ ENV TZ="Europe/Prague" \
ENABLE_CRON=0 \
ENABLE_SUPERVISOR=0 \
COMPOSER_ALLOW_SUPERUSER=1 \ COMPOSER_ALLOW_SUPERUSER=1 \
PHP_OPCACHE_ENABLE=1 \ PHP_OPCACHE_ENABLE=1 \
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
@@ -107,20 +105,12 @@ RUN { \
echo "opcache.save_comments=1"; \ echo "opcache.save_comments=1"; \
} > "$PHP_INI_DIR/conf.d/10-opcache.ini" } > "$PHP_INI_DIR/conf.d/10-opcache.ini"
# Supervisor (queue workers, started when ENABLE_SUPERVISOR=1) # Supervisor (queue workers + scheduler, started from entrypoint.d/90-supervisord.sh)
RUN mkdir -p /var/log/supervisor RUN mkdir -p /var/log/supervisor
COPY ./supervisor/supervisord.conf /etc/supervisor/supervisord.conf COPY ./supervisor.d/ /etc/supervisor/conf.d/
COPY ./supervisor/conf.d/laravel-queues.conf /etc/supervisor/conf.d/laravel-queues.conf
# Cron (Laravel scheduler, started when ENABLE_CRON=1) # Entrypoint scripts (run in order from the stock entrypoint)
RUN mkdir -p /var/log/cron && \ COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/
echo "* * * * * cd ${APP_ROOT} && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1" > /etc/crontabs/www-data RUN sed -i 's#^exec #for f in /etc/entrypoint.d/*.sh; do if [ -x "$f" ]; then "$f" || { echo "entrypoint script failed: $f" >\&2; exit 1; }; fi; done\n\nexec #' /usr/local/bin/docker-php-entrypoint
# Entrypoint
COPY ./docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
WORKDIR ${APP_ROOT} WORKDIR ${APP_ROOT}
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["php-fpm"]
-17
View File
@@ -1,17 +0,0 @@
#!/bin/sh
set -e
# Optional background services, only started together with php-fpm so that
# one-off commands (php artisan ..., composer ...) are passed through untouched.
case "$1" in
php-fpm*)
if [ "${ENABLE_CRON:-0}" = "1" ]; then
crond -b -L /var/log/cron/cron.log
fi
if [ "${ENABLE_SUPERVISOR:-0}" = "1" ]; then
supervisord -c /etc/supervisor/supervisord.conf
fi
;;
esac
exec docker-php-entrypoint "$@"
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
for ini in "${PHP_INI_DIR}"/conf.d/*opcache.ini; do
if [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" = "false" ]; then
sed -ri -e "s!opcache.validate_timestamps=.*!opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS:-1}!g" "$ini"
else
sed -ri -e 's!opcache.enable=1!opcache.enable=0!g' "$ini"
fi
done
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
# Composer dependencies
[ -f composer.json ] || exit 0
if [ "$init" = "true" ] || [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" = "true" ]; then
echo "Initial setup nebo debug mód - instalace Composeru s dev závislostmi"
composer install --prefer-dist --optimize-autoloader
else
echo "Produkční instalace - Composer bez dev závislostí"
composer install --prefer-dist --no-dev --optimize-autoloader
fi
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
# Prepares .env. When /config is mounted, .env is restored from /config/.env and saved there on first creation.
cd "${APP_ROOT:-/var/www/html}" || exit 0
[ -f artisan ] || exit 0
if [ -d /config ] && [ -f /config/.env ]; then
echo "Using existing /config/.env"
cp /config/.env .env
elif [ ! -f .env ] && [ -f .env.example ]; then
echo "Creating .env from example"
cp .env.example .env
chown "$(stat -c %u:%g .env.example)" .env
if [ -d /config ]; then
cp .env /config/.env
fi
fi
+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
# Generates APP_KEY only when none exists yet (env or .env), so an existing key is never rotated.
cd "${APP_ROOT:-/var/www/html}" || exit 0
[ -f artisan ] || exit 0
[ -f .env ] || exit 0
[ -n "$APP_KEY" ] && exit 0
if ! grep -Eq '^APP_KEY=.+' .env; then
echo "Generating application key"
php artisan key:generate --force --no-interaction
[ -d /config ] && cp .env /config/.env
fi
exit 0
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
# Clear Laravel caches
[ -f artisan ] || exit 0
echo "Clearing Laravel caches"
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
# SQLite database initialization
if { grep -iq "^DB_CONNECTION=sqlite" .env && [ "$DB_CONNECTION" = "sqlite" ]; } || [ "$DEPLOY_ENV" = "sqlite" ]; then
if [ ! -f database/database.sqlite ]; then
echo "Creating empty SQLite database"
touch database/database.sqlite
fi
fi
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
# Link storage and seed database if first init
[ -f artisan ] || exit 0
echo "Linking storage directory"
php artisan storage:link
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
# Migrate database
[ -f artisan ] || exit 0
echo "Running database migrations"
php artisan migrate --force --no-interaction
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
cat > /etc/supervisor/supervisord.conf <<'EOF'
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
[include]
files = /etc/supervisor/conf.d/*.conf
EOF
# nodaemon=true keeps supervisord in the foreground, so detach it here
supervisord -c /etc/supervisor/supervisord.conf &
@@ -0,0 +1,6 @@
[program:scheduler]
command=/usr/local/bin/php %(ENV_APP_ROOT)s/artisan schedule:work
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/scheduler.log
@@ -0,0 +1,8 @@
; Example only, not loaded (supervisor includes just *.conf).
; To enable it, copy it to /etc/supervisor/conf.d/reverb.conf (or rename it to reverb.conf in supervisor.d).
[program:reverb]
command=/usr/local/bin/php %(ENV_APP_ROOT)s/artisan reverb:start --host=0.0.0.0 --no-interaction --debug
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/reverb.log
-6
View File
@@ -1,6 +0,0 @@
[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/run/supervisord.pid
[include]
files = /etc/supervisor/conf.d/*.conf