Files
3dealer/Dockerfile
T
elviraandClaude Opus 5.5 6d88d53882 Infra: Caddy instead of nginx (plain swap, TLS stays in front)
Caddy 2.11.7 built with xcaddy, with caddy-ratelimit pinned to commit
5625512f (for M3/F7 later; its only tag is years old). Prod bakes
public/ and the config into the image (target caddy); dev uses the
caddy-base stage with docker/caddy and public/ bind-mounted.

It's a 1:1 swap for the host's TLS proxy: plain HTTP on
127.0.0.1:${APP_PORT:-8090}, auto_https off, and
trusted_proxies private_ranges so the proxy's X-Forwarded-* headers
still reach Laravel (checked: https + forwarded host in redirects, as
before). Narrow that range once it's known where TLS ends.

Carried over from nginx:
- php_fastcgi to app:9000, 300s read timeout, try_files to index.php
- /build, /static, /packages and /storage (from the storage volume)
  with Cache-Control "public, max-age=31536000, immutable"
- /sitemap.xml from storage/app, max-age=3600, application/xml
- X-Frame-Options SAMEORIGIN + X-Content-Type-Options nosniff
- 100 MiB upload limit (413 above, as before)
- dotfiles denied except /.well-known/
- /stoic/ proxied to stoic:2727, prefix stripped, cookie paths
  rewritten to /stoic/
- access log to stdout, favicon/robots not logged

Changed on purpose:
- FastCGI page cache dropped (and X-Cache-Status with it). The static
  page cache comes later (P2). It also replayed the first visitor's
  Set-Cookie (session + XSRF) to other guests, since it ignored
  Set-Cookie and keyed on URL only.
- New: zstd/gzip compression for text responses (nginx had none).
- Security headers now on every response; prod nginx dropped them on
  PHP responses and on 4xx/5xx.
- A missing file under the static paths is a plain 404 instead of
  Laravel's page with a 404 status.
- No Via or CGI Status header; one Content-Type on the sitemap (nginx
  sent two).
