diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c36a3ba --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto +*.sh text eol=lf +docker/apache/start_safe_perms text eol=lf diff --git a/Dockerfile b/Dockerfile index e3204f0..4157ef9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/composer.json b/composer.json index e765ec9..7312976 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/docker-compose.yml b/docker-compose.yml index 590fc27..9995ee4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: {} diff --git a/docker/app/docker-entrypoint.sh b/docker/app/docker-entrypoint.sh new file mode 100755 index 0000000..2882a73 --- /dev/null +++ b/docker/app/docker-entrypoint.sh @@ -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 "$@" diff --git a/docker/php/install-composer.sh b/docker/app/install-composer.sh similarity index 72% rename from docker/php/install-composer.sh rename to docker/app/install-composer.sh index 6f01e38..f4ad41b 100755 --- a/docker/php/install-composer.sh +++ b/docker/app/install-composer.sh @@ -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');") diff --git a/docker/php/php.ini b/docker/app/php.ini similarity index 100% rename from docker/php/php.ini rename to docker/app/php.ini diff --git a/docker/db/.dockerignore b/docker/db/.dockerignore new file mode 100644 index 0000000..c430d8b --- /dev/null +++ b/docker/db/.dockerignore @@ -0,0 +1,10 @@ +**/*.log +**/*.md +**/*.sql.gz +**/._* +**/.DS_Store +**/.gitignore +**/Thumbs.db +.dockerignore +data/ +Dockerfile diff --git a/docker/db/.gitignore b/docker/db/.gitignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/docker/db/.gitignore @@ -0,0 +1 @@ +data/ diff --git a/docker/db/Dockerfile b/docker/db/Dockerfile new file mode 100644 index 0000000..aa56256 --- /dev/null +++ b/docker/db/Dockerfile @@ -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"] diff --git a/docker/db/docker-healthcheck.sh b/docker/db/docker-healthcheck.sh new file mode 100755 index 0000000..52e0903 --- /dev/null +++ b/docker/db/docker-healthcheck.sh @@ -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 diff --git a/docker/nginx/.dockerignore b/docker/nginx/.dockerignore new file mode 100644 index 0000000..e99352e --- /dev/null +++ b/docker/nginx/.dockerignore @@ -0,0 +1,8 @@ +**/*.log +**/*.md +**/._* +**/.DS_Store +**/.gitignore +**/Thumbs.db +.dockerignore +Dockerfile diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..07b07f0 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:1.11-alpine + +COPY conf.d /etc/nginx/conf.d/ diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf index 501def4..cd87e84 100644 --- a/docker/nginx/conf.d/default.conf +++ b/docker/nginx/conf.d/default.conf @@ -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; } diff --git a/docker/php/start.sh b/docker/php/start.sh deleted file mode 100644 index 952fae9..0000000 --- a/docker/php/start.sh +++ /dev/null @@ -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 diff --git a/web/index.php b/web/index.php index e5458ff..8df305c 100644 --- a/web/index.php +++ b/web/index.php @@ -1,7 +1,6 @@