feat: split dev and prod docker-compose files

This commit is contained in:
Kévin Dunglas 2020-10-14 23:03:21 +02:00
parent 07e4f08f31
commit d9554a6f00
No known key found for this signature in database
GPG Key ID: 9D0C5D6EEB42C445
5 changed files with 50 additions and 47 deletions

View File

@ -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}

View File

@ -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).

View File

@ -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"

7
docker-compose.prod.yml Normal file
View File

@ -0,0 +1,7 @@
version: "3.4"
# Production environment override
services:
php:
environment:
APP_ENV: prod

View File

@ -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"