-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (61 loc) · 2.6 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
SELF_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
PHP_SERVICE := docker-compose exec webapp sh -c
# Define a static project name that will be prepended to each service name
export COMPOSE_PROJECT_NAME := symfony
# Create configuration files needed by the environment
SETUP_ENV := $(shell (test -f $(SELF_DIR)/.env || cp $(SELF_DIR)/.env.dist $(SELF_DIR)/.env))
# Extract environment variables needed by the environment
export DB_DIR := $(shell grep DB_DIR $(SELF_DIR)/.env | awk -F '=' '{print $$NF}')
##
## ----------------------------------------------------------------------------
## Environment
## ----------------------------------------------------------------------------
##
backup: ## Backup the "db" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q db) \
-v $(dir $(SELF_DIR))backup:/backup \
busybox sh -c "tar cvf /backup/backup.db.tar $(DB_DIR)"
build: ## Build the environment
docker-compose build
cache: ## Flush the Symfony cache
$(PHP_SERVICE) "bin/console cache:clear"
logs: ## Follow logs generated by all containers + 10 most recent entries.
docker-compose logs -f --tail=10
logs-full: ## Follow logs generated by all containers + 50 most recent entries.
docker-compose logs -f --tail=50
nginx: ## Open a terminal in the "nginx" container
docker-compose exec nginx sh
app: ## Open a terminal in the "app" container
docker-compose exec app sh
db: ## Open a terminal in the "db" container
docker-compose exec db sh
redis: ## Open a terminal in the "redis" container
docker-compose exec redis sh
rabbit: ## Open a terminal in the "rabbitmq" container
docker-compose exec rabbitmq sh
elk: ## Open a terminal in the "elk" container
docker-compose exec elk sh
ps: ## List all containers managed by the environment
docker-compose ps
restore: ## Restore the "db" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q db) \
-v $(dir $(SELF_DIR))backup:/backup \
busybox sh -c "tar xvf /backup/backup.db.tar /var/lib/mysql"
docker-compose restart db
start: ## Start the environment
docker-compose build
docker-compose up -d --remove-orphans
stats: ## Print real-time statistics about containers ressources usage
docker stats $(docker ps --format={{.Names}})
stop: ## Stop the environment
docker-compose stop
.PHONY: backup build cache composer logs logs-full nginx web db redis rabbit elk ps restore start stats stop
.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