From 5110ded7e5897a033e45a8ffc9e6383cb2bff2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Sun, 5 Jan 2025 21:09:27 +0100 Subject: [PATCH] feat: support running using Docker Compose This commit adds a Docker Compose file which will run the application using docker. The application is fronted by Traefik, and runs using PHP-fpm. nginx is used to accept queries from Traefik and relay them to the PHP-fpm containers (Traefik doesn't support FastCGI directly). Sessions are shared between the various PHP containers using memcached. Part of this work is based on [this repo](https://github.com/wandersonwhcr/docker-nginx-php-fpm) --- .gitignore | 1 + docker/Dockerfile | 37 ++++++++ docker/app-config.inc.php | 15 ++++ docker/compose.yml | 93 ++++++++++++++++++++ docker/db-config.sql | 6 ++ docker/env.example | 23 +++++ docker/init-sql.sh | 5 ++ docker/nginx-templates/default.conf.template | 21 +++++ 8 files changed, 201 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/app-config.inc.php create mode 100644 docker/compose.yml create mode 100644 docker/db-config.sql create mode 100644 docker/env.example create mode 100644 docker/init-sql.sh create mode 100644 docker/nginx-templates/default.conf.template diff --git a/.gitignore b/.gitignore index 355afad..e1f8611 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ includes/config.inc.php database/config.sql site/.htaccess +docker/.env diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..4e7b01a --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,37 @@ +# syntax=docker/dockerfile:1.7-labs +ARG PHP_VERSION=8.3 +ARG POSTGRESQL_VERSION=17 + +# +# Application image +# + +FROM php:${PHP_VERSION}-fpm-alpine AS application + +RUN <> /usr/local/etc/php-fpm.d/zz-docker.conf + echo "chdir = /var/www/tasks/site" >> /usr/local/etc/php-fpm.d/zz-docker.conf + curl --silent --remote-name https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/v0.5.0/php-fpm-healthcheck + install --owner root --group root --mode 755 php-fpm-healthcheck /usr/local/bin/php-fpm-healthcheck + rm -rf php-fpm-healthcheck + mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" +EOF +HEALTHCHECK --interval=5s \ + CMD php-fpm-healthcheck || exit 1 + +COPY --parents site includes arse /var/www/tasks/ + +# +# Database image +# + +FROM postgres:${POSTGRESQL_VERSION} AS database +RUN mkdir /opt/tasks +COPY --parents database.sql database /opt/tasks/ diff --git a/docker/app-config.inc.php b/docker/app-config.inc.php new file mode 100644 index 0000000..2caa95e --- /dev/null +++ b/docker/app-config.inc.php @@ -0,0 +1,15 @@ +