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

@@ -1,99 +1,112 @@
# syntax=docker/dockerfile:1.6 # syntax=docker/dockerfile:1.6
ARG PHP_VERSION=8.3 ARG PHP_VERSION=8.3
ARG NODE_VERSION=20 ARG NODE_VERSION=20
################################################################################ ################################################################################
# Composer dependencies (install vendor/) # Composer dependencies
################################################################################ ################################################################################
FROM composer:2 AS vendor FROM composer:2 AS vendor
WORKDIR /var/www/html WORKDIR /var/www/html
COPY composer.json composer.lock ./ COPY composer.json composer.lock ./
RUN composer install \ RUN composer install \
--no-dev \ --no-dev \
--no-scripts \ --no-scripts \
--no-interaction \ --no-interaction \
--prefer-dist \ --prefer-dist \
--optimize-autoloader \ --optimize-autoloader \
--ignore-platform-reqs --ignore-platform-reqs
COPY . . COPY . .
################################################################################ ################################################################################
# Node build stage - compile front-end assets (needs PHP + vendor) # Node build stage - compile front-end assets (needs PHP + vendor)
################################################################################ ################################################################################
FROM node:${NODE_VERSION}-bookworm AS node_builder FROM node:${NODE_VERSION}-bookworm AS node_builder
WORKDIR /var/www/html WORKDIR /var/www/html
RUN apt-get update \ 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 \
&& rm -rf /var/lib/apt/lists/* php-cli \
php-mbstring \
php-xml \
php-curl \
php-zip \
&& rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
RUN npm ci --no-audit --prefer-offline RUN npm ci --no-audit --prefer-offline
COPY . . COPY . .
COPY --from=vendor /var/www/html/vendor ./vendor COPY --from=vendor /var/www/html/vendor ./vendor
RUN npm run build RUN npm run build
################################################################################ ################################################################################
# PHP-FPM runtime image # PHP-FPM runtime image
################################################################################ ################################################################################
FROM php:${PHP_VERSION}-fpm-bullseye AS app FROM php:${PHP_VERSION}-fpm-bullseye AS app
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
ENV APP_ENV=production \ ENV APP_ENV=production \
APP_DEBUG=false \ APP_DEBUG=false \
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 PHP_OPCACHE_VALIDATE_TIMESTAMPS=0
WORKDIR /opt/app WORKDIR /var/www/html
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
git \ git \
curl \ curl \
libjpeg62-turbo-dev \ libjpeg62-turbo-dev \
libpng-dev \ libpng-dev \
libfreetype6-dev \ libfreetype6-dev \
libzip-dev \ libzip-dev \
libonig-dev \ libonig-dev \
libicu-dev \ libicu-dev \
libxml2-dev \ libxml2-dev \
libmagickwand-dev \ libmagickwand-dev \
unzip \ unzip \
nano \ nano \
rsync \ rsync \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \ && docker-php-ext-install -j"$(nproc)" \
bcmath \ bcmath \
exif \ exif \
gd \ gd \
intl \ intl \
opcache \ opcache \
pcntl \ pcntl \
pdo_mysql \ pdo_mysql \
zip \ zip \
&& pecl install redis imagick \ && pecl install redis imagick \
&& docker-php-ext-enable redis imagick \ && docker-php-ext-enable redis imagick \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY . . COPY . .
COPY --from=vendor /var/www/html/vendor ./vendor COPY --from=vendor /var/www/html/vendor ./vendor
COPY --from=node_builder /var/www/html/public/build ./public/build COPY --from=node_builder /var/www/html/public/build ./public/build
COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini RUN mkdir -p /opt/app \
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini && rsync -a /var/www/html/ /opt/app/ \
COPY docker/app/entrypoint.sh /usr/local/bin/app-entrypoint && chown -R www-data:www-data /opt/app
RUN chmod +x /usr/local/bin/app-entrypoint
EXPOSE 9000 RUN groupmod -o -g "$GID" www-data \
ENTRYPOINT ["app-entrypoint"] && usermod -o -u "$UID" -g www-data www-data
CMD ["php-fpm"]
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 condition: service_healthy
redis: redis:
condition: service_started 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 restart: unless-stopped
web: web:
image: nginx:1.27-alpine image: nginx:1.27-alpine
depends_on: depends_on:
- app app:
condition: service_healthy
volumes: volumes:
- app-code:/var/www/html:ro - app-code:/var/www/html:ro
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf: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 command: /var/www/html/docs/queue-supervisor/queue-worker.sh default
environment: environment:
<<: *app-env <<: *app-env
SKIP_CODE_SYNC: "1"
volumes: volumes:
- app-code:/var/www/html - app-code:/var/www/html
depends_on: depends_on:
- app app:
- redis condition: service_healthy
redis:
condition: service_started
restart: unless-stopped restart: unless-stopped
media-storage-worker: media-storage-worker:
@@ -92,11 +106,14 @@ services:
<<: *app-env <<: *app-env
QUEUE_TRIES: 5 QUEUE_TRIES: 5
QUEUE_SLEEP: 5 QUEUE_SLEEP: 5
SKIP_CODE_SYNC: "1"
volumes: volumes:
- app-code:/var/www/html - app-code:/var/www/html
depends_on: depends_on:
- app app:
- redis condition: service_healthy
redis:
condition: service_started
restart: unless-stopped restart: unless-stopped
scheduler: scheduler:
@@ -104,10 +121,12 @@ services:
command: php artisan schedule:work command: php artisan schedule:work
environment: environment:
<<: *app-env <<: *app-env
SKIP_CODE_SYNC: "1"
volumes: volumes:
- app-code:/var/www/html - app-code:/var/www/html
depends_on: depends_on:
- app app:
condition: service_healthy
restart: unless-stopped restart: unless-stopped
horizon: horizon:
@@ -115,11 +134,14 @@ services:
command: /var/www/html/docs/queue-supervisor/horizon.sh command: /var/www/html/docs/queue-supervisor/horizon.sh
environment: environment:
<<: *app-env <<: *app-env
SKIP_CODE_SYNC: "1"
volumes: volumes:
- app-code:/var/www/html - app-code:/var/www/html
depends_on: depends_on:
- app app:
- redis condition: service_healthy
redis:
condition: service_started
restart: unless-stopped restart: unless-stopped
redis: redis:
@@ -159,4 +181,4 @@ volumes:
networks: networks:
coolify: coolify:
external: true external: true

View File

@@ -1,33 +1,50 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
APP_SOURCE=${APP_SOURCE:-/opt/app} APP_SOURCE=${APP_SOURCE:-/opt/app}
APP_TARGET=${APP_TARGET:-/var/www/html} APP_TARGET=${APP_TARGET:-/var/www/html}
APP_USER=${APP_USER:-www-data} APP_USER=${APP_USER:-www-data}
APP_GROUP=${APP_GROUP:-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 if [[ ! -d "$APP_TARGET" ]]; then
# while preserving runtime data that lives under storage/. mkdir -p "$APP_TARGET"
rsync -a --delete \ fi
--exclude storage \
--exclude public/storage \
--exclude bootstrap/cache \
--exclude .env \
"${APP_SOURCE}/" "${APP_TARGET}/"
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" "$APP_TARGET"
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
php artisan config:cache --quiet || true ensure_helper_scripts() {
php artisan route:cache --quiet || true if compgen -G "$APP_TARGET/docs/queue-supervisor/*.sh" > /dev/null; then
php artisan event:cache --quiet || true 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 "$@" exec "$@"