From d9554a6f008200c47c9aa546ddd96c01a261f543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= <dunglas@gmail.com> Date: Wed, 14 Oct 2020 23:03:21 +0200 Subject: [PATCH] feat: split dev and prod docker-compose files --- Dockerfile | 3 --- README.md | 34 +++++++++++++--------------------- docker-compose.override.yml | 29 +++++++++++++++++++++++++++++ docker-compose.prod.yml | 7 +++++++ docker-compose.yml | 24 +----------------------- 5 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.prod.yml diff --git a/Dockerfile b/Dockerfile index 4d5f4be..da24d32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,9 +74,6 @@ ENV PATH="${PATH}:/root/.composer/vendor/bin" WORKDIR /srv/app -# build for production -ARG APP_ENV=prod - # Allow to use development versions of Symfony ARG STABILITY="stable" ENV STABILITY ${STABILITY:-stable} diff --git a/README.md b/README.md index 0fb1006..a1a13c4 100644 --- a/README.md +++ b/README.md @@ -14,24 +14,22 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony Use the `SYMFONY_VERSION` environment variable to select a specific Symfony version. -For instance, use the following command to install Symfony 3.4: +For instance, use the following command to install Symfony 4.4: -`SYMFONY_VERSION=3.4.* docker-compose up --build` + $ SYMFONY_VERSION=4.4.* docker-compose up --build To install a non-stable version of Symfony, use the `STABILITY` environment variable during the build. The value must be [a valid Composer stability option](https://getcomposer.org/doc/04-schema.md#minimum-stability)) . For instance, use the following command to use the `master` branch of Symfony: -```bash -STABILITY=dev docker-compose up --build -``` + $ STABILITY=dev docker-compose up --build ## Customize Server Name Use the `SERVER_NAME` environment variable to define your custom server name. -`SERVER_NAME=symfony.wip docker-compose up --build` + $ SERVER_NAME=symfony.wip docker-compose up --build ## Debugging @@ -47,7 +45,7 @@ it's recommended to add a custom stage to the end of the `Dockerfile`. # Dockerfile FROM symfony_php as symfony_php_dev -ARG XDEBUG_VERSION=2.8.0 +ARG XDEBUG_VERSION=2.9.8 RUN set -eux; \ apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \ pecl install xdebug-$XDEBUG_VERSION; \ @@ -57,12 +55,13 @@ RUN set -eux; \ ### Configure Xdebug with Docker Compose Override -Using an [override](https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files) file named `docker-compose.override.yaml` ensures that the production +Using an [override](https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files) file named `docker-compose.debug.yaml` ensures that the production configuration remains untouched. As example, an override could look like this: ```yaml +# docker-compose.debug.yaml version: "3.4" services: @@ -86,22 +85,16 @@ services: Then run: -```bash -docker-compose up -d -``` - -If `docker-compose.yml` and a `docker-compose.override.yml` are present on the same directory level, Docker Compose combines the two files into a single configuration, applying the configuration in the `docker-compose.override.yml` file over and in addition to the values in the `docker-compose.yml` file. + $ docker-compose -f docker-compose.yml -f docker-compose.debug.yml up -d ### Troubleshooting Inspect the installation with the following command. The requested Xdebug version should be displayed in the output. -```bash -$ docker-compose exec php php --version - -PHP ... - with Xdebug v2.8.0 ... -``` + $ docker-compose exec php php --version + + PHP ... + with Xdebug v2.8.0 ... ### Editing Permissions on Linux @@ -111,9 +104,8 @@ If you work on linux and cannot edit some of the project files right after the f If you have a SSL trust issues, download the self-signed certificate and run : -`sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /path/to/you/certificate.cer` + $ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /path/to/you/certificate.cer ## Credits Created by [Kévin Dunglas](https://dunglas.fr), co-maintained by [Maxime Helias](https://twitter.com/maxhelias) and sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop). - diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..9041173 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,29 @@ +version: "3.4" + +# Development environment override +services: + php: + volumes: + - ./:/srv/app:rw,cached + - ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini + # If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host + # - ./api/var:/srv/app/var:rw + environment: + APP_ENV: dev + + nginx: + volumes: + - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro + - ./public:/srv/app/public:ro + + # This HTTP/2 proxy is not secure: it should only be used in dev + h2-proxy: + build: + context: . + target: symfony_h2-proxy + depends_on: + - nginx + volumes: + - ./docker/h2-proxy/default.conf:/etc/nginx/conf.d/default.conf:ro + ports: + - "443:443" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..6544bc6 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,7 @@ +version: "3.4" + +# Production environment override +services: + php: + environment: + APP_ENV: prod diff --git a/docker-compose.yml b/docker-compose.yml index 182aa68..7536bb3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,14 +14,8 @@ services: timeout: 3s retries: 3 start_period: 30s - volumes: - # Comment out the next line in production - - ./:/srv/app:rw,cached - - ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini - # If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host - # - ./api/var:/srv/app/var:rw environment: - - SYMFONY_VERSION + SYMFONY_VERSION: nginx: build: @@ -29,21 +23,5 @@ services: target: symfony_nginx depends_on: - php - volumes: - # Comment out the next line in production - - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro - - ./public:/srv/app/public:ro ports: - "80:80" - - # This HTTP/2 proxy is not secure: it should only be used in dev - h2-proxy: - build: - context: . - target: symfony_h2-proxy - depends_on: - - nginx - volumes: - - ./docker/h2-proxy/default.conf:/etc/nginx/conf.d/default.conf:ro - ports: - - "443:443"