Skip to content

Commit 0375d8b

Browse files
committed
USE docker for running web server and workers
Using symfony docker repo. Configuring the worker was a bit more complex though. See here: dunglas/symfony-docker#539
1 parent c2fe771 commit 0375d8b

25 files changed

+558
-30
lines changed

.dockerignore

+34
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

+58
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

.env

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
###> symfony/framework-bundle ###
1818
APP_ENV=dev
19-
APP_SECRET=38036e5da397502212456a2509bbd5fd
19+
APP_SECRET=c392384cffb81013d0fd7633a78d5277
2020
###< symfony/framework-bundle ###
2121

2222
###> doctrine/doctrine-bundle ###
@@ -29,13 +29,16 @@ APP_SECRET=38036e5da397502212456a2509bbd5fd
2929
DATABASE_URL="postgresql://app:[email protected]:5432/app?serverVersion=16&charset=utf8"
3030
###< doctrine/doctrine-bundle ###
3131

32+
###> symfony/mailer ###
33+
# MAILER_DSN=null://null
34+
###< symfony/mailer ###
35+
3236
###> symfony/messenger ###
3337
# Choose one of the transports below
3438
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
3539
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
3640
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
3741
###< symfony/messenger ###
3842

39-
###> symfony/mailer ###
40-
# MAILER_DSN=null://null
41-
###< symfony/mailer ###
43+
STABILITY=stable
44+
SYMFONY_VERSION=6.4.*

.gitattributes

+17
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

+73
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

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#syntax=docker/dockerfile:1.4
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+
###> recipes ###
40+
###> doctrine/doctrine-bundle ###
41+
RUN install-php-extensions pdo_pgsql
42+
###< doctrine/doctrine-bundle ###
43+
###< recipes ###
44+
45+
COPY --link frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/
46+
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
47+
COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile
48+
49+
ENTRYPOINT ["docker-entrypoint"]
50+
51+
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1
52+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ]
53+
54+
# Dev FrankenPHP image
55+
FROM frankenphp_base AS frankenphp_dev
56+
57+
ENV APP_ENV=dev XDEBUG_MODE=off
58+
59+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
60+
61+
RUN set -eux; \
62+
install-php-extensions \
63+
xdebug \
64+
;
65+
66+
COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
67+
68+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
69+
70+
# Prod FrankenPHP image
71+
FROM frankenphp_base AS frankenphp_prod
72+
73+
ENV APP_ENV=prod
74+
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"
75+
76+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
77+
78+
COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
79+
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile
80+
81+
# prevent the reinstallation of vendors at every changes in the source code
82+
COPY --link composer.* symfony.* ./
83+
RUN set -eux; \
84+
composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress
85+
86+
# copy sources
87+
COPY --link . ./
88+
RUN rm -Rf frankenphp/
89+
90+
RUN set -eux; \
91+
mkdir -p var/cache var/log; \
92+
composer dump-autoload --classmap-authoritative --no-dev; \
93+
composer dump-env prod; \
94+
composer run-script --no-dev post-install-cmd; \
95+
chmod +x bin/console; sync;

assets/bootstrap.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import { startStimulusApp } from '@symfony/stimulus-bridge';
2+
3+
// Registers Stimulus controllers from controllers.json and in the controllers/ directory
4+
export const app = startStimulusApp(require.context(
5+
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
6+
true,
7+
/\.[jt]sx?$/
8+
));
19
import { startStimulusApp } from '@symfony/stimulus-bundle';
210

311
const app = startStimulusApp();

assets/styles/app.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
.card:hover #card-description {
3030
transition: visibility 0.6s 0.8s;
3131
visibility: visible;
32-
}
32+
}

compose.override.yaml

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
1-
version: '3'
2-
1+
# Development environment override
32
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/app.dev.ini:/usr/local/etc/php/conf.d/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+
php-worker:
24+
build:
25+
context: .
26+
target: frankenphp_dev
27+
volumes:
28+
- ./:/app
29+
# If you develop on Mac or Windows you can remove the vendor/ directory
30+
# from the bind-mount for better performance by enabling the next line:
31+
- /app/vendor
32+
33+
###> symfony/mercure-bundle ###
34+
###< symfony/mercure-bundle ###
35+
436
###> doctrine/doctrine-bundle ###
537
database:
638
ports:

compose.prod.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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}
11+
12+
php-worker:
13+
build:
14+
context: .
15+
target: frankenphp_prod
16+
environment:
17+
APP_SECRET: ${APP_SECRET}

0 commit comments

Comments
 (0)