-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
104 lines (79 loc) · 4.05 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# This Makefile is designed to be included by another Makefile located in your project directory.
# ==> https://github.com/EmakinaFR/docker-magento2/wiki/Makefile
SHELL := /bin/bash
PHP_SERVICE := docker compose exec -u www-data:www-data php bash -c
# Define a dynamic project name that will be prepended to each service name
export COMPOSE_PROJECT_NAME := magento2_$(shell echo $$(basename $$(pwd)) | tr '[:upper:]' '[:lower:]')
# Extract environment variables needed by the environment
export PROJECT_LOCATION := $(shell echo ${MAKEFILE_DIRECTORY})
export DOCKER_PHP_IMAGE := $(shell grep DOCKER_PHP_IMAGE ${MAKEFILE_DIRECTORY}docker/local/.env | awk -F '=' '{print $$NF}')
export DOCKER_MYSQL_IMAGE := $(shell grep DOCKER_MYSQL_IMAGE ${MAKEFILE_DIRECTORY}docker/local/.env | awk -F '=' '{print $$NF}')
export DOCKER_ELASTICSEARCH_IMAGE := $(shell grep DOCKER_ELASTICSEARCH_IMAGE ${MAKEFILE_DIRECTORY}docker/local/.env | awk -F '=' '{print $$NF}')
export DOCKER_REDIS_IMAGE := $(shell grep DOCKER_REDIS_IMAGE ${MAKEFILE_DIRECTORY}docker/local/.env | awk -F '=' '{print $$NF}')
##
## ----------------------------------------------------------------------------
## Environment
## ----------------------------------------------------------------------------
##
backup: ## Backup the "mysql" volume
docker run --rm \
--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
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"
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
logs-full: ## Follow logs generated by all containers from the containers creation
docker compose logs -f
mysql: ## Open a terminal in the "mysql" container
docker compose exec mysql bash
nginx: ## Open a terminal in the "nginx" container
docker compose exec -u nginx:nginx nginx bash -l
php: ## Open a terminal in the "php" container
docker compose exec -u www-data:www-data php bash -l
ps: ## List all containers managed by the environment
docker compose ps
purge: ## Purge all services, associated volumes
docker compose down --volumes
redis: ## Open a terminal in the "redis" container
docker compose exec redis sh
restart: stop start ## Restart the environment
restore: ## Restore the "mysql" volume
docker run --rm \
--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
root: ## Display the commands to set up the environment for an advanced usage
@echo "export COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}"
@echo "export COMPOSE_FILE=${COMPOSE_FILE}"
@echo "export PROJECT_LOCATION=${PROJECT_LOCATION}"
@echo "export DOCKER_PHP_IMAGE=${DOCKER_PHP_IMAGE}"
@echo "export DOCKER_MYSQL_IMAGE=${DOCKER_MYSQL_IMAGE}"
@echo "export DOCKER_ELASTICSEARCH_IMAGE=${DOCKER_ELASTICSEARCH_IMAGE}"
@echo "export DOCKER_REDIS_IMAGE=${DOCKER_REDIS_IMAGE}"
@echo ""
@echo "# Run this command to configure your shell:"
@echo "# eval \$$(make root)"
start: ## Start the environment
@docker compose up --detach --remove-orphans
stats: ## Print real-time statistics about containers ressources usage
docker stats $(docker ps --format={{.Names}})
stop: ## Stop the environment
@docker compose stop
yarn: ## Install Composer dependencies from the "php" container
$(PHP_SERVICE) "yarn install --cwd=/var/www/html"
.PHONY: backup build cache composer logs logs-full mysql nginx php ps purge restart restore root start stats stop yarn
.DEFAULT_GOAL := help
help:
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) \
| sed -e 's/^.*Makefile://g' \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' \
| sed -e 's/\[32m##/[33m/'
.PHONY: help