Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
docker: install and configure supervisor for consume message, fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauthi committed Jul 2, 2023
1 parent b2a7c13 commit 35be31e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
18 changes: 10 additions & 8 deletions .docker/apachephp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# https://github.com/docker-library/php/blob/f4baf0edbc4e05e241938c68bcc7c9635707583d/7.2/stretch/apache/Dockerfile
FROM php:8.2-apache
MAINTAINER J.GAUTHI <github.com/jgauthi>

# Some libs
RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils
# Some libs + Supervisor
RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils supervisor

# https://github.com/mlocati/docker-php-extension-installer
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
Expand Down Expand Up @@ -32,11 +31,6 @@ RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Purge
RUN rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y g++ \
&& apt-get clean

# PHP Conf
# RUN usermod -u 1000 www-data
COPY php.ini /usr/local/etc/php/php.ini
Expand All @@ -45,6 +39,14 @@ COPY php.ini /usr/local/etc/php/php.ini
COPY apache_default.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite headers

# Purge
RUN rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y g++ \
&& apt-get clean

# USER www-data
WORKDIR /var/www/project/poc-messenger

# Supervisor conf for apache and worker
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord", "-n"]
18 changes: 18 additions & 0 deletions .docker/apachephp/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D

[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"

[program:messenger-consume]
command=php /var/www/project/poc-messenger/bin/console messenger:consume async --time-limit=3600
user=www-data
numprocs=2
startsecs=0
autostart=true
autorestart=true
startretries=10
process_name=%(program_name)s_%(process_num)02d
1 change: 1 addition & 0 deletions .docker/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM mysql:8
MAINTAINER J.GAUTHI <github.com/jgauthi>

ARG DB_USER
ARG DB_PASSWORD
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ clear-cache: perm
@$(CONSOLE) cache:clear --no-warmup
@$(CONSOLE) cache:warnot

c\:c: clear-cache

clear: perm ## Remove all the cache, the logs, the sessions and the built assets
@$(EXEC_SF) rm -rf var/cache/* var/log/* public/build
@$(EXEC_SF) rm -f var/.php_cs.cache
Expand Down Expand Up @@ -78,7 +80,7 @@ sf-cmd: ## Symfony Command, example: `make sf-cmd CMD="debug:container"`
sf-route: ## Api routes
@$(CONSOLE) debug:route

messenger: ## Consume messenger message, you can add verbose mode: CMD="-v"
messenger: ## [Optional] Consume messenger message, you can add verbose mode: CMD="-v". This command is not required, supervisor send message automatically.
@$(CONSOLE) messenger:consume async $(CMD)

shell: ## Run Api container in interactive mode
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# POC Symfony 6.2 with Messenger component + Docker (LAMP, MailDev, RabbitMQ)
# POC Symfony 6.2 with Messenger component + Docker (LAMP with Supervisor, MailDev, RabbitMQ)
Messenger provides a message bus with the ability to send messages and then handle them immediately in your application or send them through transports (e.g. queues) to be handled later. To learn more deeply about it, read the [Messenger component docs](https://symfony.com/doc/6.2/messenger.htmlcomponents/messenger.html).

The messages are automatically consumed (send) by a worker from [supervisor](http://supervisord.org). Without it, you need to launch manually the command `make messenger` (or `php bin/console messenger:consume async` in local symfony server).


## Prerequisites

* Docker & Docker-compose
* `Make` command. On linux, install with `sudo apt install build-essential`. On Windows, [see here](https://stackoverflow.com/questions/32127524/how-to-install-and-use-make-in-windows/54086635).
* These ports must be available for docker: `8000, 8080, 1025, 1080, 15672` _(you can change it on `docker-compose.override.yml` file after install)_.

More information on [symfony website](https://symfony.com/doc/6.2/reference/requirements.html).

Expand All @@ -26,8 +29,8 @@ Use docker for execute the built-in web server and access the application in you
```bash
make up

# Launch Messages service
make messenger
# Launch Messages service (optional: only needed if supervisor is not launch)
# make messenger

# For stop services
make stop
Expand Down

0 comments on commit 35be31e

Please sign in to comment.