From 817470a67b704b6be4712cbd0c185ec60fd186b8 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:45:59 +0100 Subject: [PATCH 01/12] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c7650297..f8670440c 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,9 @@ with [FrankenPHP](https://frankenphp.dev) and [Caddy](https://caddyserver.com/) 7. [Using MySQL instead of PostgreSQL](docs/mysql.md) 8. [Using Alpine Linux instead of Debian](docs/alpine.md) 9. [Using a Makefile](docs/makefile.md) -10. [Updating the template](docs/updating.md) -11. [Troubleshooting](docs/troubleshooting.md) +10. [Using async Symfony Messenger](docs/symfony-messenger.md) +11. [Updating the template](docs/updating.md) +12. [Troubleshooting](docs/troubleshooting.md) ## License From e50c12890d2bf7d8c98998548b6687bf3445e2b0 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:57:42 +0100 Subject: [PATCH 02/12] Create symfony-messenger.md --- docs/symfony-messenger.md | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docs/symfony-messenger.md diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md new file mode 100644 index 000000000..033e502e9 --- /dev/null +++ b/docs/symfony-messenger.md @@ -0,0 +1,62 @@ +# Using async Symfony Messenger + +Add new service to the `compose.yaml`: +```yaml + php-worker: + image: ${IMAGES_PREFIX:-}app-php-worker + restart: unless-stopped + environment: + - RUN_MIGRATIONS=false + healthcheck: + disable: true + depends_on: + - php +``` + +Add new services to the `compose.override.yaml`: +```yaml + php-worker: + profiles: + - donotstart + + php-worker-async: + scale: 2 + extends: + file: compose.yaml + service: php-worker + image: ${IMAGES_PREFIX:-}app-php-worker-async + build: + context: . + target: frankenphp_dev + command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] + volumes: + - ./:/app + - /app/var/ + depends_on: + php: + condition: service_healthy +``` + +Two instances of `php-worker-async` will start after `php` container which does installation of Symfony. They will share app folder because of `- ./:/app` in volumes configuration. `- /app/var/` defines that every container will have its own and separate `/app/var/` folder, [note missing `:`](https://stackoverflow.com/questions/46166304/docker-compose-volumes-without-colon). + +To add additional workers just copy `php-worker-async` service and replace every usage of the `async` in the new service with appropriate value for the new worker. + +Add new service to the `compose.prod.yaml`: +```yaml + php-worker: + build: + context: . + target: frankenphp_prod + environment: + APP_SECRET: ${APP_SECRET} +``` + +Apply the following changes to the `frankenphp/docker-entrypoint.sh`: +```patch +- if grep -q ^DATABASE_URL= .env; then ++ run_migrations=${RUN_MIGRATIONS:-true} ++ if grep -q ^DATABASE_URL= .env && [ "$run_migrations" = "true" ]; then +``` + +> [!NOTE] +> After all changes are made the containers need to be rebuilt. From abf96f4678fd0a171739c5ff0d9fd4ce28ea1651 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:22:30 +0100 Subject: [PATCH 03/12] Apply suggestions from code review Co-authored-by: Stanislau Kviatkouski <7-zete-7@users.noreply.github.com> --- docs/symfony-messenger.md | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 033e502e9..259054856 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -3,15 +3,14 @@ Add new service to the `compose.yaml`: ```yaml php-worker: - image: ${IMAGES_PREFIX:-}app-php-worker - restart: unless-stopped - environment: - - RUN_MIGRATIONS=false - healthcheck: - disable: true - depends_on: - - php -``` + image: ${IMAGES_PREFIX:-}app-php-worker + restart: unless-stopped + environment: + - RUN_MIGRATIONS=false + healthcheck: + disable: true + depends_on: + - php Add new services to the `compose.override.yaml`: ```yaml @@ -44,18 +43,16 @@ To add additional workers just copy `php-worker-async` service and replace every Add new service to the `compose.prod.yaml`: ```yaml php-worker: - build: - context: . - target: frankenphp_prod - environment: - APP_SECRET: ${APP_SECRET} -``` + build: + context: . + target: frankenphp_prod + environment: + APP_SECRET: ${APP_SECRET} Apply the following changes to the `frankenphp/docker-entrypoint.sh`: ```patch - if grep -q ^DATABASE_URL= .env; then -+ run_migrations=${RUN_MIGRATIONS:-true} -+ if grep -q ^DATABASE_URL= .env && [ "$run_migrations" = "true" ]; then ++ if grep -q ^DATABASE_URL= .env && [ "${RUN_MIGRATIONS:-true}" = "true" ]; then ``` > [!NOTE] From 0d82aba9a613a614d3c2bcaf3649071187bd58aa Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:32:36 +0100 Subject: [PATCH 04/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 259054856..397fb3387 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -11,6 +11,7 @@ Add new service to the `compose.yaml`: disable: true depends_on: - php +``` Add new services to the `compose.override.yaml`: ```yaml @@ -48,6 +49,7 @@ Add new service to the `compose.prod.yaml`: target: frankenphp_prod environment: APP_SECRET: ${APP_SECRET} +``` Apply the following changes to the `frankenphp/docker-entrypoint.sh`: ```patch From 2639b9c1d60177bf7728fc41c943315333b8faaf Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:53:08 +0100 Subject: [PATCH 05/12] Update symfony-messenger.md Improved `compose.prod.yaml` --- docs/symfony-messenger.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 397fb3387..2d6b7fa8d 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -44,11 +44,22 @@ To add additional workers just copy `php-worker-async` service and replace every Add new service to the `compose.prod.yaml`: ```yaml php-worker: + profiles: + - donotstart + + php-worker-async: + scale: 2 + extends: + file: compose.yaml + service: php-worker + image: ${IMAGES_PREFIX:-}app-php-worker-async build: context: . - target: frankenphp_prod - environment: - APP_SECRET: ${APP_SECRET} + target: frankenphp_dev + command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] + depends_on: + php: + condition: service_healthy ``` Apply the following changes to the `frankenphp/docker-entrypoint.sh`: From aa80aa22f69220c4680dce5ee04a8bd32f5c6900 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:54:35 +0100 Subject: [PATCH 06/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 2d6b7fa8d..3010a353e 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -41,7 +41,7 @@ Two instances of `php-worker-async` will start after `php` container which does To add additional workers just copy `php-worker-async` service and replace every usage of the `async` in the new service with appropriate value for the new worker. -Add new service to the `compose.prod.yaml`: +Add new services to the `compose.prod.yaml`: ```yaml php-worker: profiles: From a1bfdf2f2b1facc39c846d1219724f53e1e3a430 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 12:10:32 +0100 Subject: [PATCH 07/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 3010a353e..1c69efd39 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -55,7 +55,7 @@ Add new services to the `compose.prod.yaml`: image: ${IMAGES_PREFIX:-}app-php-worker-async build: context: . - target: frankenphp_dev + target: frankenphp_prod command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] depends_on: php: From 0fb2915ea300f2b4e7a994fdb593bbe3e8e35a30 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 12:13:51 +0100 Subject: [PATCH 08/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 1c69efd39..345ad83f7 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -52,7 +52,7 @@ Add new services to the `compose.prod.yaml`: extends: file: compose.yaml service: php-worker - image: ${IMAGES_PREFIX:-}app-php-worker-async + image: php-worker-async build: context: . target: frankenphp_prod From 71a4536d0f03246a64402fab277044cd6f86f208 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 12:15:01 +0100 Subject: [PATCH 09/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 345ad83f7..367849fb3 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -52,7 +52,6 @@ Add new services to the `compose.prod.yaml`: extends: file: compose.yaml service: php-worker - image: php-worker-async build: context: . target: frankenphp_prod From f058913d216cf280b853f1551faba5784cc01d1a Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Sun, 3 Nov 2024 12:23:43 +0100 Subject: [PATCH 10/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 367849fb3..1c69efd39 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -52,6 +52,7 @@ Add new services to the `compose.prod.yaml`: extends: file: compose.yaml service: php-worker + image: ${IMAGES_PREFIX:-}app-php-worker-async build: context: . target: frankenphp_prod From eeb912d32aaa0250221e2862fca18ce74e3c4332 Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:06:40 +0100 Subject: [PATCH 11/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 1c69efd39..51af7383c 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -28,7 +28,7 @@ Add new services to the `compose.override.yaml`: build: context: . target: frankenphp_dev - command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] + command: ['bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] volumes: - ./:/app - /app/var/ @@ -56,7 +56,7 @@ Add new services to the `compose.prod.yaml`: build: context: . target: frankenphp_prod - command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] + command: ['bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M'] depends_on: php: condition: service_healthy From 1678c4cb59af7e702c208983b91833b68524eecf Mon Sep 17 00:00:00 2001 From: k-37 <60838818+k-37@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:38:27 +0100 Subject: [PATCH 12/12] Update symfony-messenger.md --- docs/symfony-messenger.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/symfony-messenger.md b/docs/symfony-messenger.md index 51af7383c..839ba3366 100644 --- a/docs/symfony-messenger.md +++ b/docs/symfony-messenger.md @@ -37,10 +37,12 @@ Add new services to the `compose.override.yaml`: condition: service_healthy ``` -Two instances of `php-worker-async` will start after `php` container which does installation of Symfony. They will share app folder because of `- ./:/app` in volumes configuration. `- /app/var/` defines that every container will have its own and separate `/app/var/` folder, [note missing `:`](https://stackoverflow.com/questions/46166304/docker-compose-volumes-without-colon). +Two instances, which are defined by `scale` property, of `php-worker-async` will start after `php` container which does installation of Symfony and runs database migrations. They will share app folder because of `- ./:/app` in volumes configuration. `- /app/var/` defines that every container will have its own and separate `/app/var/` folder, [note missing `:`](https://stackoverflow.com/questions/46166304/docker-compose-volumes-without-colon). To add additional workers just copy `php-worker-async` service and replace every usage of the `async` in the new service with appropriate value for the new worker. +In `compose.yaml` we have base `php-worker` service which is extended by `php-worker-async` in `compose.override.yaml` and in `compose.prod.yaml` with `extends` property. [`donotstart` service profile](https://docs.docker.com/compose/how-tos/profiles/) on `php-worker` service is used to prevent it from starting, because it is only used as a base for eventual multiple workers with different configuration. + Add new services to the `compose.prod.yaml`: ```yaml php-worker: