Merge pull request #2 from dunglas/upgrade

Upgrade the Docker setup and dependencies
This commit is contained in:
Kévin Dunglas 2017-06-12 10:37:12 +02:00 committed by GitHub
commit 2d6d2ecd59
16 changed files with 147 additions and 68 deletions

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
* text=auto
*.sh text eol=lf
docker/apache/start_safe_perms text eol=lf

View File

@ -3,7 +3,6 @@ FROM php:7.1-fpm-alpine
RUN apk add --no-cache --virtual .persistent-deps \
git \
icu-libs \
make \
zlib
ENV APCU_VERSION 5.1.8
@ -23,10 +22,9 @@ RUN set -xe \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
&& apk del .build-deps
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer
COPY docker/app/php.ini /usr/local/etc/php/php.ini
COPY docker/app/install-composer.sh /usr/local/bin/docker-app-install-composer
RUN chmod +x /usr/local/bin/docker-app-install-composer
RUN set -xe \
@ -42,7 +40,7 @@ ENV COMPOSER_ALLOW_SUPERUSER 1
RUN composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --optimize-autoloader --classmap-authoritative \
&& composer clear-cache
WORKDIR /srv/api-platform
WORKDIR /srv/app
COPY composer.json ./
COPY composer.lock ./
@ -63,8 +61,8 @@ COPY web web/
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
COPY docker/php/start.sh /usr/local/bin/docker-app-start
COPY docker/app/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint
RUN chmod +x /usr/local/bin/docker-app-entrypoint
RUN chmod +x /usr/local/bin/docker-app-start
CMD ["docker-app-start"]
ENTRYPOINT ["docker-app-entrypoint"]
CMD ["php-fpm"]

View File

@ -3,17 +3,13 @@
"type": "project",
"license": "proprietary",
"description": "Project description",
"minimum-stability": "dev",
"require": {
"php": "^7.1",
"symfony/flex": "1.0.x-dev",
"symfony/framework-bundle": "3.3.x-dev",
"symfony/yaml": "3.3.x-dev"
"php": "^7.1.3",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^3.3",
"symfony/yaml": "^3.3"
},
"config": {
"platform": {
"php": "7.1"
},
"preferred-install": {
"*": "dist"
},
@ -39,11 +35,8 @@
"@auto-scripts"
]
},
"repositories": [
{ "type": "vcs", "url": "https://github.com/fabpot/flex" }
],
"conflict": {
"symfony/symfony": "<3.3",
"symfony/symfony": "*",
"symfony/twig-bundle": "<3.3",
"symfony/debug": "<3.3"
},

View File

@ -1,36 +1,54 @@
version: '3'
services:
#db:
# image: mysql:5.7
# environment:
# MYSQL_DATABASE: symfony
# MYSQL_USER: symfony
# MYSQL_PASSWORD: symfony
# MYSQL_RANDOM_ROOT_PASSWORD: 'true'
# volumes:
# - db-data:/var/lib/mysql
# healthcheck:
# test: mysql --user=api_platform --password=api_platform -e "SELECT 1" api_platform
php:
build: .
app:
build:
context: .
dockerfile: ./Dockerfile
#depends_on:
# - db
environment:
# Change to prod in production
- SYMFONY_ENV=dev
volumes:
- ./:/srv/api-platform
env_file:
- .env
# Comment out the next line in production
- ./:/srv/app:rw
# This is for assets:install
- ./web:/srv/app/web:rw
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
- /srv/app/var
- /srv/app/var/cache
- /srv/app/var/logs
- /srv/app/var/sessions
- /srv/app/vendor
nginx:
image: nginx:1.11-alpine
depends_on:
- php
ports:
- '80:80'
build:
context: ./docker/nginx
dockerfile: ./Dockerfile
volumes:
# Comment out the next line in production
- ./docker/nginx/conf.d:/etc/nginx/conf.d:ro
- ./:/srv/api-platform
- ./web:/srv/app/web:ro
ports:
- "80:80"
#volumes:
# db-data:
# Uncomment the following lines to add a MySQL container
#db:
# build:
# context: ./docker/db
# dockerfile: ./Dockerfile
# environment:
# - MYSQL_DATABASE=app
# # You should definitely change the password in production
# - MYSQL_PASSWORD=symfony
# - MYSQL_RANDOM_ROOT_PASSWORD=true
# - MYSQL_USER=symfony
# volumes:
# - db-data:/var/lib/mysql:rw
# # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# # - ./docker/db/data:/var/lib/mysql:rw
volumes:
app-web: {}
#db-data: {}

24
docker/app/docker-entrypoint.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
set -e
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi
if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
# Detect the host IP
export DOCKER_BRIDGE_IP
DOCKER_BRIDGE_IP=$(ip ro | grep default | cut -d' ' -f 3)
if [ "$SYMFONY_ENV" = 'prod' ]; then
composer install --prefer-dist --no-dev --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --no-interaction
else
composer install --prefer-dist --no-progress --no-suggest --no-interaction
fi
# Permissions hack because setfacl does not work on Mac and Windows
chown -R www-data var
fi
exec docker-php-entrypoint "$@"

View File

@ -1,5 +1,9 @@
#!/bin/sh
# Copyright (c) Nils Adermann, Jordi Boggiano
# Origin: https://github.com/composer/composer/blob/master/doc/faqs/how-to-install-composer-programmatically.md
# Licence: MIT
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")

10
docker/db/.dockerignore Normal file
View File

@ -0,0 +1,10 @@
**/*.log
**/*.md
**/*.sql.gz
**/._*
**/.DS_Store
**/.gitignore
**/Thumbs.db
.dockerignore
data/
Dockerfile

1
docker/db/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
data/

6
docker/db/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM mysql:5.7
COPY docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck
HEALTHCHECK CMD ["docker-healthcheck"]

30
docker/db/docker-healthcheck.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# Copyright (c) 2014-2016 Docker, Inc.
# Origin: https://github.com/docker-library/healthcheck/blob/master/mysql/docker-healthcheck
# Licence: MIT
set -eo pipefail
if [ "$MYSQL_RANDOM_ROOT_PASSWORD" ] && [ -z "$MYSQL_USER" ] && [ -z "$MYSQL_PASSWORD" ]; then
# there's no way we can guess what the random MySQL password was
echo >&2 'healthcheck error: cannot determine random root password (and MYSQL_USER and MYSQL_PASSWORD were not set)'
exit 0
fi
host="$(hostname --ip-address || echo '127.0.0.1')"
user="${MYSQL_USER:-root}"
export MYSQL_PWD="${MYSQL_PASSWORD:-$MYSQL_ROOT_PASSWORD}"
args=(
# force mysql to not use the local "mysqld.sock" (test "external" connectibility)
-h"$host"
-u"$user"
--silent
)
if select="$(echo 'SELECT 1' | mysql "${args[@]}")" && [ "$select" = '1' ]; then
exit 0
fi
exit 1

View File

@ -0,0 +1,8 @@
**/*.log
**/*.md
**/._*
**/.DS_Store
**/.gitignore
**/Thumbs.db
.dockerignore
Dockerfile

3
docker/nginx/Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM nginx:1.11-alpine
COPY conf.d /etc/nginx/conf.d/

View File

@ -1,12 +1,13 @@
server {
root /srv/api-platform/web;
root /srv/app/web;
resolver 127.0.0.11;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_pass app:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
@ -29,7 +30,4 @@ server {
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/app_error.log;
access_log /var/log/nginx/app_access.log;
}

View File

@ -1,16 +0,0 @@
#!/bin/sh
set -xe
# Detect the host IP
export DOCKER_BRIDGE_IP=$(ip ro | grep default | cut -d' ' -f 3)
if [ "APP_ENV" = 'prod' ]; then
composer install --prefer-dist --no-dev --no-progress --no-suggest --optimize-autoloader --classmap-authoritative
else
composer install --prefer-dist --no-progress --no-suggest
fi
# Permissions hack because setfacl does not work on Mac and Windows
chown -R www-data var
exec php-fpm

View File

@ -1,7 +1,6 @@
<?php
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;