From 298148407a502afd488f2c0568b06df44552bb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20P?= Date: Wed, 1 Nov 2023 08:10:56 +0100 Subject: [PATCH] infra: update Docker config (#29) * rename docker-compose files * update Dockerfile * update frankenphp Caddyfile, docker-entrypoint.sh * update ci.yml * update .dockerignore * update .editorconfig close: #28 --- .dockerignore | 5 +- .editorconfig | 27 ++-------- .github/workflows/ci.yml | 12 ++--- Dockerfile | 32 ++++++------ ...pose.override.yml => compose.override.yaml | 1 + docker-compose.prod.yml => compose.prod.yaml | 0 docker-compose.yml => compose.yaml | 0 docker/frankenphp/Caddyfile | 52 +++++++------------ docker/frankenphp/docker-entrypoint.sh | 2 +- 9 files changed, 53 insertions(+), 78 deletions(-) rename docker-compose.override.yml => compose.override.yaml (99%) rename docker-compose.prod.yml => compose.prod.yaml (100%) rename docker-compose.yml => compose.yaml (100%) diff --git a/.dockerignore b/.dockerignore index 3225cf9..91fccfa 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,7 +10,10 @@ **/.git/ **/.gitattributes **/.gitignore -**/.gitmodules +***/compose.*.yaml +**/compose.*.yml +**/compose.yaml +**/compose.yml*/.gitmodules **/docker-compose.*.yaml **/docker-compose.*.yml **/docker-compose.yaml diff --git a/.editorconfig b/.editorconfig index 29f08ed..c721fc6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,63 +12,46 @@ trim_trailing_whitespace = true insert_final_newline = true [*.{js,html,ts,tsx}] -indent_style = space indent_size = 2 [*.json] -indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false -[*.php] -indent_style = space -indent_size = 4 - [*.sh] indent_style = tab -indent_size = 4 [*.xml{,.dist}] indent_style = space indent_size = 4 [*.{yaml,yml}] -indent_style = space -indent_size = 4 trim_trailing_whitespace = false [.github/workflows/*.yml] -indent_style = space indent_size = 2 [.gitmodules] indent_style = tab -indent_size = 4 [.php_cs{,.dist}] indent_style = space indent_size = 4 -[.travis.yml] -indent_style = space -indent_size = 2 - [composer.json] -indent_style = space indent_size = 4 -[docker-compose{,.*}.{yaml,yml}] +[{,docker-}compose{,.*}.{yaml,yml}] indent_style = space indent_size = 2 -[Dockerfile] +[{,*.*}Dockerfile] indent_style = tab -indent_size = 4 -[Makefile] +[{,*.*}Caddyfile] indent_style = tab -indent_size = 4 -tab_width = 4 +[Makefile] +indent_style = tab diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34cac1c..b9590ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Lint Dockerfile uses: hadolint/hadolint-action@v3.1.0 tests: @@ -28,18 +28,18 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Build Docker images - uses: docker/bake-action@v3 + uses: docker/bake-action@v4 with: load: true files: | - docker-compose.yml - docker-compose.override.yml + compose.yaml + compose.override.yaml set: | *.cache-from=type=gha,scope=${{github.ref}} *.cache-from=type=gha,scope=refs/heads/main diff --git a/Dockerfile b/Dockerfile index f1133d7..abae0f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,22 +16,22 @@ WORKDIR /app # persistent / runtime deps # hadolint ignore=DL3018 RUN apk add --no-cache \ - acl \ - fcgi \ - file \ - gettext \ - git \ - postgresql-dev \ + acl \ + file \ + gettext \ + git \ + postgresql-dev \ ; RUN set -eux; \ - install-php-extensions \ - apcu \ - intl \ - opcache \ - zip \ - pdo_pgsql \ - ; + install-php-extensions \ + apcu \ + intl \ + opcache \ + opcache \ + zip \ + pdo_pgsql \ + ; COPY --link docker/frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/ COPY --link --chmod=755 docker/frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint @@ -45,7 +45,7 @@ ENV PATH="${PATH}:/root/.composer/vendor/bin" COPY --from=composer_upstream --link /composer /usr/bin/composer -HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:2019/metrics || exit 1 +HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1 CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ] # Dev FrankenPHP image @@ -58,8 +58,8 @@ RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" RUN set -eux; \ install-php-extensions \ - xdebug \ - ; + xdebug \ + ; COPY --link docker/frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/ diff --git a/docker-compose.override.yml b/compose.override.yaml similarity index 99% rename from docker-compose.override.yml rename to compose.override.yaml index da74f96..555f5ba 100644 --- a/docker-compose.override.yml +++ b/compose.override.yaml @@ -20,6 +20,7 @@ services: extra_hosts: # Ensure that host.docker.internal is correctly defined on Linux - host.docker.internal:host-gateway + tty: true database: image: postgres:${POSTGRES_VERSION:-15}-alpine diff --git a/docker-compose.prod.yml b/compose.prod.yaml similarity index 100% rename from docker-compose.prod.yml rename to compose.prod.yaml diff --git a/docker-compose.yml b/compose.yaml similarity index 100% rename from docker-compose.yml rename to compose.yaml diff --git a/docker/frankenphp/Caddyfile b/docker/frankenphp/Caddyfile index 5f48385..0a95f3b 100644 --- a/docker/frankenphp/Caddyfile +++ b/docker/frankenphp/Caddyfile @@ -4,26 +4,31 @@ frankenphp { {$FRANKENPHP_CONFIG} } -} -{$SERVER_NAME:localhost} + # https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm + order mercure after encode + order vulcain after reverse_proxy + order php_server before file_server +} {$CADDY_EXTRA_CONFIG} -log { - # Redact the authorization query parameter that can be set by Mercure - format filter { - wrap console - fields { - uri query { - replace authorization REDACTED +{$SERVER_NAME:localhost} { + log { + # Redact the authorization query parameter that can be set by Mercure + format filter { + wrap console + fields { + uri query { + replace authorization REDACTED + } } } } -} -route { root * /app/public + encode zstd gzip + mercure { # Transport to use (default to Bolt) transport_url {$MERCURE_TRANSPORT_URL:bolt:///data/mercure.db} @@ -38,28 +43,11 @@ route { # Extra directives {$MERCURE_EXTRA_DIRECTIVES} } - vulcain - - # Add trailing slash for directory requests - @canonicalPath { - file {path}/index.php - not path */ - } - redir @canonicalPath {path}/ 308 - - # If the requested file does not exist, try index files - @indexFiles file { - try_files {path} {path}/index.php index.php - split_path .php - } - rewrite @indexFiles {http.matchers.file.relative} - # FrankenPHP! - @phpFiles path *.php - php @phpFiles + vulcain - encode zstd gzip - file_server + # Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics + header ?Permissions-Policy "browsing-topics=()" - respond 404 + php_server } diff --git a/docker/frankenphp/docker-entrypoint.sh b/docker/frankenphp/docker-entrypoint.sh index bb4a3ca..2dbcab5 100755 --- a/docker/frankenphp/docker-entrypoint.sh +++ b/docker/frankenphp/docker-entrypoint.sh @@ -2,7 +2,7 @@ set -e if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then - if [ ! -d 'vendor/' ]; then + if [ -z "$(ls -A 'vendor/' 2>/dev/null)" ]; then composer install --prefer-dist --no-progress --no-interaction fi