Skip to content

Commit

Permalink
Merge pull request #75 from EmakinaFR/feature/compose
Browse files Browse the repository at this point in the history
  • Loading branch information
duboiss authored Nov 8, 2021
2 parents 976711a + 6c8e619 commit fd12b2d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ==> https://github.com/EmakinaFR/docker-magento2/wiki/Makefile

SHELL := /bin/bash
PHP_SERVICE := docker-compose exec -u www-data:www-data php sh -c
PHP_SERVICE := docker compose exec -u www-data:www-data php sh -c

# Define a dynamic project name that will be prepended to each service name
export COMPOSE_PROJECT_NAME := magento2_$(shell echo $${PWD\#\#*/} | tr '[:upper:]' '[:lower:]')
Expand All @@ -22,50 +22,50 @@ export DOCKER_REDIS_IMAGE := $(shell grep DOCKER_REDIS_IMAGE ${MAKEFILE_DIRECTOR

backup: ## Backup the "mysql" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q mysql) \
--volumes-from $$(docker compose ps -q mysql) \
--volume $$(pwd):/backup \
busybox sh -c "tar cvf /backup/backup.tar /var/lib/mysql"

build: ## Build the environment
docker-compose build --pull
docker compose build --pull

cache: ## Flush cache stored in Redis
docker-compose exec redis sh -c "redis-cli -n 1 FLUSHDB"
docker-compose exec redis sh -c "redis-cli -n 2 FLUSHDB"
docker compose exec redis sh -c "redis-cli -n 1 FLUSHDB"
docker compose exec redis sh -c "redis-cli -n 2 FLUSHDB"

composer: ## Install Composer dependencies from the "php" container
$(PHP_SERVICE) "composer install --optimize-autoloader --prefer-dist --working-dir=/var/www/html"

logs: ## Follow logs generated by all containers
docker-compose logs -f --tail=0
docker compose logs -f --tail=0

logs-full: ## Follow logs generated by all containers from the containers creation
docker-compose logs -f
docker compose logs -f

mysql: ## Open a terminal in the "mysql" container
docker-compose exec mysql sh
docker compose exec mysql sh

nginx: ## Open a terminal in the "nginx" container
docker-compose exec -u nginx:nginx nginx sh -l
docker compose exec -u nginx:nginx nginx sh -l

php: ## Open a terminal in the "php" container
docker-compose exec -u www-data:www-data php sh -l
docker compose exec -u www-data:www-data php sh -l

ps: ## List all containers managed by the environment
docker-compose ps
docker compose ps

purge: ## Purge all services, associated volumes and the Mutagen session
docker-compose down --volumes
docker compose down --volumes
mutagen sync terminate --label-selector='name==${COMPOSE_PROJECT_NAME}'

restart: stop start ## Restart the environment

restore: ## Restore the "mysql" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q mysql) \
--volumes-from $$(docker compose ps -q mysql) \
--volume $$(pwd):/backup \
busybox sh -c "tar xvf /backup/backup.tar var/lib/mysql/"
docker-compose restart mysql
docker compose restart mysql

root: ## Display the commands to set up the environment for an advanced usage
@echo "export COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}"
Expand All @@ -80,7 +80,7 @@ root: ## Display the commands to set up the environment for an advanced usage
@echo "# eval \$$(make root)"

start: ## Start the environment
@docker-compose up --detach --remove-orphans
@docker compose up --detach --remove-orphans

@if [[ ! "$$(mutagen sync list --label-selector='name==${COMPOSE_PROJECT_NAME}')" =~ "${COMPOSE_PROJECT_NAME}" ]]; then \
mutagen sync create \
Expand All @@ -98,7 +98,7 @@ start: ## Start the environment
fi

@echo "Fixing permissions on the shared SSH agent..."
@docker-compose exec -T php bash -c "chown www-data:www-data /run/host-services/ssh-auth.sock"
@docker compose exec -T php bash -c "chown www-data:www-data /run/host-services/ssh-auth.sock"

@while [[ ! "$$(mutagen sync list --label-selector='name==${COMPOSE_PROJECT_NAME}')" =~ "Status: Watching for changes" ]]; do \
echo "Waiting for synchronization to complete..."; \
Expand All @@ -109,7 +109,7 @@ stats: ## Print real-time statistics about containers ressources usage
docker stats $(docker ps --format={{.Names}})

stop: ## Stop the environment
@docker-compose stop
@docker compose stop
@mutagen sync pause --label-selector='name==${COMPOSE_PROJECT_NAME}'

yarn: ## Install Composer dependencies from the "php" container
Expand Down

0 comments on commit fd12b2d

Please sign in to comment.