Skip to content

Commit df6286b

Browse files
committed
Upgrade the Docker setup and dependencies
1 parent 10b49ac commit df6286b

16 files changed

+147
-68
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.sh text eol=lf
3+
docker/apache/start_safe_perms text eol=lf

Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM php:7.1-fpm-alpine
33
RUN apk add --no-cache --virtual .persistent-deps \
44
git \
55
icu-libs \
6-
make \
76
zlib
87

98
ENV APCU_VERSION 5.1.8
@@ -23,10 +22,9 @@ RUN set -xe \
2322
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
2423
&& apk del .build-deps
2524

26-
COPY docker/php/php.ini /usr/local/etc/php/php.ini
27-
28-
COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer
25+
COPY docker/app/php.ini /usr/local/etc/php/php.ini
2926

27+
COPY docker/app/install-composer.sh /usr/local/bin/docker-app-install-composer
3028
RUN chmod +x /usr/local/bin/docker-app-install-composer
3129

3230
RUN set -xe \
@@ -42,7 +40,7 @@ ENV COMPOSER_ALLOW_SUPERUSER 1
4240
RUN composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --optimize-autoloader --classmap-authoritative \
4341
&& composer clear-cache
4442

45-
WORKDIR /srv/api-platform
43+
WORKDIR /srv/app
4644

4745
COPY composer.json ./
4846
COPY composer.lock ./
@@ -63,8 +61,8 @@ COPY web web/
6361

6462
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
6563

66-
COPY docker/php/start.sh /usr/local/bin/docker-app-start
67-
68-
RUN chmod +x /usr/local/bin/docker-app-start
64+
COPY docker/app/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint
65+
RUN chmod +x /usr/local/bin/docker-app-entrypoint
6966

70-
CMD ["docker-app-start"]
67+
ENTRYPOINT ["docker-app-entrypoint"]
68+
CMD ["php-fpm"]

composer.json

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
"type": "project",
44
"license": "proprietary",
55
"description": "Project description",
6-
"minimum-stability": "dev",
76
"require": {
8-
"php": "^7.1",
9-
"symfony/flex": "1.0.x-dev",
10-
"symfony/framework-bundle": "3.3.x-dev",
11-
"symfony/yaml": "3.3.x-dev"
7+
"php": "^7.1.3",
8+
"symfony/flex": "^1.0",
9+
"symfony/framework-bundle": "^3.3",
10+
"symfony/yaml": "^3.3"
1211
},
1312
"config": {
14-
"platform": {
15-
"php": "7.1"
16-
},
1713
"preferred-install": {
1814
"*": "dist"
1915
},
@@ -39,11 +35,8 @@
3935
"@auto-scripts"
4036
]
4137
},
42-
"repositories": [
43-
{ "type": "vcs", "url": "https://github.com/fabpot/flex" }
44-
],
4538
"conflict": {
46-
"symfony/symfony": "<3.3",
39+
"symfony/symfony": "*",
4740
"symfony/twig-bundle": "<3.3",
4841
"symfony/debug": "<3.3"
4942
},

docker-compose.yml

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
11
version: '3'
22

33
services:
4-
#db:
5-
# image: mysql:5.7
6-
# environment:
7-
# MYSQL_DATABASE: symfony
8-
# MYSQL_USER: symfony
9-
# MYSQL_PASSWORD: symfony
10-
# MYSQL_RANDOM_ROOT_PASSWORD: 'true'
11-
# volumes:
12-
# - db-data:/var/lib/mysql
13-
# healthcheck:
14-
# test: mysql --user=api_platform --password=api_platform -e "SELECT 1" api_platform
15-
16-
php:
17-
build: .
4+
app:
5+
build:
6+
context: .
7+
dockerfile: ./Dockerfile
188
#depends_on:
199
# - db
10+
environment:
11+
# Change to prod in production
12+
- SYMFONY_ENV=dev
2013
volumes:
21-
- ./:/srv/api-platform
22-
env_file:
23-
- .env
14+
# Comment out the next line in production
15+
- ./:/srv/app:rw
16+
# This is for assets:install
17+
- ./web:/srv/app/web:rw
18+
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
19+
- /srv/app/var
20+
- /srv/app/var/cache
21+
- /srv/app/var/logs
22+
- /srv/app/var/sessions
23+
- /srv/app/vendor
2424

2525
nginx:
26-
image: nginx:1.11-alpine
27-
depends_on:
28-
- php
29-
ports:
30-
- '80:80'
26+
build:
27+
context: ./docker/nginx
28+
dockerfile: ./Dockerfile
3129
volumes:
30+
# Comment out the next line in production
3231
- ./docker/nginx/conf.d:/etc/nginx/conf.d:ro
33-
- ./:/srv/api-platform
32+
- ./web:/srv/app/web:ro
33+
ports:
34+
- "80:80"
35+
36+
# Uncomment the following lines to add a MySQL container
37+
#db:
38+
# build:
39+
# context: ./docker/db
40+
# dockerfile: ./Dockerfile
41+
# environment:
42+
# - MYSQL_DATABASE=app
43+
# # You should definitely change the password in production
44+
# - MYSQL_PASSWORD=symfony
45+
# - MYSQL_RANDOM_ROOT_PASSWORD=true
46+
# - MYSQL_USER=symfony
47+
# volumes:
48+
# - db-data:/var/lib/mysql:rw
49+
# # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
50+
# # - ./docker/db/data:/var/lib/mysql:rw
3451

