fiddle with docker

This commit is contained in:
Codex Agent
2025-11-15 17:00:57 +01:00
parent 4981d9f060
commit 5348c5b137
3 changed files with 159 additions and 107 deletions

View File

@@ -4,7 +4,7 @@
ARG NODE_VERSION=20
################################################################################
# Composer dependencies (install vendor/)
# Composer dependencies
################################################################################
FROM composer:2 AS vendor
@@ -30,7 +30,12 @@
WORKDIR /var/www/html
RUN apt-get update \
&& apt-get install -y --no-install-recommends php-cli php-mbstring php-xml php-curl php-zip \
&& apt-get install -y --no-install-recommends \
php-cli \
php-mbstring \
php-xml \
php-curl \
php-zip \
&& rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json ./
@@ -53,7 +58,7 @@
APP_DEBUG=false \
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0
WORKDIR /opt/app
WORKDIR /var/www/html
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
@@ -71,7 +76,7 @@
nano \
rsync \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \
&& docker-php-ext-install -j"$(nproc)" \
bcmath \
exif \
gd \
@@ -89,11 +94,19 @@
COPY --from=vendor /var/www/html/vendor ./vendor
COPY --from=node_builder /var/www/html/public/build ./public/build
COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
RUN mkdir -p /opt/app \
&& rsync -a /var/www/html/ /opt/app/ \
&& chown -R www-data:www-data /opt/app
RUN groupmod -o -g "$GID" www-data \
&& usermod -o -u "$UID" -g www-data www-data
COPY docker/php/php.ini /usr/local/etc/php/conf.d/zz-app.ini
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/zz-opcache.ini
COPY docker/app/entrypoint.sh /usr/local/bin/app-entrypoint
RUN chmod +x /usr/local/bin/app-entrypoint
EXPOSE 9000
ENTRYPOINT ["app-entrypoint"]
CMD ["php-fpm"]

View File

@@ -47,12 +47,23 @@ services:
condition: service_healthy
redis:
condition: service_started
healthcheck:
test:
- CMD
- php
- -r
- "exit(file_exists('/var/www/html/vendor/autoload.php') ? 0 : 1);"
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
web:
image: nginx:1.27-alpine
depends_on:
- app
app:
condition: service_healthy
volumes:
- app-code:/var/www/html:ro
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
@@ -78,11 +89,14 @@ services:
command: /var/www/html/docs/queue-supervisor/queue-worker.sh default
environment:
<<: *app-env
SKIP_CODE_SYNC: "1"
volumes:
- app-code:/var/www/html
depends_on:
- app
- redis
app:
condition: service_healthy
redis:
condition: service_started
restart: unless-stopped
media-storage-worker:
@@ -92,11 +106,14 @@ services:
<<: *app-env
QUEUE_TRIES: 5
QUEUE_SLEEP: 5
SKIP_CODE_SYNC: "1"
volumes:
- app-code:/var/www/html
depends_on:
- app
- redis
app:
condition: service_healthy
redis:
condition: service_started
restart: unless-stopped
scheduler:
@@ -104,10 +121,12 @@ services:
command: php artisan schedule:work
environment:
<<: *app-env
SKIP_CODE_SYNC: "1"
volumes:
- app-code:/var/www/html
depends_on:
- app
app:
condition: service_healthy
restart: unless-stopped
horizon:
@@ -115,11 +134,14 @@ services:
command: /var/www/html/docs/queue-supervisor/horizon.sh
environment:
<<: *app-env
SKIP_CODE_SYNC: "1"
volumes:
- app-code:/var/www/html
depends_on:
- app
- redis
app:
condition: service_healthy
redis:
condition: service_started
restart: unless-stopped
redis:

View File

@@ -1,33 +1,50 @@
#!/usr/bin/env bash
set -euo pipefail
APP_SOURCE=${APP_SOURCE:-/opt/app}
APP_TARGET=${APP_TARGET:-/var/www/html}
APP_USER=${APP_USER:-www-data}
APP_GROUP=${APP_GROUP:-www-data}
SKIP_CODE_SYNC=${SKIP_CODE_SYNC:-0}
mkdir -p "${APP_TARGET}"
sync_code() {
if [[ "$SKIP_CODE_SYNC" == "1" ]]; then
return
fi
# Sync the built application from the immutable image into the shared app volume
# while preserving runtime data that lives under storage/.
rsync -a --delete \
--exclude storage \
--exclude public/storage \
--exclude bootstrap/cache \
--exclude .env \
"${APP_SOURCE}/" "${APP_TARGET}/"
if [[ ! -d "$APP_TARGET" ]]; then
mkdir -p "$APP_TARGET"
fi
cd "${APP_TARGET}"
rsync -a --delete --omit-dir-times --no-perms --no-owner --no-group \
--exclude="storage/logs" \
--exclude="storage/framework/sessions" \
"$APP_SOURCE"/ "$APP_TARGET"/ || true
mkdir -p storage/framework/{cache,sessions,testing,views} storage/logs bootstrap/cache
chown -R "${APP_USER}:${APP_GROUP}" storage bootstrap/cache || true
find storage -type d -exec chmod 775 {} \;
find storage -type f -exec chmod 664 {} \;
chmod -R ug+rwx bootstrap/cache
chown -R "$APP_USER:$APP_GROUP" "$APP_TARGET"
}
php artisan config:cache --quiet || true
php artisan route:cache --quiet || true
php artisan event:cache --quiet || true
ensure_helper_scripts() {
if compgen -G "$APP_TARGET/docs/queue-supervisor/*.sh" > /dev/null; then
chmod +x "$APP_TARGET"/docs/queue-supervisor/*.sh || true
fi
}
prepare_storage() {
cd "$APP_TARGET"
if [[ ! -h public/storage ]]; then
php artisan storage:link >/dev/null 2>&1 || true
fi
if [[ -n "${PENDING_MIGRATIONS:-}" ]]; then
php artisan migrate --force >/dev/null 2>&1 || true
fi
}
sync_code
ensure_helper_scripts
prepare_storage
cd "$APP_TARGET"
exec "$@"