-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (109 loc) · 4.09 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
TAG ?= $(shell git rev-parse --abbrev-ref HEAD)
# Public targets
.PHONY: init
init:
@echo "Initializing the environment"
$(MAKE) .networks-init
$(MAKE) .proxy-deploy
@echo "Environment initialized"
.PHONY: destroy
destroy:
@echo "Destroying the environment"
$(MAKE) destroy-stages
$(MAKE) .proxy-destroy
$(MAKE) .networks-destroy
@echo "Environment destroyed"
.PHONY: deploy-stage
deploy-stage:
@echo "Deploying the ${TAG} stage"
$(MAKE) .feature-branch-deploy
@echo "Stage ${TAG} deployed"
.PHONY: destroy-stages
destroy-stages:
@echo "Destroying all stages"
@docker container ls --filter "label=stage" --format="{{.Labels}}" | sed -un "s/^.*stage=\([^,]*\).*$$/\1/p" | xargs --no-run-if-empty -L1 -I {} $(MAKE) destroy-stage TAG={}
@echo "All stages destroyed"
.PHONY: destroy-stage
destroy-stage:
@echo "Destroying the ${TAG} stage"
$(MAKE) .feature-branch-destroy
@echo "Stage ${TAG} destroyed"
# Networks
.PHONY: .networks-init
.networks-init:
@echo "Initializing networks"
-@docker network create proxy
@echo "Networks initialized"
.PHONY: .networks-destroy
.networks-destroy:
@echo "Destroying networks"
@docker network remove proxy
@echo "Networks destroyed"
# Proxy
.PHONY: .proxy-deploy
.proxy-deploy:
@echo "Deploying the proxy"
$(MAKE) .proxy-build-images
$(MAKE) .proxy-push-images
$(MAKE) .proxy-start
@echo "Proxy deployed"
.PHONY: .proxy-build-images
.proxy-build-images:
@echo "Building proxy's Docker images"
@docker-compose -f proxy/docker-compose.yaml build
.PHONY: .proxy-push-images
.proxy-push-images:
@echo "Pushing proxy's Docker images"
.PHONY: .proxy-start
.proxy-start:
@echo "Starting proxy's stack"
@docker-compose -f proxy/docker-compose.yaml up -d
.PHONY: .proxy-destroy
.proxy-destroy:
@docker-compose -f proxy/docker-compose.yaml down
# Code
.PHONY: .feature-branch-deploy
.feature-branch-deploy:
@echo "Deploying the '${TAG}' feature branch"
$(MAKE) .feature-branch-init-environment-variables
$(MAKE) .feature-branch-build-images
$(MAKE) .feature-branch-push-images
$(MAKE) .feature-branch-start
$(MAKE) .feature-branch-database-init
$(MAKE) .feature-branch-database-migrations
$(MAKE) .feature-branch-database-load-fixtures
@echo "Feature branch '${TAG}' deployed"
.PHONY: .feature-branch-init-environment-variables # out of the scope of the demo
.feature-branch-init-environment-variables:
@echo "Initializing environment variables"
.PHONY: .feature-branch-build-images
.feature-branch-build-images:
@echo "Building feature branch's Docker images"
@export TAG=$(TAG) && docker-compose -f code/docker-compose.yaml -p $(TAG) build
.PHONY: .feature-branch-push-images # out of the scope of the demo
.feature-branch-push-images:
@echo "Pushing feature branch's Docker images"
.PHONY: .feature-branch-start
.feature-branch-start:
@echo "Starting feature branch's stack"
@export TAG=$(TAG) && docker-compose -f code/docker-compose.yaml -p $(TAG) up -d
.PHONY: .feature-branch-database-init
.feature-branch-database-init:
@echo "Initializing the feature branch's database"
@export TAG=$(TAG) && docker-compose -f code/docker-compose.yaml -p $(TAG) exec php bin/console doctrine:database:create --if-not-exists --no-interaction --quiet
@echo "Feature branch's database initialized"
.PHONY: .feature-branch-database-migrations
.feature-branch-database-migrations:
@echo "Executing migrations on the feature branch's database"
@export TAG=$(TAG) && docker-compose -f code/docker-compose.yaml -p $(TAG) exec php bin/console doctrine:migrations:migrate --no-interaction --quiet
@echo "Feature branch's migrations executed"
.PHONY: .feature-branch-database-load-fixtures
.feature-branch-database-load-fixtures:
@echo "Loading fixtures on the feature branch's database"
@export TAG=$(TAG) && docker-compose -f code/docker-compose.yaml -p $(TAG) exec php bin/console doctrine:fixtures:load --no-interaction --quiet
@echo "Feature branch's fixtures loaded"
.PHONY: .feature-branch-destroy
.feature-branch-destroy:
@echo "Destroying the ${TAG} feature branch's stack"
@export TAG=$(TAG) && docker-compose -f code/docker-compose.yaml -p $(TAG) down
@echo "${TAG} feature branch's destroyed"