diff --git a/.gitignore b/.gitignore index 18f89487ee..1cafdff916 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ /docker-compose.override.yaml /docker-compose.override.yml +/compose.override.yaml +/compose.override.yml /docker/mysql/data/ ###> symfony/framework-bundle ### @@ -46,4 +48,5 @@ /npm-debug.log /yarn-error.log /yarn.lock +/package-lock.json ###< symfony/webpack-encore-bundle ### diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..61eae83004 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +.PHONY: run + +DOCKER_USER ?= "$(shell id -u):$(shell id -g)" +ENV ?= "dev" + +init: + @if [ ! -e compose.override.yml ]; then \ + cp compose.override.dist.yml compose.override.yml; \ + fi + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose run --rm php composer install --no-interaction --no-scripts + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose run --rm nodejs + make install + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose up -d + +run: + make up + +debug: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose -f compose.yml -f compose.override.yml -f compose.debug.yml up -d + +up: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose up -d + +down: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose down + +install: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose run --rm php bin/console sylius:install -s default -n + +clean: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose down -v + +php-shell: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose exec php sh + +node-shell: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose run --rm -i nodejs sh + +node-watch: + @ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) docker-compose run --rm -i nodejs "npm run watch" diff --git a/compose.override.dist.yml b/compose.override.dist.yml new file mode 100644 index 0000000000..86a1df7c26 --- /dev/null +++ b/compose.override.dist.yml @@ -0,0 +1,71 @@ +version: "3.8" +services: + php: + image: ghcr.io/sylius/sylius-php:8.2-fixuid-xdebug-alpine + user: ${DOCKER_USER:-1000:1000} + depends_on: + mysql: + condition: service_healthy + environment: + # You can move these environment variables to your .env.local file + APP_DEBUG: 0 + APP_ENV: ${ENV:-prod} + APP_SECRET: EDITME + DATABASE_URL: "mysql://root@mysql/sylius_%kernel.environment%" + MAILER_DSN: smtp://mailhog:1025 + MESSENGER_TRANSPORT_DSN: doctrine://default + SYLIUS_MESSENGER_TRANSPORT_MAIN_DSN: doctrine://default + SYLIUS_MESSENGER_TRANSPORT_MAIN_FAILED_DSN: doctrine://default?queue_name=main_failed + SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_DSN: doctrine://default?queue_name=catalog_promotion_removal + SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_FAILED_DSN: doctrine://default?queue_name=catalog_promotion_removal_failed + PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC} + XDEBUG_MODE: debug + XDEBUG_CONFIG: >- + client_host=host.docker.internal + client_port=9003 + log=/dev/stdout + # This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers` + # Then PHPStorm will use the corresponding path mappings + PHP_IDE_CONFIG: serverName=sylius + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - .:/srv/sylius:rw,cached + # if you develop on Linux, you may use a bind-mounted host directory instead +# - ./var:/srv/sylius/var:rw + - ./public:/srv/sylius/public:rw,delegated + # if you develop on Linux, you may use a bind-mounted host directory instead +# - ./public/media:/srv/sylius/public/media:rw + - public-media:/srv/sylius/public/media:rw + mysql: + volumes: + - mysql-data:/var/lib/mysql:rw + ports: + - "8051:3306" + nginx: + volumes: + - ./public:/srv/sylius/public:ro + # if you develop on Linux, you may use a bind-mounted host directory instead +# - ./public/media:/srv/sylius/public/media:ro + - public-media:/srv/sylius/public/media:ro,nocopy + ports: + - "8050:80" + nodejs: + image: node:${NODE_VERSION:-18}-alpine + user: ${DOCKER_USER:-1000:1000} + working_dir: /srv/sylius + entrypoint: [ "/bin/sh","-c" ] + command: + - | + npm install + npm run build + volumes: + - .:/srv/sylius:rw,cached + - ./public:/srv/sylius/public:rw,delegated + mailhog: + ports: + - "8052:8025" + +volumes: + mysql-data: + public-media: diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000000..fbdc6a533b --- /dev/null +++ b/compose.yml @@ -0,0 +1,20 @@ +services: + php: + image: ghcr.io/sylius/sylius-php:8.2-alpine + mysql: + image: mysql:8.0 + platform: linux/amd64 + healthcheck: + test: '/usr/bin/mysql --execute "SHOW databases;"' + timeout: 3s + interval: 1s + retries: 10 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + cap_add: + - SYS_NICE # prevent "mbind: Operation not permitted" errors + nginx: + image: ghcr.io/sylius/sylius-nginx:latest + mailhog: + # do not use in production! + image: mailhog/mailhog:latest diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index 02d5b87b38..0000000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,118 +0,0 @@ -services: - php: - container_name: php - build: - context: . - target: sylius_php_prod - depends_on: - - migrations - environment: - APP_DEBUG: 0 - APP_ENV: prod - APP_SECRET: EDITME - DATABASE_URL: mysql://sylius:${MYSQL_PASSWORD}@mysql/sylius_prod - MAILER_URL: smtp://localhost - MESSENGER_TRANSPORT_DSN: doctrine://default - SYLIUS_MESSENGER_TRANSPORT_MAIN_DSN: doctrine://default - SYLIUS_MESSENGER_TRANSPORT_MAIN_FAILED_DSN: doctrine://default?queue_name=main_failed - SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_DSN: doctrine://default?queue_name=catalog_promotion_removal - SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_FAILED_DSN: doctrine://default?queue_name=catalog_promotion_removal_failed - PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC} - 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 - - ./public/media:/srv/sylius/public/media:rw - networks: - - sylius - - cron: - container_name: cron - build: - context: . - target: sylius_cron - depends_on: - - migrations - environment: - APP_ENV: prod - APP_DEBUG: 0 - APP_SECRET: EDITME - DATABASE_URL: mysql://sylius:${MYSQL_PASSWORD}@mysql/sylius_prod - 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"] - restart: always - build: - context: . - target: sylius_php_prod - depends_on: - - migrations - environment: - APP_ENV: prod - APP_DEBUG: 0 - APP_SECRET: EDITME - DATABASE_URL: mysql://sylius:${MYSQL_PASSWORD}@mysql/sylius_prod - MESSENGER_TRANSPORT_DSN: doctrine://default - SYLIUS_MESSENGER_TRANSPORT_MAIN_DSN: doctrine://default - SYLIUS_MESSENGER_TRANSPORT_MAIN_FAILED_DSN: doctrine://default?queue_name=main_failed - SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_DSN: doctrine://default?queue_name=catalog_promotion_removal - SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_FAILED_DSN: doctrine://default?queue_name=catalog_promotion_removal_failed - PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC} - 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 - image: mysql:5.7 # Sylius is fully working on mysql 8.0 version - environment: - MYSQL_RANDOM_ROOT_PASSWORD: true - MYSQL_DATABASE: sylius_prod - 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 - networks: - - sylius - - nginx: - container_name: nginx - # in production, we may want to use a static website hosting service - build: - context: . - target: sylius_nginx - depends_on: - - php - volumes: - # use a bind-mounted host directory, as we want to keep the media - - ./public/media:/srv/sylius/public/media:ro - networks: - - sylius - ports: - - 80:80 - -networks: - sylius: - driver: bridge diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index ddcdec2930..0000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,104 +0,0 @@ -services: - php: - container_name: php - build: - context: . - target: sylius_php_dev - depends_on: - - migrations - environment: - - APP_ENV=dev - - APP_DEBUG=1 - - APP_SECRET=EDITME - - DATABASE_URL=mysql://sylius:${MYSQL_PASSWORD:-nopassword}@mysql/sylius - - MAILER_DSN=smtp://mailhog:1025 - - PHP_DATE_TIMEZONE=${PHP_DATE_TIMEZONE:-UTC} - volumes: - - .:/srv/sylius:rw,cached - # if you develop on Linux, you may use a bind-mounted host directory instead - # - ./var:/srv/sylius/var:rw - - ./public:/srv/sylius/public:rw,delegated - # if you develop on Linux, you may use a bind-mounted host directory instead - # - ./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 - platform: linux/amd64 - environment: - - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-nopassword} - - MYSQL_DATABASE=sylius - - 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: - - "${MYSQL_PORT:-3306}:3306" - cap_add: - - SYS_NICE # prevent "mbind: Operation not permitted" errors - - node: - container_name: node - build: - context: . - target: sylius_node - command: ["yarn", "watch"] - depends_on: - - php - environment: - - GULP_ENV=dev - - PHP_HOST=php - - PHP_PORT=9000 - volumes: - - .:/srv/sylius:rw,cached - - ./public:/srv/sylius/public:rw,delegated - ports: - - "${NODE_PORT:-35729}:35729" - - nginx: - container_name: nginx - build: - context: . - target: sylius_nginx - depends_on: - - php - - node # to ensure correct build order - volumes: - - ./public:/srv/sylius/public:ro - # if you develop on Linux, you may use a bind-mounted host directory instead - # - ./public/media:/srv/sylius/public/media:ro - - public-media:/srv/sylius/public/media:ro,nocopy - ports: - - "${HTTP_PORT:-80}:80" - - mailhog: - # do not use in production! - image: mailhog/mailhog:latest - environment: - - MH_STORAGE=maildir - # volumes: - # - ./docker/mailhog/maildir:/maildir:rw,delegated - ports: - - "${MAILHOG_PORT:-8025}:8025" - -volumes: - mysql-data: - public-media: diff --git a/docker/cron/crontab b/docker/cron/crontab deleted file mode 100644 index c8fe77b70a..0000000000 --- a/docker/cron/crontab +++ /dev/null @@ -1,2 +0,0 @@ -* * * * * php /srv/sylius/bin/console sylius:remove-expired-carts -* * * * * php /srv/sylius/bin/console sylius:cancel-unpaid-orders diff --git a/docker/cron/docker-entrypoint.sh b/docker/cron/docker-entrypoint.sh deleted file mode 100755 index 360a4f9de5..0000000000 --- a/docker/cron/docker-entrypoint.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -set -e - -while ping -c1 migrations >/dev/null 2>&1; -do - (>&2 echo "Waiting for Migrations container to finish") - sleep 1; -done; - -(>&2 echo "Migrations container finished. Starting Cron process.") - -exec docker-php-entrypoint "$@" diff --git a/docker/migrations/docker-entrypoint.sh b/docker/migrations/docker-entrypoint.sh deleted file mode 100755 index 6f3311c340..0000000000 --- a/docker/migrations/docker-entrypoint.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/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 diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf deleted file mode 100644 index c2565c79de..0000000000 --- a/docker/nginx/conf.d/default.conf +++ /dev/null @@ -1,43 +0,0 @@ -server { - root /srv/sylius/public; - listen *:80; - - location / { - # try to serve file directly, fallback to index.php - try_files $uri /index.php$is_args$args; - } - - location ~ ^/index\.php(/|$) { - resolver 127.0.0.11 valid=10s ipv6=off; - set $backendfpm "php:9000"; - # Comment the next line and uncomment the next to enable dynamic resolution (incompatible with Kubernetes); - fastcgi_pass $backendfpm; - #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/index.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; - } - - client_max_body_size 6m; -} diff --git a/docker/node/docker-entrypoint.sh b/docker/node/docker-entrypoint.sh deleted file mode 100755 index ecd73af806..0000000000 --- a/docker/node/docker-entrypoint.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/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/dev/opcache.ini b/docker/php/dev/opcache.ini deleted file mode 100644 index b6a356a8ef..0000000000 --- a/docker/php/dev/opcache.ini +++ /dev/null @@ -1,10 +0,0 @@ -[opcache] -opcache.enable=1 -opcache.enable_cli=1 -opcache.memory_consumption=256 -opcache.max_accelerated_files=20000 -opcache.validate_timestamps=1 -opcache.revalidate_freq=0 -opcache.jit=1255 -opcache.jit_buffer_size=128M -opcache.interned_strings_buffer=16 diff --git a/docker/php/dev/php.ini b/docker/php/dev/php.ini deleted file mode 100644 index fc1acf94ae..0000000000 --- a/docker/php/dev/php.ini +++ /dev/null @@ -1,7 +0,0 @@ -memory_limit=3G -post_max_size=6M -upload_max_filesize=5M -realpath_cache_size=4096K -realpath_cache_ttl=600 - -date.timezone=${PHP_DATE_TIMEZONE} diff --git a/docker/php/docker-entrypoint.sh b/docker/php/docker-entrypoint.sh deleted file mode 100755 index 54b400a019..0000000000 --- a/docker/php/docker-entrypoint.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/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/log var/sessions public/media - setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var public/media - setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var public/media - - if [ "$APP_ENV" != 'prod' ]; then - composer install --prefer-dist --no-progress --no-interaction - bin/console assets:install --no-interaction - bin/console sylius:theme:assets:install public --no-interaction - fi - - 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 "$@" diff --git a/docker/php/prod/opcache.ini b/docker/php/prod/opcache.ini deleted file mode 100644 index 58be9e0bce..0000000000 --- a/docker/php/prod/opcache.ini +++ /dev/null @@ -1,9 +0,0 @@ -[opcache] -opcache.enable=1 -opcache.enable_cli=1 -opcache.memory_consumption=256 -opcache.max_accelerated_files=20000 -opcache.validate_timestamps=0 -opcache.jit=1255 -opcache.jit_buffer_size=128M -opcache.interned_strings_buffer=16 diff --git a/docker/php/prod/php.ini b/docker/php/prod/php.ini deleted file mode 100644 index 31170a769d..0000000000 --- a/docker/php/prod/php.ini +++ /dev/null @@ -1,7 +0,0 @@ -memory_limit=256M -post_max_size=6M -upload_max_filesize=5M -realpath_cache_size=4096K -realpath_cache_ttl=600 - -date.timezone=${PHP_DATE_TIMEZONE} diff --git a/docker/test.sh b/docker/test.sh deleted file mode 100755 index 29dddcba88..0000000000 --- a/docker/test.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -set -e - -readonly timeout=100 -readonly sleep_time=5 - -i=1 -time=$((timeout * sleep_time)) - -until curl -L --fail http://localhost:80 2>/dev/null -do - i=$((i+1)) - - if [ "${i}" -gt "${timeout}" ]; then - - echo "Sylius Store was never created, aborting due to ${time}s timeout!" - curl -L http://localhost:80 -H Accept:application/json - exit 1 - else - echo "Sylius Store did not response" - fi - - sleep $sleep_time -done