Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker setup #242

Merged
merged 2 commits into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .env.prod.dist
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@

/vendor
/node_modules
/yarn-error.log

/etc/build/*
!/etc/build/.gitkeep

/behat.yml
/phpunit.xml
/phpspec.yml

/.env
/docker-compose.override.yaml
/docker-compose.override.yml
/docker/mysql/data/
48 changes: 46 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
145 changes: 145 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 2 additions & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:

mailer_transport: '%env(SYLIUS_MAILER_TRANSPORT)%'
mailer_host: '%env(SYLIUS_MAILER_HOST)%'
mailer_port: '%env(SYLIUS_MAILER_PORT)%'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract this change to another PR?

Copy link
Contributor Author

@teohhanhui teohhanhui Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. But we need it here...

mailer_user: '%env(SYLIUS_MAILER_USER)%'
mailer_password: '%env(SYLIUS_MAILER_PASSWORD)%'

Expand All @@ -25,6 +26,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): ~

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -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"
Loading