- Dropped as unneeded: open_file_cache, fastcgi buffers/keepalive,
  `charset utf-8` (Caddy's MIME types carry it where it matters).

Stoic's dev config called the app at http://nginx/validate; it's now
http://caddy/validate. bootstrap/app.php and .env.example comments
updated. docker/nginx/ is removed.

Not in this repo, not changed: boboko-test and the boboko starter
still use nginx.

Deploy note: the service is renamed nginx -> caddy; Envoy's
`up -d --remove-orphans` removes the old nginx container. Expect a few
seconds without a listener on 8090 while it swaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 01:01:13 +02:00

149 lines
6.1 KiB
Docker

# ── Stage 1: Composer deps ───────────────────────────────────────────────────
FROM composer:2 AS composer-build
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install \
--no-dev \
--no-interaction \
--no-scripts \
--prefer-dist \
--optimize-autoloader \
--ignore-platform-reqs
# ── Stage 2a: Vite dev (node_modules only, no build) ──────────────────────────
FROM node:22-alpine AS vite-dev
# git: needed for npm to install @boboko/core's git+https tagged-VCS form (see
# package.json's _dependencies and docker/entrypoint-vite.sh). No build-time
# `npm install` here — package.json's boboko/core path-repo form (../boboko-core)
# isn't visible in the build context, only once bind-mounted at container start,
# and entrypoint-vite.sh already runs npm install on every boot, so this would be
# redundant even if it could work.
RUN apk add --no-cache git
WORKDIR /app
COPY docker/entrypoint-vite.sh /entrypoint-vite.sh
RUN chmod +x /entrypoint-vite.sh
ENTRYPOINT ["/entrypoint-vite.sh"]
# ── Stage 2b: Node / Vite build ──────────────────────────────────────────────
FROM node:22-alpine AS node-build
# git: same reason as vite-dev above — npm needs it to resolve @boboko/core's
# git+https tagged-VCS form.
RUN apk add --no-cache git
WORKDIR /app
COPY package*.json ./
RUN npm ci --ignore-scripts
COPY . .
COPY --from=composer-build /app/vendor ./vendor
RUN npm run build
# ── Stage 3: PHP base (Ubuntu + ondrej/php — pre-compiled, no source builds) ─
FROM ubuntu:24.04 AS php-base
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
RUN apt-get update \
&& apt-get install -y --no-install-recommends software-properties-common ca-certificates gnupg curl \
&& add-apt-repository ppa:ondrej/php \
&& curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| gpg --dearmor -o /usr/share/keyrings/pgdg.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] https://apt.postgresql.org/pub/repos/apt noble-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
php8.5-fpm \
php8.5-cli \
php8.5-pgsql \
php8.5-intl \
php8.5-zip \
php8.5-gd \
php8.5-bcmath \
php8.5-imagick \
php8.5-exif \
php8.5-mbstring \
php8.5-xml \
php8.5-curl \
php8.5-redis \
php8.5-soap \
postgresql-client-18 \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /run/php \
&& sed -i 's|listen = /run/php/php8.5-fpm.sock|listen = 9000|' /etc/php/8.5/fpm/pool.d/www.conf \
&& echo "clear_env = no" >> /etc/php/8.5/fpm/pool.d/www.conf
RUN apt-get update \
&& apt-get install -y --no-install-recommends php8.5-dev php-pear autoconf gcc make \
&& pecl install opentelemetry \
&& echo "extension=opentelemetry.so" > /etc/php/8.5/mods-available/opentelemetry.ini \
&& phpenmod opentelemetry \
&& apt-get purge -y --auto-remove php8.5-dev php-pear autoconf gcc make \
&& rm -rf /var/lib/apt/lists/*
# ── Stage 4: Production ───────────────────────────────────────────────────────
FROM php-base AS production
COPY docker/php/php.ini /etc/php/8.5/fpm/conf.d/99-app.ini
COPY docker/php/php.ini /etc/php/8.5/cli/conf.d/99-app.ini
COPY docker/php/fpm-pool.conf /etc/php/8.5/fpm/pool.d/zz-app.conf
WORKDIR /var/www/html
COPY --from=composer-build /app/vendor ./vendor
COPY --from=node-build /app/public/build ./public/build
COPY . .
RUN chown -R www-data:www-data storage bootstrap/cache \
&& chmod -R 775 storage bootstrap/cache
COPY docker/entrypoint.sh /entrypoint.sh
COPY docker/entrypoint-worker.sh /entrypoint-worker.sh
RUN chmod +x /entrypoint.sh /entrypoint-worker.sh
EXPOSE 9000
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm8.5", "-F"]
# ── Stage 5a: Caddy binary (xcaddy, pinned versions) ─────────────────────────
# caddy-ratelimit isn't used yet: it's for the search subdomain (M3) and the
# PHP-route rate limits (F7). Its only tag (v0.1.0) is years old, so it's
# pinned to a commit.
FROM caddy:2.11.7-builder-alpine AS caddy-build
RUN xcaddy build v2.11.7 \
--with github.com/mholt/caddy-ratelimit@5625512f24f6f59d6f64fb3aafe5eecff0b286db
# Development uses this stage as is, with docker/caddy and public/ bind-mounted
# (docker-compose.dev.yml).
FROM caddy:2.11.7-alpine AS caddy-base
COPY --from=caddy-build /usr/bin/caddy /usr/bin/caddy
# ── Stage 5b: Caddy for production (config + public assets baked in) ─────────
FROM caddy-base AS caddy
COPY docker/caddy/global.caddy docker/caddy/common.caddy docker/caddy/Caddyfile /etc/caddy/
COPY --from=production /var/www/html/public /var/www/html/public
# ── Stage 6: Development ──────────────────────────────────────────────────────
FROM php-base AS development
RUN apt-get update && apt-get install -y --no-install-recommends git unzip curl \
&& rm -rf /var/lib/apt/lists/*
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY docker/php/php.dev.ini /etc/php/8.5/fpm/conf.d/99-app.ini
COPY docker/php/php.dev.ini /etc/php/8.5/cli/conf.d/99-app.ini
WORKDIR /var/www/html
# No build-time `composer install` here: composer.json's boboko/core path repo
# (../boboko-core) isn't visible in the build context, only once bind-mounted at
# container start — entrypoint.sh already runs composer install +
# composer update boboko/* on every boot, so this would be redundant even if it
# could work.
COPY docker/entrypoint.sh /entrypoint.sh
COPY docker/entrypoint-worker.sh /entrypoint-worker.sh
RUN chmod +x /entrypoint.sh /entrypoint-worker.sh
EXPOSE 9000
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm8.5", "-F"]