Skip to content

Commit 8de18d0

Browse files
committed
feat: use Symfony docker
1 parent 54b251e commit 8de18d0

23 files changed

+583
-82
lines changed

.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
**/*.log
2+
**/*.md
3+
**/*.php~
4+
**/*.dist.php
5+
**/*.dist
6+
**/*.cache
7+
**/._*
8+
**/.dockerignore
9+
**/.DS_Store
10+
**/.git/
11+
**/.gitattributes
12+
**/.gitignore
13+
**/.gitmodules
14+
**/compose.*.yaml
15+
**/compose.*.yml
16+
**/compose.yaml
17+
**/compose.yml
18+
**/docker-compose.*.yaml
19+
**/docker-compose.*.yml
20+
**/docker-compose.yaml
21+
**/docker-compose.yml
22+
**/Dockerfile
23+
**/Thumbs.db
24+
.github/
25+
docs/
26+
public/bundles/
27+
tests/
28+
var/
29+
vendor/
30+
.editorconfig
31+
.env.*.local
32+
.env.local
33+
.env.local.php
34+
.env.test

.editorconfig

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
# Change these settings to your own preference
9+
indent_style = space
10+
indent_size = 4
11+
12+
# We recommend you to keep these unchanged
13+
end_of_line = lf
14+
charset = utf-8
15+
trim_trailing_whitespace = true
16+
insert_final_newline = true
17+
18+
[*.{js,html,ts,tsx}]
19+
indent_size = 2
20+
21+
[*.json]
22+
indent_size = 2
23+
24+
[*.md]
25+
trim_trailing_whitespace = false
26+
27+
[*.sh]
28+
indent_style = tab
29+
30+
[*.xml{,.dist}]
31+
indent_style = space
32+
indent_size = 4
33+
34+
[*.{yaml,yml}]
35+
trim_trailing_whitespace = false
36+
37+
[.github/workflows/*.yml]
38+
indent_size = 2
39+
40+
[.gitmodules]
41+
indent_style = tab
42+
43+
[.php_cs{,.dist}]
44+
indent_style = space
45+
indent_size = 4
46+
47+
[composer.json]
48+
indent_size = 4
49+
50+
[{,docker-}compose{,.*}.{yaml,yml}]
51+
indent_style = space
52+
indent_size = 2
53+
54+
[{,*.*}Dockerfile]
55+
indent_style = tab
56+
57+
[{,*.*}Caddyfile]
58+
indent_style = tab

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
* text=auto eol=lf
2+
3+
*.conf text eol=lf
4+
*.html text eol=lf
5+
*.ini text eol=lf
6+
*.js text eol=lf
7+
*.json text eol=lf
8+
*.md text eol=lf
9+
*.php text eol=lf
10+
*.sh text eol=lf
11+
*.yaml text eol=lf
12+
*.yml text eol=lf
13+
bin/console text eol=lf
14+
composer.lock text eol=lf merge=ours
15+
16+
*.ico binary
17+
*.png binary

.github/workflows/ci.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: ~
8+
workflow_dispatch: ~
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
tests:
16+
name: Tests
17+
runs-on: ubuntu-latest
18+
steps:
19+
-
20+
name: Checkout
21+
uses: actions/checkout@v4
22+
-
23+
name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
-
26+
name: Build Docker images
27+
uses: docker/bake-action@v4
28+
with:
29+
pull: true
30+
load: true
31+
files: |
32+
compose.yaml
33+
compose.override.yaml
34+
set: |
35+
*.cache-from=type=gha,scope=${{github.ref}}
36+
*.cache-from=type=gha,scope=refs/heads/main
37+
*.cache-to=type=gha,scope=${{github.ref}},mode=max
38+
-
39+
name: Start services
40+
run: docker compose up --wait --no-build
41+
-
42+
name: Check HTTP reachability
43+
run: curl -v --fail-with-body http://localhost
44+
-
45+
name: Check HTTPS reachability
46+
if: false # Remove this line when the homepage will be configured, or change the path to check
47+
run: curl -vk --fail-with-body https://localhost
48+
-
49+
name: Create test database
50+
if: false # Remove this line if Doctrine ORM is installed
51+
run: docker compose exec -T php bin/console -e test doctrine:database:create
52+
-
53+
name: Run migrations
54+
if: false # Remove this line if Doctrine Migrations is installed
55+
run: docker compose exec -T php bin/console -e test doctrine:migrations:migrate --no-interaction
56+
-
57+
name: Run PHPUnit
58+
if: false # Remove this line if PHPUnit is installed
59+
run: docker compose exec -T php bin/phpunit
60+
-
61+
name: Doctrine Schema Validator
62+
if: false # Remove this line if Doctrine ORM is installed
63+
run: docker compose exec -T php bin/console -e test doctrine:schema:validate
64+
lint:
65+
name: Docker Lint
66+
runs-on: ubuntu-latest
67+
steps:
68+
-
69+
name: Checkout
70+
uses: actions/checkout@v4
71+
-
72+
name: Lint Dockerfile
73+
uses: hadolint/[email protected]

Dockerfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#syntax=docker/dockerfile:1
2+
3+
# Versions
4+
FROM dunglas/frankenphp:1-php8.3 AS frankenphp_upstream
5+
6+
# The different stages of this Dockerfile are meant to be built into separate images
7+
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
8+
# https://docs.docker.com/compose/compose-file/#target
9+
10+
11+
# Base FrankenPHP image
12+
FROM frankenphp_upstream AS frankenphp_base
13+
14+
WORKDIR /app
15+
16+
VOLUME /app/var/
17+
18+
# persistent / runtime deps
19+
# hadolint ignore=DL3008
20+
RUN apt-get update && apt-get install -y --no-install-recommends \
21+
acl \
22+
file \
23+
gettext \
24+
git \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
RUN set -eux; \
28+
install-php-extensions \
29+
@composer \
30+
apcu \
31+
intl \
32+
opcache \
33+
zip \
34+
;
35+
36+
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
37+
ENV COMPOSER_ALLOW_SUPERUSER=1
38+
39+
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
40+
41+
###> recipes ###
42+
###< recipes ###
43+
44+
COPY --link frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/
45+
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
46+
COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile
47+
48+
ENTRYPOINT ["docker-entrypoint"]
49+
50+
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1
51+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ]
52+
53+
# Dev FrankenPHP image
54+
FROM frankenphp_base AS frankenphp_dev
55+
56+
ENV APP_ENV=dev XDEBUG_MODE=off
57+
58+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
59+
60+
RUN set -eux; \
61+
install-php-extensions \
62+
xdebug \
63+
;
64+
65+
COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
66+
67+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
68+
69+
# Prod FrankenPHP image
70+
FROM frankenphp_base AS frankenphp_prod
71+
72+
ENV APP_ENV=prod
73+
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"
74+
75+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
76+
77+
COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
78+
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile
79+
80+
# prevent the reinstallation of vendors at every changes in the source code
81+
COPY --link composer.* symfony.* ./
82+
RUN set -eux; \
83+
composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress
84+
85+
# copy sources
86+
COPY --link . ./
87+
RUN rm -Rf frankenphp/
88+
89+
RUN set -eux; \
90+
mkdir -p var/cache var/log; \
91+
composer dump-autoload --classmap-authoritative --no-dev; \
92+
composer dump-env prod; \
93+
composer run-script --no-dev post-install-cmd; \
94+
chmod +x bin/console; sync;

assets/vendor/@hotwired/turbo/turbo.index.js

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/vendor/barecss/css/bare.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/vendor/installed.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111
),
1212
'barecss/css/bare.min.css' =>
1313
array (
14-
'version' => '1.1.1',
14+
'version' => '1.1.0',
15+
'dependencies' =>
16+
array (
17+
),
18+
'extraFiles' =>
19+
array (
20+
),
21+
),
22+
'@hotwired/turbo' =>
23+
array (
24+
'version' => '7.3.0',
1525
'dependencies' =>
1626
array (
1727
),

compose.override.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Development environment override
2+
services:
3+
php:
4+
build:
5+
context: .
6+
target: frankenphp_dev
7+
volumes:
8+
- ./:/app
9+
- ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
10+
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
11+
# If you develop on Mac or Windows you can remove the vendor/ directory
12+
# from the bind-mount for better performance by enabling the next line:
13+
#- /app/vendor
14+
environment:
15+
MERCURE_EXTRA_DIRECTIVES: demo
16+
# See https://xdebug.org/docs/all_settings#mode
17+
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
18+
extra_hosts:
19+
# Ensure that host.docker.internal is correctly defined on Linux
20+
- host.docker.internal:host-gateway
21+
tty: true
22+
23+
###> symfony/mercure-bundle ###
24+
###< symfony/mercure-bundle ###

compose.prod.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Production environment override
2+
services:
3+
php:
4+
build:
5+
context: .
6+
target: frankenphp_prod
7+
environment:
8+
APP_SECRET: ${APP_SECRET}
9+
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
10+
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}

compose.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
php:
3+
image: ${IMAGES_PREFIX:-}app-php
4+
restart: unless-stopped
5+
environment:
6+
SERVER_NAME: ${SERVER_NAME:-localhost}, php:80
7+
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
8+
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
9+
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
10+
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8}
11+
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
12+
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
13+
MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}/.well-known/mercure}
14+
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
15+
# The two next lines can be removed after initial installation
16+
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
17+
STABILITY: ${STABILITY:-stable}
18+
volumes:
19+
- caddy_data:/data
20+
- caddy_config:/config
21+
ports:
22+
# HTTP
23+
- target: 80
24+
published: ${HTTP_PORT:-80}
25+
protocol: tcp
26+
# HTTPS
27+
- target: 443
28+
published: ${HTTPS_PORT:-443}
29+
protocol: tcp
30+
# HTTP/3
31+
- target: 443
32+
published: ${HTTP3_PORT:-443}
33+
protocol: udp
34+
35+
# Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service
36+
###> symfony/mercure-bundle ###
37+
###< symfony/mercure-bundle ###
38+
39+
volumes:
40+
caddy_data:
41+
caddy_config:
42+
###> symfony/mercure-bundle ###
43+
###< symfony/mercure-bundle ###

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
},
101101
"symfony": {
102102
"allow-contrib": false,
103-
"require": "7.1.*"
103+
"require": "7.1.*",
104+
"docker": true
104105
}
105106
},
106107
"scripts": {
@@ -117,7 +118,8 @@
117118
"auto-scripts": {
118119
"cache:clear": "symfony-cmd",
119120
"assets:install %PUBLIC_DIR%": "symfony-cmd",
120-
"requirements-checker": "script"
121+
"requirements-checker": "script",
122+
"importmap:install": "symfony-cmd"
121123
}
122124
},
123125
"scripts-descriptions": {

0 commit comments

Comments
 (0)