From 27b1676c47595c5ea06fb5b3020eaaf74e94af26 Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Tue, 5 May 2026 09:32:06 +0200 Subject: [PATCH] build: add docker deployment files --- .dockerignore | 6 ++++++ compose.dev.yaml | 21 +++++++++++++++++++++ compose.yaml | 29 +++++++++++++++++++++++++++++ docker/Dockerfile | 31 +++++++++++++++++++++++++++++++ docker/entrypoint.sh | 11 +++++++++++ docker/nginx/default.conf | 25 +++++++++++++++++++++++++ docker/php/php.ini | 7 +++++++ 7 files changed, 130 insertions(+) create mode 100644 .dockerignore create mode 100644 compose.dev.yaml create mode 100644 compose.yaml create mode 100644 docker/Dockerfile create mode 100755 docker/entrypoint.sh create mode 100644 docker/nginx/default.conf create mode 100644 docker/php/php.ini diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..146630f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +docs/superpowers/plans +var +vendor +.env.local +compose.dev.yaml diff --git a/compose.dev.yaml b/compose.dev.yaml new file mode 100644 index 0000000..f6774cc --- /dev/null +++ b/compose.dev.yaml @@ -0,0 +1,21 @@ +services: + app: + build: + context: . + dockerfile: docker/Dockerfile + target: app + environment: + APP_ENV: dev + APP_DEBUG: "1" + APP_SECRET: dev-secret + DATABASE_URL: sqlite:////app/var/data/app.db + APP_CACHE_DIR: /app/var/bootstrap-cache + volumes: + - .:/app + - app-data:/app/var/data + - app-cache:/app/var/bootstrap-cache + + nginx: + volumes: + - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro + - ./public:/app/public:ro diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..0356ee9 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,29 @@ +services: + app: + build: + context: . + dockerfile: docker/Dockerfile + target: app + environment: + APP_ENV: prod + APP_DEBUG: "0" + APP_SECRET: ${APP_SECRET:-change-me} + DATABASE_URL: sqlite:////app/var/data/app.db + APP_CACHE_DIR: /app/var/bootstrap-cache + volumes: + - app-data:/app/var/data + - app-cache:/app/var/bootstrap-cache + + nginx: + build: + context: . + dockerfile: docker/Dockerfile + target: web + depends_on: + - app + ports: + - "${HTTP_PORT:-8080}:80" + +volumes: + app-data: + app-cache: diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..f4f0931 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,31 @@ +FROM php:8.3-fpm-alpine AS app + +RUN apk add --no-cache bash git icu-dev sqlite-dev unzip \ + && docker-php-ext-install intl opcache pdo pdo_sqlite + +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + +WORKDIR /app + +COPY composer.json composer.lock ./ +RUN composer install --no-dev --prefer-dist --no-interaction --no-progress --no-scripts + +COPY . . +COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini +COPY docker/entrypoint.sh /usr/local/bin/app-entrypoint + +RUN chmod +x /usr/local/bin/app-entrypoint \ + && mkdir -p var/data var/bootstrap-cache \ + && composer dump-autoload --classmap-authoritative --no-dev \ + && composer run-script --no-dev post-install-cmd \ + && chown -R www-data:www-data var + +ENTRYPOINT ["app-entrypoint"] +CMD ["php-fpm"] + +FROM nginx:1.27-alpine AS web + +WORKDIR /app + +COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf +COPY public /app/public diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..a052aa3 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -eu + +mkdir -p /app/var/data /app/var/bootstrap-cache +chown -R www-data:www-data /app/var + +if [ "${APP_ENV:-prod}" != "test" ]; then + php /app/bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration +fi + +exec "$@" diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..06e7c81 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name _; + root /app/public; + index index.php; + + client_max_body_size 2m; + + location / { + try_files $uri /index.php$is_args$args; + } + + location ~ ^/index\.php(/|$) { + fastcgi_pass app:9000; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + internal; + } + + location ~ \.php$ { + return 404; + } +} diff --git a/docker/php/php.ini b/docker/php/php.ini new file mode 100644 index 0000000..a2a61ab --- /dev/null +++ b/docker/php/php.ini @@ -0,0 +1,7 @@ +date.timezone=UTC +memory_limit=256M +upload_max_filesize=2M +post_max_size=2M +opcache.enable=1 +opcache.enable_cli=0 +opcache.validate_timestamps=0