Skip to content

Commit

Permalink
Merge branch '1.12' into docker-cron-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferror authored Nov 15, 2022
2 parents 21b1401 + 4fe2ad4 commit bc7685e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = false

[docker-compose.{yaml,yml}]
indent_size = 2

[docker-compose.*.{yaml,yml}]
indent_size = 2

[.babelrc]
indent_style = space
indent_size = 2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: matrix.platform == 'linux/amd64'
-
name: Setup Sylius Store
run: docker compose -f ${{ matrix.docker_compose }} up -d
run: LOAD_FIXTURES=1 docker compose -f ${{ matrix.docker_compose }} up -d
if: matrix.platform == 'linux/amd64'
-
name: Health Check Store
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["crond", "-f"]

FROM sylius_php_prod AS sylius_migrations_prod

COPY docker/migrations/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]

FROM sylius_php_dev AS sylius_migrations_dev

COPY docker/migrations/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

RUN composer dump-autoload --classmap-authoritative

ENTRYPOINT ["docker-entrypoint"]
25 changes: 21 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: .
target: sylius_php_prod
depends_on:
- mysql
- migrations
environment:
APP_DEBUG: 0
APP_ENV: prod
Expand All @@ -28,7 +28,7 @@ services:
context: .
target: sylius_cron
depends_on:
- mysql
- migrations
environment:
APP_ENV: prod
APP_DEBUG: 0
Expand All @@ -37,7 +37,7 @@ services:
PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC}
networks:
- sylius

worker:
container_name: worker
command: ["php", "bin/console", "messenger:consume", "main", "catalog_promotion_removal", "--limit=5", "--memory-limit=256M", "--time-limit=600"]
Expand All @@ -46,7 +46,7 @@ services:
context: .
target: sylius_php_prod
depends_on:
- mysql
- migrations
environment:
APP_ENV: prod
APP_DEBUG: 0
Expand All @@ -57,6 +57,23 @@ services:
networks:
- sylius

migrations:
container_name: migrations
build:
context: .
target: sylius_migrations_prod
depends_on:
- mysql
environment:
APP_ENV: prod
APP_DEBUG: 0
APP_SECRET: EDITME
DATABASE_URL: mysql://sylius:${MYSQL_PASSWORD}@mysql/sylius_prod
LOAD_FIXTURES: ${LOAD_FIXTURES:-0}
PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC}
networks:
- sylius

mysql:
container_name: mysql
# in production, we may want to use a managed database service
Expand Down
17 changes: 16 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: .
target: sylius_php_dev
depends_on:
- mysql
- migrations
environment:
- APP_ENV=dev
- APP_DEBUG=1
Expand All @@ -22,6 +22,21 @@ services:
# - ./public/media:/srv/sylius/public/media:rw
- public-media:/srv/sylius/public/media:rw

migrations:
container_name: migrations
build:
context: .
target: sylius_migrations_dev
depends_on:
- mysql
environment:
- APP_ENV=dev
- APP_DEBUG=1
- APP_SECRET=EDITME
- DATABASE_URL=mysql://sylius:${MYSQL_PASSWORD:-nopassword}@mysql/sylius
- LOAD_FIXTURES=1
- PHP_DATE_TIMEZONE=${PHP_DATE_TIMEZONE:-UTC}

mysql:
container_name: mysql
image: mysql:5.7 # Sylius is fully working on mysql 8.0 version
Expand Down
25 changes: 25 additions & 0 deletions docker/migrations/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
set -e

attempt_left=20

until php bin/console doctrine:query:sql "select 1" >/dev/null 2>&1;
do
attempt_left=$((attempt_left-1))

if [ "${attempt_left}" -eq "0" ]; then

(>&2 echo "MySQL did not answer. Aborting migrations.")
exit 1
else
(>&2 echo "Waiting for MySQL to be ready...")
fi

sleep 1
done

php bin/console doctrine:migrations:migrate --no-interaction

if [ "$LOAD_FIXTURES" = "1" ]; then
php bin/console sylius:fixtures:load --no-interaction
fi
12 changes: 5 additions & 7 deletions docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
bin/console sylius:theme:assets:install public --no-interaction
fi

until bin/console doctrine:query:sql "select 1" >/dev/null 2>&1; do
(>&2 echo "Waiting for MySQL to be ready...")
sleep 1
done

bin/console doctrine:migrations:migrate --no-interaction
bin/console sylius:fixtures:load --no-interaction
while ping -c1 migrations >/dev/null 2>&1;
do
(>&2 echo "Waiting for Migrations container to finish")
sleep 1;
done;
fi

exec docker-php-entrypoint "$@"

0 comments on commit bc7685e

Please sign in to comment.