From 5a70148d67346dc0d56b6268d6eca0cda8571147 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Mon, 23 Jul 2018 16:54:45 +0200 Subject: [PATCH 1/2] Add Docker setup --- .dockerignore | 32 ++++++ .editorconfig | 8 ++ .env.dist | 11 ++ .env.prod.dist | 11 ++ .gitignore | 6 ++ .travis.yml | 48 ++++++++- Dockerfile | 145 +++++++++++++++++++++++++++ app/config/config.yml | 2 +- app/config/parameters.yml.dist | 4 +- composer.json | 2 +- composer.lock | 2 +- docker-compose.prod.yml | 51 ++++++++++ docker-compose.yml | 108 ++++++++++++++++++++ docker/nginx/conf.d/default.conf | 39 +++++++ docker/nginx/conf.d/default.dev.conf | 62 ++++++++++++ docker/nodejs/docker-entrypoint.sh | 18 ++++ docker/php/docker-entrypoint.sh | 29 ++++++ docker/php/php-cli.dev.ini | 14 +++ docker/php/php.ini | 12 +++ gulpfile.babel.js | 3 + package.json | 3 +- 21 files changed, 602 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 .env.dist create mode 100644 .env.prod.dist create mode 100644 Dockerfile create mode 100644 docker-compose.prod.yml create mode 100644 docker-compose.yml create mode 100644 docker/nginx/conf.d/default.conf create mode 100644 docker/nginx/conf.d/default.dev.conf create mode 100755 docker/nodejs/docker-entrypoint.sh create mode 100755 docker/php/docker-entrypoint.sh create mode 100644 docker/php/php-cli.dev.ini create mode 100644 docker/php/php.ini diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..6d49f7ffb4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,32 @@ +**/*.log +**/*.md +**/*.php~ +**/._* +**/.dockerignore +**/.DS_Store +**/.git/ +**/.gitattributes +**/.gitignore +**/.gitkeep +**/.gitmodules +**/Dockerfile +**/Thumbs.db +.editorconfig +.env* +.php_cs.cache +.travis.yml +app/config/parameters.yml +app/config/*.local.yml +composer.phar +docker-compose*.yaml +docker-compose*.yml +docker/mysql/data/ +etc/build/* +node_modules/ +var/* +vendor/ +web/assets/ +web/bundles/ +web/css/ +web/js/ +web/media/ diff --git a/.editorconfig b/.editorconfig index cb0388ff8d..c98941d5c3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -65,6 +65,14 @@ indent_size = 4 indent_style = space indent_size = 4 +[docker-compose{,.override}.{yaml,yml}] +indent_style = space +indent_size = 2 + +[Dockerfile] +indent_style = tab +indent_size = 4 + [package.json] indent_style = space indent_size = 2 diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000000..25f3dc4b75 --- /dev/null +++ b/.env.dist @@ -0,0 +1,11 @@ +MYSQL_PASSWORD= +MYSQL_ROOT_PASSWORD= +PHP_DATE_TIMEZONE=UTC +SYLIUS_APP_DEV_PERMITTED=1 +SYLIUS_HOST=127.0.0.1 +SYLIUS_MAILER_HOST=mailhog +SYLIUS_MAILER_PASSWORD= +SYLIUS_MAILER_PORT=1025 +SYLIUS_MAILER_USER= +SYLIUS_SECRET= +SYMFONY_ENV=dev diff --git a/.env.prod.dist b/.env.prod.dist new file mode 100644 index 0000000000..5a897fa1b0 --- /dev/null +++ b/.env.prod.dist @@ -0,0 +1,11 @@ +MYSQL_PASSWORD= +MYSQL_ROOT_PASSWORD= +PHP_DATE_TIMEZONE= +SYLIUS_APP_DEV_PERMITTED=0 +SYLIUS_HOST= +SYLIUS_MAILER_HOST= +SYLIUS_MAILER_PASSWORD= +SYLIUS_MAILER_PORT= +SYLIUS_MAILER_USER= +SYLIUS_SECRET= +SYMFONY_ENV=prod diff --git a/.gitignore b/.gitignore index 88aba9c46a..a99c5fcd11 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ /vendor /node_modules +/yarn-error.log /etc/build/* !/etc/build/.gitkeep @@ -26,3 +27,8 @@ /behat.yml /phpunit.xml /phpspec.yml + +/.env +/docker-compose.override.yaml +/docker-compose.override.yml +/docker/mysql/data/ diff --git a/.travis.yml b/.travis.yml index 9cc90d99e5..958afe031f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,49 @@ language: php dist: trusty -sudo: false +sudo: required php: - 7.1 - 7.2 +jobs: + include: + - stage: deploy + env: + DOCKER_COMPOSE_VERSION=1.22.0 + before_install: + - sudo rm /usr/local/bin/docker-compose + - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose + - chmod +x docker-compose + - sudo mv docker-compose /usr/local/bin + install: true + before_script: + - sudo service mysql stop + # wait for mysql to shutdown + - while sudo lsof -Pi :3306 -sTCP:LISTEN -t; do sleep 1; done + script: + - docker-compose pull --ignore-pull-failures || true + - docker-compose build --pull + - docker-compose up -d + - sleep 60 + - docker-compose exec php bin/console sylius:fixtures:load --no-interaction + - curl http://localhost/app_dev.php/ + - curl http://localhost/app_dev.php/admin/ + after_success: true + after_failure: true + before_deploy: + - echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin "$DOCKER_REGISTRY" + deploy: + provider: script + script: docker-compose push + skip_cleanup: true + on: + repo: Sylius/Sylius-Standard + tags: true + after_deploy: true + after_script: true + cache: yarn: true directories: @@ -23,7 +60,14 @@ env: - SYMFONY_VERSION="4.1.*" services: - - memcached + - docker + - memcached + - mysql + +addons: + apt: + packages: + - docker-ce before_install: - phpenv config-rm xdebug.ini || true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..c0b39e3973 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,145 @@ +# the different stages of this Dockerfile are meant to be built into separate images +# https://docs.docker.com/compose/compose-file/#target + +ARG PHP_VERSION=7.2 +ARG NODE_VERSION=10 +ARG NGINX_VERSION=1.15 + +FROM php:${PHP_VERSION}-fpm-alpine AS sylius_php + +# persistent / runtime deps +RUN apk add --no-cache \ + acl \ + file \ + gettext \ + git \ + mariadb-client \ + ; + +ARG APCU_VERSION=5.1.11 +RUN set -eux; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + freetype-dev \ + icu-dev \ + libjpeg-turbo-dev \ + libpng-dev \ + libtool \ + libwebp-dev \ + libzip-dev \ + mariadb-dev \ + zlib-dev \ + ; \ + \ + docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include --with-webp-dir=/usr/include --with-freetype-dir=/usr/include/; \ + docker-php-ext-configure zip --with-libzip; \ + docker-php-ext-install -j$(nproc) \ + exif \ + gd \ + intl \ + pdo_mysql \ + zip \ + ; \ + pecl install \ + apcu-${APCU_VERSION} \ + ; \ + pecl clear-cache; \ + docker-php-ext-enable \ + apcu \ + opcache \ + ; \ + \ + runDeps="$( \ + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \ + | tr ',' '\n' \ + | sort -u \ + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ + )"; \ + apk add --no-cache --virtual .sylius-phpexts-rundeps $runDeps; \ + \ + apk del .build-deps + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +COPY docker/php/php.ini /usr/local/etc/php/php.ini + +# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser +ENV COMPOSER_ALLOW_SUPERUSER=1 +RUN set -eux; \ + composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \ + composer clear-cache +ENV PATH="${PATH}:/root/.composer/vendor/bin" + +WORKDIR /srv/sylius + +# build for production +ARG SYMFONY_ENV=prod + +# prevent the reinstallation of vendors at every changes in the source code +COPY composer.json composer.lock ./ +RUN set -eux; \ + composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest; \ + composer clear-cache + +COPY . ./ + +RUN set -eux; \ + mkdir -p var/cache var/logs; \ + composer dump-autoload --classmap-authoritative --no-dev; \ + composer run-script --no-dev post-install-cmd; \ + chmod +x bin/console; sync; \ + bin/console sylius:install:assets; \ + bin/console sylius:theme:assets:install +VOLUME /srv/sylius/var + +VOLUME /srv/sylius/web/media + +COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint +RUN chmod +x /usr/local/bin/docker-entrypoint + +ENTRYPOINT ["docker-entrypoint"] +CMD ["php-fpm"] + +FROM node:${NODE_VERSION}-alpine AS sylius_nodejs + +WORKDIR /srv/sylius + +RUN set -eux; \ + apk add --no-cache --virtual .build-deps \ + g++ \ + gcc \ + git \ + make \ + python \ + ; + +# prevent the reinstallation of vendors at every changes in the source code +COPY package.json yarn.lock ./ +RUN set -eux; \ + yarn install; \ + yarn cache clean + +COPY --from=sylius_php /srv/sylius/vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Resources/private vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Resources/private/ +COPY --from=sylius_php /srv/sylius/vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Resources/private vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Resources/private/ +COPY --from=sylius_php /srv/sylius/vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/private vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/private/ + +COPY --from=sylius_php /srv/sylius/vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js +COPY --from=sylius_php /srv/sylius/vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/gulpfile.babel.js vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/gulpfile.babel.js + +COPY gulpfile.babel.js .babelrc ./ +RUN set -eux; \ + GULP_ENV=prod yarn build + +COPY docker/nodejs/docker-entrypoint.sh /usr/local/bin/docker-entrypoint +RUN chmod +x /usr/local/bin/docker-entrypoint + +ENTRYPOINT ["docker-entrypoint"] +CMD ["yarn", "watch"] + +FROM nginx:${NGINX_VERSION}-alpine AS sylius_nginx + +COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/ + +WORKDIR /srv/sylius + +COPY --from=sylius_php /srv/sylius/web web/ +COPY --from=sylius_nodejs /srv/sylius/web web/ diff --git a/app/config/config.yml b/app/config/config.yml index 0e5744a731..78f4277826 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -31,12 +31,12 @@ framework: doctrine: dbal: - driver: '%database_driver%' host: '%database_host%' port: '%database_port%' dbname: '%database_name%' user: '%database_user%' password: '%database_password%' + driver: pdo_mysql server_version: '5.5' charset: UTF8 diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index f6a60eee79..74b2665ff1 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -1,5 +1,4 @@ parameters: - database_driver: '%env(SYLIUS_DATABASE_DRIVER)%' database_host: '%env(SYLIUS_DATABASE_HOST)%' database_port: '%env(SYLIUS_DATABASE_PORT)%' database_name: '%env(SYLIUS_DATABASE_NAME)%' @@ -10,13 +9,13 @@ parameters: mailer_transport: '%env(SYLIUS_MAILER_TRANSPORT)%' mailer_host: '%env(SYLIUS_MAILER_HOST)%' + mailer_port: '%env(SYLIUS_MAILER_PORT)%' mailer_user: '%env(SYLIUS_MAILER_USER)%' mailer_password: '%env(SYLIUS_MAILER_PASSWORD)%' secret: '%env(SYLIUS_SECRET)%' # Fallback values (used if environmental variables are not set) - env(SYLIUS_DATABASE_DRIVER): pdo_mysql env(SYLIUS_DATABASE_HOST): 127.0.0.1 env(SYLIUS_DATABASE_PORT): ~ env(SYLIUS_DATABASE_NAME): sylius @@ -25,6 +24,7 @@ parameters: env(SYLIUS_MAILER_TRANSPORT): smtp env(SYLIUS_MAILER_HOST): 127.0.0.1 + env(SYLIUS_MAILER_PORT): ~ env(SYLIUS_MAILER_USER): ~ env(SYLIUS_MAILER_PASSWORD): ~ diff --git a/composer.json b/composer.json index 86144df9be..ab3f29ed6b 100644 --- a/composer.json +++ b/composer.json @@ -79,7 +79,7 @@ "symfony-var-dir": "var", "symfony-web-dir": "web", "symfony-tests-dir": "tests", - "symfony-assets-install": "relative", + "symfony-assets-install": "copy", "incenteev-parameters": { "file": "app/config/parameters.yml" }, diff --git a/composer.lock b/composer.lock index 2ffc0da754..c5e958733d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "be6639f89865b7a009f63e30a45a1fcf", + "content-hash": "8cfea0df1227483798340479506a224b", "packages": [ { "name": "behat/transliterator", diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000000..5d33c2f078 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,51 @@ +version: '3.4' + +services: + php: + image: quay.io/sylius/php:latest + depends_on: + - mysql + environment: + - SYMFONY_ENV=${SYMFONY_ENV:-prod} + - SYLIUS_APP_DEV_PERMITTED=${SYLIUS_APP_DEV_PERMITTED:-0} + - SYLIUS_HOST=${SYLIUS_HOST:?SYLIUS_HOST is not set or empty} + - SYLIUS_DATABASE_HOST=mysql + - SYLIUS_DATABASE_PORT=3306 + - SYLIUS_DATABASE_NAME=sylius + - SYLIUS_DATABASE_USER=sylius + - SYLIUS_DATABASE_PASSWORD=${MYSQL_PASSWORD:?MYSQL_PASSWORD is not set or empty} + - SYLIUS_MAILER_TRANSPORT=smtp + - SYLIUS_MAILER_HOST=${SYLIUS_MAILER_HOST:?SYLIUS_MAILER_HOST is not set or empty} + - SYLIUS_MAILER_PORT=${SYLIUS_MAILER_PORT:?SYLIUS_MAILER_PORT is not set or empty} + - SYLIUS_MAILER_USER=${SYLIUS_MAILER_USER?SYLIUS_MAILER_USER is not set} + - SYLIUS_MAILER_PASSWORD=${SYLIUS_MAILER_PASSWORD?SYLIUS_MAILER_PASSWORD is not set} + - SYLIUS_SECRET=${SYLIUS_SECRET:?SYLIUS_SECRET is not set or empty} + - PHP_DATE_TIMEZONE=${PHP_DATE_TIMEZONE:?PHP_DATE_TIMEZONE is not set or empty} + volumes: + # use a bind-mounted host directory, as we want to keep the sessions + - ./var/sessions:/srv/sylius/var/sessions:rw + # use a bind-mounted host directory, as we want to keep the media + - ./web/media:/srv/sylius/web/media:rw + + mysql: + # in production, we may want to use a managed database service + image: percona:5.7 + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:?MYSQL_ROOT_PASSWORD is not set or empty} + - MYSQL_DATABASE=sylius + - MYSQL_USER=sylius + - MYSQL_PASSWORD=${MYSQL_PASSWORD:?MYSQL_PASSWORD is not set or empty} + volumes: + # use a bind-mounted host directory, because we never want to lose our data! + - ./docker/mysql/data:/var/lib/mysql:rw,delegated + + nginx: + # in production, we may want to use a static website hosting service + image: quay.io/sylius/nginx:latest + depends_on: + - php + volumes: + # use a bind-mounted host directory, as we want to keep the media + - ./web/media:/srv/sylius/web/media:ro + ports: + - "80:80" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..42de94d14f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,108 @@ +version: '3.4' + +services: + php: + build: + context: . + target: sylius_php + cache_from: + - quay.io/sylius/php:latest + - quay.io/sylius/nodejs:latest + - quay.io/sylius/nginx:latest + image: quay.io/sylius/php:latest + depends_on: + - mysql + environment: + - SYMFONY_ENV=${SYMFONY_ENV-dev} + - SYLIUS_APP_DEV_PERMITTED=${SYLIUS_APP_DEV_PERMITTED-1} + - SYLIUS_HOST=${SYLIUS_HOST-127.0.0.1} + - SYLIUS_DATABASE_HOST=mysql + - SYLIUS_DATABASE_PORT=3306 + - SYLIUS_DATABASE_NAME=sylius + - SYLIUS_DATABASE_USER=sylius + - SYLIUS_DATABASE_PASSWORD=${MYSQL_PASSWORD:-nopassword} + - SYLIUS_MAILER_TRANSPORT=smtp + - SYLIUS_MAILER_HOST=${SYLIUS_MAILER_HOST-mailhog} + - SYLIUS_MAILER_PORT=${SYLIUS_MAILER_PORT-1025} + - SYLIUS_MAILER_USER=${SYLIUS_MAILER_USER-} + - SYLIUS_MAILER_PASSWORD=${SYLIUS_MAILER_PASSWORD-} + - SYLIUS_SECRET=${SYLIUS_SECRET:-nosecret} + - PHP_DATE_TIMEZONE=${PHP_DATE_TIMEZONE:-UTC} + volumes: + - .:/srv/sylius:rw,cached + - ./docker/php/php-cli.dev.ini:/usr/local/etc/php/php-cli.ini + # if you develop on Linux, you may use a bind-mounted host directory instead + # - ./var:/srv/sylius/var:rw + - ./web:/srv/sylius/web:rw,delegated + # if you develop on Linux, you may use a bind-mounted host directory instead + # - ./web/media:/srv/sylius/web/media:rw + - web-media:/srv/sylius/web/media:rw + + mysql: + image: percona:5.7 + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-nopassword} + - MYSQL_DATABASE=sylius_${SYMFONY_ENV-dev} + - MYSQL_USER=sylius + - MYSQL_PASSWORD=${MYSQL_PASSWORD:-nopassword} + volumes: + - mysql-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/mysql/data:/var/lib/mysql:rw,delegated + ports: + - "3306:3306" + + nodejs: + build: + context: . + target: sylius_nodejs + cache_from: + - quay.io/sylius/php:latest + - quay.io/sylius/nodejs:latest + - quay.io/sylius/nginx:latest + image: quay.io/sylius/nodejs:latest + depends_on: + - php + environment: + - GULP_ENV=dev + - PHP_HOST=php + - PHP_PORT=9000 + volumes: + - .:/srv/sylius:rw,cached + - ./web:/srv/sylius/web:rw,delegated + ports: + - "35729:35729" + + nginx: + build: + context: . + target: sylius_nginx + cache_from: + - quay.io/sylius/php:latest + - quay.io/sylius/nodejs:latest + - quay.io/sylius/nginx:latest + image: quay.io/sylius/nginx:latest + depends_on: + - php + volumes: + - ./docker/nginx/conf.d/default.dev.conf:/etc/nginx/conf.d/default.conf + - ./web:/srv/sylius/web:ro + # if you develop on Linux, you may use a bind-mounted host directory instead + # - ./web/media:/srv/sylius/web/media:ro + - web-media:/srv/sylius/web/media:ro,nocopy + ports: + - "80:80" + + mailhog: + # do not use in production! + image: mailhog/mailhog:latest + environment: + - MH_STORAGE=maildir + volumes: + - ./docker/mailhog/maildir:/maildir:rw,delegated + ports: + - "8025:8025" + +volumes: + mysql-data: + web-media: diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf new file mode 100644 index 0000000000..d8d03ee915 --- /dev/null +++ b/docker/nginx/conf.d/default.conf @@ -0,0 +1,39 @@ +server { + root /srv/sylius/web; + + location / { + # try to serve file directly, fallback to app.php + try_files $uri /app.php$is_args$args; + } + + # PROD + location ~ ^/app\.php(/|$) { + # Comment the next line and uncomment the lines after to enable dynamic resolution (incompatible with Kubernetes) + fastcgi_pass php:9000; + #resolver 127.0.0.11; + #set $upstream_host php; + #fastcgi_pass $upstream_host:9000; + + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + # When you are using symlinks to link the document root to the + # current version of your application, you should pass the real + # application path instead of the path to the symlink to PHP + # FPM. + # Otherwise, PHP's OPcache may not properly detect changes to + # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 + # for more information). + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + # Prevents URIs that include the front controller. This will 404: + # http://domain.tld/app.php/some-path + # Remove the internal directive to allow URIs like this + internal; + } + + # return 404 for all other php files not matching the front controller + # this prevents access to other php files you don't want to be accessible. + location ~ \.php$ { + return 404; + } +} diff --git a/docker/nginx/conf.d/default.dev.conf b/docker/nginx/conf.d/default.dev.conf new file mode 100644 index 0000000000..2442c9302d --- /dev/null +++ b/docker/nginx/conf.d/default.dev.conf @@ -0,0 +1,62 @@ +server { + root /srv/sylius/web; + + location / { + # try to serve file directly, fallback to app.php + try_files $uri /app.php$is_args$args; + } + + # DEV + # This rule should only be placed on your development environment + # In production, don't include this and don't deploy app_dev.php or config.php + location ~ ^/(app_dev|config)\.php(/|$) { + # Comment the next line and uncomment the lines after to enable dynamic resolution (incompatible with Kubernetes) + fastcgi_pass php:9000; + #resolver 127.0.0.11; + #set $upstream_host php; + #fastcgi_pass $upstream_host:9000; + + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + # When you are using symlinks to link the document root to the + # current version of your application, you should pass the real + # application path instead of the path to the symlink to PHP + # FPM. + # Otherwise, PHP's OPcache may not properly detect changes to + # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 + # for more information). + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + } + + # PROD + location ~ ^/app\.php(/|$) { + # Comment the next line and uncomment the lines after to enable dynamic resolution (incompatible with Kubernetes) + fastcgi_pass php:9000; + #resolver 127.0.0.11; + #set $upstream_host php; + #fastcgi_pass $upstream_host:9000; + + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + # When you are using symlinks to link the document root to the + # current version of your application, you should pass the real + # application path instead of the path to the symlink to PHP + # FPM. + # Otherwise, PHP's OPcache may not properly detect changes to + # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 + # for more information). + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + # Prevents URIs that include the front controller. This will 404: + # http://domain.tld/app.php/some-path + # Remove the internal directive to allow URIs like this + internal; + } + + # return 404 for all other php files not matching the front controller + # this prevents access to other php files you don't want to be accessible. + location ~ \.php$ { + return 404; + } +} diff --git a/docker/nodejs/docker-entrypoint.sh b/docker/nodejs/docker-entrypoint.sh new file mode 100755 index 0000000000..ecd73af806 --- /dev/null +++ b/docker/nodejs/docker-entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- node "$@" +fi + +if [ "$1" = 'node' ] || [ "$1" = 'yarn' ]; then + yarn install + + >&2 echo "Waiting for PHP to be ready..." + until nc -z "$PHP_HOST" "$PHP_PORT"; do + sleep 1 + done +fi + +exec "$@" diff --git a/docker/php/docker-entrypoint.sh b/docker/php/docker-entrypoint.sh new file mode 100755 index 0000000000..427ae1c1e9 --- /dev/null +++ b/docker/php/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/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 + mkdir -p var/cache var/logs web/media + setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var web/media + setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var web/media + + if [ "$SYMFONY_ENV" != 'prod' ]; then + composer install --prefer-dist --no-progress --no-suggest --no-interaction + bin/console assets:install web --no-interaction + bin/console sylius:theme:assets:install --no-interaction + fi + + >&2 echo "Waiting for MySQL to be ready..." + until select="$(echo 'SELECT 1' | mysql --host="${SYLIUS_DATABASE_HOST}" --database="${SYLIUS_DATABASE_NAME}_${SYMFONY_ENV}" --user="${SYLIUS_DATABASE_USER}" --password="${SYLIUS_DATABASE_PASSWORD}" --silent)" && [ "$select" = '1' ]; do + sleep 1 + done + if [ "$(ls -A app/migrations/*.php 2> /dev/null)" ]; then + bin/console doctrine:migrations:migrate --no-interaction + fi +fi + +exec docker-php-entrypoint "$@" diff --git a/docker/php/php-cli.dev.ini b/docker/php/php-cli.dev.ini new file mode 100644 index 0000000000..0bde7e729a --- /dev/null +++ b/docker/php/php-cli.dev.ini @@ -0,0 +1,14 @@ +apc.enable_cli = 1 +date.timezone = ${PHP_DATE_TIMEZONE} +opcache.enable_cli = 1 +session.auto_start = Off +short_open_tag = Off + +# http://symfony.com/doc/current/performance.html +opcache.interned_strings_buffer = 16 +opcache.max_accelerated_files = 20000 +opcache.memory_consumption = 256 +realpath_cache_size = 4096K +realpath_cache_ttl = 600 + +memory_limit = -1 diff --git a/docker/php/php.ini b/docker/php/php.ini new file mode 100644 index 0000000000..1fabe37694 --- /dev/null +++ b/docker/php/php.ini @@ -0,0 +1,12 @@ +apc.enable_cli = 1 +date.timezone = ${PHP_DATE_TIMEZONE} +opcache.enable_cli = 1 +session.auto_start = Off +short_open_tag = Off + +# http://symfony.com/doc/current/performance.html +opcache.interned_strings_buffer = 16 +opcache.max_accelerated_files = 20000 +opcache.memory_consumption = 256 +realpath_cache_size = 4096K +realpath_cache_ttl = 600 diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 56c86ae9ac..7d0f439936 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -52,6 +52,9 @@ watchShop.description = 'Watch shop asset sources and rebuild on changes.'; export const build = gulp.parallel(buildAdmin, buildShop); build.description = 'Build assets.'; +export const watch = gulp.parallel(watchAdmin, watchShop); +watch.description = 'Watch asset sources and rebuild on changes.'; + gulp.task('admin', buildAdmin); gulp.task('admin-watch', watchAdmin); gulp.task('shop', buildShop); diff --git a/package.json b/package.json index 14072b2b32..b1f25293e2 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "build": "gulp build", "gulp": "gulp build", "lint": "yarn lint:js", - "lint:js": "eslint gulpfile.babel.js" + "lint:js": "eslint gulpfile.babel.js", + "watch": "gulp watch" }, "repository": { "type": "git", From bdfd1c8025dc5e5ec9e153c1d08316a9a925108c Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Sun, 29 Jul 2018 11:57:18 +0200 Subject: [PATCH 2/2] Revert removing "database_driver" parameter --- app/config/config.yml | 2 +- app/config/parameters.yml.dist | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/config/config.yml b/app/config/config.yml index 78f4277826..0e5744a731 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -31,12 +31,12 @@ framework: doctrine: dbal: + driver: '%database_driver%' host: '%database_host%' port: '%database_port%' dbname: '%database_name%' user: '%database_user%' password: '%database_password%' - driver: pdo_mysql server_version: '5.5' charset: UTF8 diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 74b2665ff1..592370ca17 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -1,4 +1,5 @@ parameters: + database_driver: '%env(SYLIUS_DATABASE_DRIVER)%' database_host: '%env(SYLIUS_DATABASE_HOST)%' database_port: '%env(SYLIUS_DATABASE_PORT)%' database_name: '%env(SYLIUS_DATABASE_NAME)%' @@ -16,6 +17,7 @@ parameters: secret: '%env(SYLIUS_SECRET)%' # Fallback values (used if environmental variables are not set) + env(SYLIUS_DATABASE_DRIVER): pdo_mysql env(SYLIUS_DATABASE_HOST): 127.0.0.1 env(SYLIUS_DATABASE_PORT): ~ env(SYLIUS_DATABASE_NAME): sylius