Skip to content

Commit

Permalink
Add new Docker concept (#935)
Browse files Browse the repository at this point in the history
The new concept allows to setup environment with just one command 🚀 

```bash
make init # initialize Sylius installation with required dependencies

ENV=test make run # to change the environment to test

make debug # to run php container with xDebug + mailhog
```



### Requirements
- Docker
- Makefile

### used dependencies 
- https://github.com/sylius/docker-images - ready to use Sylius images
- https://github.com/boxboat/fixuid - fixes user ID between local
machine and docker container (required for Linux)
  • Loading branch information
jakubtobiasz authored Mar 25, 2024
2 parents 0051c3c + 37312e3 commit ceb354c
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 406 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

/docker-compose.override.yaml
/docker-compose.override.yml
/compose.override.yaml
/compose.override.yml
/docker/mysql/data/

###> symfony/framework-bundle ###
Expand Down Expand Up @@ -46,4 +48,5 @@
/npm-debug.log
/yarn-error.log
/yarn.lock
/package-lock.json
###< symfony/webpack-encore-bundle ###
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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"
71 changes: 71 additions & 0 deletions compose.override.dist.yml
Original file line number Diff line number Diff line change
@@ -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:
20 changes: 20 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -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
118 changes: 0 additions & 118 deletions docker-compose.prod.yml

This file was deleted.

104 changes: 0 additions & 104 deletions docker-compose.yml

This file was deleted.

2 changes: 0 additions & 2 deletions docker/cron/crontab

This file was deleted.

12 changes: 0 additions & 12 deletions docker/cron/docker-entrypoint.sh

This file was deleted.

Loading

0 comments on commit ceb354c

Please sign in to comment.