Skip to content

Commit

Permalink
[Docker] Add docker support for Sylius 2.0 (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoResponseMate authored Jan 24, 2025
2 parents e1dc070 + a0ab182 commit 8d3b1ed
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 115 deletions.
48 changes: 0 additions & 48 deletions .docker/nginx/nginx.conf

This file was deleted.

5 changes: 0 additions & 5 deletions .docker/php/php.ini

This file was deleted.

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
**/.github
**/.gitignore
**/.gitkeep
**/.gitmodules
**/.idea
**/Dockerfile
**/Thumbs.db
**/docker-compose*.yaml
**/docker-compose*.yml
.editorconfig
.php_cs.cache
.travis.yml
composer.phar
docker/mysql/data/
etc/build/*
node_modules/
var/*
vendor/
public/assets/
public/build/
public/bundles/
public/css/
public/js/
public/media/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/behat.yml
/phpspec.yml
/phpunit.xml
/compose.override.yml
.phpunit.result.cache

# Symfony CLI https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project
Expand Down
56 changes: 36 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
phpunit:
vendor/bin/phpunit
.PHONY: run

phpspec:
vendor/bin/phpspec run --ansi --no-interaction -f dot
DOCKER_COMPOSE ?= docker compose
DOCKER_USER ?= "$(shell id -u):$(shell id -g)"
ENV ?= "dev"

phpstan:
vendor/bin/phpstan analyse
init:
@make -s docker-compose-check
@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
@ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) $(DOCKER_COMPOSE) up -d

behat:
APP_ENV=test vendor/bin/behat --colors --strict --no-interaction -vvv -f progress
run:
@make -s up

install:
composer install --no-interaction --no-scripts
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

backend:
tests/Application/bin/console sylius:install --no-interaction
tests/Application/bin/console sylius:fixtures:load default --no-interaction
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

frontend:
(cd tests/Application && yarn install --pure-lockfile)
(cd tests/Application && GULP_ENV=prod yarn build)
clean:
@ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) $(DOCKER_COMPOSE) down -v

init: install backend frontend
php-shell:
@ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) $(DOCKER_COMPOSE) exec php sh

ci: init phpstan phpunit phpspec behat
node-shell:
@ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) $(DOCKER_COMPOSE) run --rm -i nodejs sh

integration: init phpunit behat
node-watch:
@ENV=$(ENV) DOCKER_USER=$(DOCKER_USER) $(DOCKER_COMPOSE) run --rm -i nodejs "npm run watch"

static: install phpspec phpstan
docker-compose-check:
@$(DOCKER_COMPOSE) version >/dev/null 2>&1 || (echo "Please install docker compose binary or set DOCKER_COMPOSE=\"docker-compose\" for legacy binary" && exit 1)
@echo "You are using \"$(DOCKER_COMPOSE)\" binary"
@echo "Current version is \"$$($(DOCKER_COMPOSE) version)\""
72 changes: 72 additions & 0 deletions compose.override.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
services:
php:
image: ghcr.io/sylius/sylius-php:8.3-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_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
SYLIUS_MESSENGER_TRANSPORT_PAYMENT_REQUEST_DSN: sync://
SYLIUS_MESSENGER_TRANSPORT_PAYMENT_REQUEST_FAILED_DSN: sync://
PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC}
XDEBUG_MODE: debug
XDEBUG_CONFIG: >-
client_host=host.docker.internal
client_port=9003
# 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:
- "3306:3306"
nginx:
environment:
WORKING_DIR: /srv/sylius/tests/Application
volumes:
- .:/srv/sylius:ro
# if you develop on Linux, you may use a bind-mounted host directory instead
# - ./public/media:/srv/sylius/public/media:ro
ports:
- "80:80"
nodejs:
image: node:${NODE_VERSION:-22}-alpine
user: ${DOCKER_USER:-1000:1000}
working_dir: /srv/sylius
entrypoint: [ "/bin/sh","-c" ]
command:
- |
cd tests/Application
yarn install
yarn build
volumes:
- .:/srv/sylius:rw,cached
- ./public:/srv/sylius/public:rw,delegated
mailhog:
ports:
- "8025:8025"

volumes:
mysql-data:
public-media:
22 changes: 22 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
php:
image: ghcr.io/sylius/sylius-php:8.3-alpine
mysql:
image: mysql:8.4
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
depends_on:
- php
mailhog:
# do not use in production!
image: mailhog/mailhog:latest
42 changes: 0 additions & 42 deletions docker-compose.yml

This file was deleted.

0 comments on commit 8d3b1ed

Please # to comment.