35-
#volumes:
36-
# db-data:
52+
volumes:
53+
app-web: {}
54+
#db-data: {}

docker/app/docker-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# first arg is `-f` or `--some-option`
5+
if [ "${1#-}" != "$1" ]; then
6+
set -- php-fpm "$@"
7+
fi
8+
9+
if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
10+
# Detect the host IP
11+
export DOCKER_BRIDGE_IP
12+
DOCKER_BRIDGE_IP=$(ip ro | grep default | cut -d' ' -f 3)
13+
14+
if [ "$SYMFONY_ENV" = 'prod' ]; then
15+
composer install --prefer-dist --no-dev --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --no-interaction
16+
else
17+
composer install --prefer-dist --no-progress --no-suggest --no-interaction
18+
fi
19+
20+
# Permissions hack because setfacl does not work on Mac and Windows
21+
chown -R www-data var
22+
fi
23+
24+
exec docker-php-entrypoint "$@"

docker/php/install-composer.sh renamed to docker/app/install-composer.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22

3+
# Copyright (c) Nils Adermann, Jordi Boggiano
4+
# Origin: https://github.com/composer/composer/blob/master/doc/faqs/how-to-install-composer-programmatically.md
5+
# Licence: MIT
6+
37
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
48
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
59
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
File renamed without changes.

docker/db/.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
**/*.log
2+
**/*.md
3+
**/*.sql.gz
4+
**/._*
5+
**/.DS_Store
6+
**/.gitignore
7+
**/Thumbs.db
8+
.dockerignore
9+
data/
10+
Dockerfile

docker/db/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data/

docker/db/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM mysql:5.7
2+
3+
COPY docker-healthcheck.sh /usr/local/bin/docker-healthcheck
4+
RUN chmod +x /usr/local/bin/docker-healthcheck
5+
6+
HEALTHCHECK CMD ["docker-healthcheck"]

docker/db/docker-healthcheck.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2014-2016 Docker, Inc.
4+
# Origin: https://github.com/docker-library/healthcheck/blob/master/mysql/docker-healthcheck
5+
# Licence: MIT
6+
7+
set -eo pipefail
8+
9+
if [ "$MYSQL_RANDOM_ROOT_PASSWORD" ] && [ -z "$MYSQL_USER" ] && [ -z "$MYSQL_PASSWORD" ]; then
10+
# there's no way we can guess what the random MySQL password was
11+
echo >&2 'healthcheck error: cannot determine random root password (and MYSQL_USER and MYSQL_PASSWORD were not set)'
12+
exit 0
13+
fi
14+
15+
host="$(hostname --ip-address || echo '127.0.0.1')"
16+
user="${MYSQL_USER:-root}"
17+
export MYSQL_PWD="${MYSQL_PASSWORD:-$MYSQL_ROOT_PASSWORD}"
18+
19+
args=(
20+
# force mysql to not use the local "mysqld.sock" (test "external" connectibility)
21+
-h"$host"
22+
-u"$user"
23+
--silent
24+
)
25+
26+
if select="$(echo 'SELECT 1' | mysql "${args[@]}")" && [ "$select" = '1' ]; then
27+
exit 0
28+
fi
29+
30+
exit 1

docker/nginx/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
**/*.log
2+
**/*.md
3+
**/._*
4+
**/.DS_Store
5+
**/.gitignore
6+
**/Thumbs.db
7+
.dockerignore
8+
Dockerfile

docker/nginx/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx:1.11-alpine
2+
3+
COPY conf.d /etc/nginx/conf.d/

docker/nginx/conf.d/default.conf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
server {
2-
root /srv/api-platform/web;
2+
root /srv/app/web;
3+
resolver 127.0.0.11;
34

45
location / {
56
# try to serve file directly, fallback to app.php
67
try_files $uri /index.php$is_args$args;
78
}
89
location ~ ^/index\.php(/|$) {
9-
fastcgi_pass php:9000;
10+
fastcgi_pass app:9000;
1011
fastcgi_split_path_info ^(.+\.php)(/.*)$;
1112
include fastcgi_params;
1213
# When you are using symlinks to link the document root to the
@@ -29,7 +30,4 @@ server {
2930
location ~ \.php$ {
3031
return 404;
3132
}
32-
33-
error_log /var/log/nginx/app_error.log;
34-
access_log /var/log/nginx/app_access.log;
3533
}

docker/php/start.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

web/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use App\Kernel;
4-
use Symfony\Component\Dotenv\Dotenv;
54
use Symfony\Component\HttpFoundation\Request;
65
use Symfony\Component\Debug\Debug;
76

0 commit comments

Comments
 (0)