-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
221 lines (178 loc) · 5.96 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
.PHONY: testall buildall fullsuitetest
fullsuitetest: buildall testall
buildall: base_buildimage mirror_buildimage multiver_buildimage multiver_config_buildimage multiver_nodirect_buildimage
testall: base_init mirror_init multiver_init multiver_config_init multiver_nodirect_init
################
## Sample App ##
################
.PHONY: plan apply destroy init
plan:
terraform -chdir=./app plan
apply:
terraform -chdir=./app apply -auto-approve
destroy:
terraform -chdir=./app destroy -auto-approve
init:
-rm -rf ./app/terraform.d ./app/.terraform ./app/.terraform.lock.hcl ./app/.terraform.tfstate.lock.info ./app/terraform.tfstate
terraform -chdir=./app init
.PHONY: plan2 apply2 destroy2 init2
plan2:
terraform -chdir=./app2 plan
apply2:
terraform -chdir=./app2 apply -auto-approve
destroy2:
terraform -chdir=./app2 destroy -auto-approve
init2:
-rm -rf ./app2/terraform.d ./app2/.terraform ./app2/.terraform.lock.hcl ./app2/.terraform.tfstate.lock.info ./app2/terraform.tfstate
terraform -chdir=./app2 init
#################
## Build Image ##
#################
BUILD_IMAGE_VERSION := 1.0.0
BUILD_CONTAINER_NAME := mybuildcontainer
BUILD_IMAGE_NAME_BASE := mybuildimage_base
BUILD_IMAGE_NAME_MIRROR := mybuildimage_mirror
BUILD_IMAGE_NAME_MULTIVER := mybuildimage_multiversion_mirror
BUILD_IMAGE_NAME_MULTIVER_CONFIG := mybuildimage_multiversion_config_mirror
BUILD_IMAGE_NAME_MULTIVER_NODIRECT := mybuildimage_multiversion_nodirect_mirror
.PHONY: base_buildimage base_run base_init
base_buildimage:
docker build \
--progress plain \
--tag "$(BUILD_IMAGE_NAME_BASE):$(BUILD_IMAGE_VERSION)" \
--tag "$(BUILD_IMAGE_NAME_BASE):latest" \
--build-arg BUILD_IMAGE_VERSION="$(BUILD_IMAGE_VERSION)" \
--file ./buildimage/Dockerfile_Base \
./buildimage
base_run: force-stop base_buildimage
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_BASE)" \
bash
base_init: force-stop
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_BASE)" \
make init
.PHONY: mirror_buildimage mirror_run mirror_init
mirror_buildimage:
docker build \
--progress plain \
--tag "$(BUILD_IMAGE_NAME_MIRROR):$(BUILD_IMAGE_VERSION)" \
--tag "$(BUILD_IMAGE_NAME_MIRROR):latest" \
--build-arg BUILD_IMAGE_VERSION="$(BUILD_IMAGE_VERSION)" \
--file ./buildimage/Dockerfile_Mirror \
./buildimage
mirror_run: force-stop mirror_buildimage
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MIRROR)" \
bash
mirror_init: force-stop
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MIRROR)" \
make init
.PHONY: multiver_buildimage multiver_run multiver_init
multiver_buildimage:
docker build \
--progress plain \
--tag "$(BUILD_IMAGE_NAME_MULTIVER):$(BUILD_IMAGE_VERSION)" \
--tag "$(BUILD_IMAGE_NAME_MULTIVER):latest" \
--build-arg BUILD_IMAGE_VERSION="$(BUILD_IMAGE_VERSION)" \
--file ./buildimage/Dockerfile_MultiVer \
./buildimage
multiver_run: force-stop multiver_buildimage
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER)" \
bash
multiver_init: force-stop
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER)" \
make init
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER)" \
make init2
.PHONY: multiver_config_buildimage multiver_config_run multiver_config_init
multiver_config_buildimage:
docker build \
--progress plain \
--tag "$(BUILD_IMAGE_NAME_MULTIVER_CONFIG):$(BUILD_IMAGE_VERSION)" \
--tag "$(BUILD_IMAGE_NAME_MULTIVER_CONFIG):latest" \
--build-arg BUILD_IMAGE_VERSION="$(BUILD_IMAGE_VERSION)" \
--file ./buildimage/Dockerfile_MultiVer_Config \
./buildimage
multiver_config_run: force-stop multiver_config_buildimage
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER_CONFIG)" \
bash
multiver_config_init: force-stop
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER_CONFIG)" \
make init
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER_CONFIG)" \
make init2
.PHONY: multiver_nodirect_buildimage multiver_nodirect_run multiver_nodirect_init
multiver_nodirect_buildimage:
docker build \
--progress plain \
--tag "$(BUILD_IMAGE_NAME_MULTIVER_NODIRECT):$(BUILD_IMAGE_VERSION)" \
--tag "$(BUILD_IMAGE_NAME_MULTIVER_NODIRECT):latest" \
--build-arg BUILD_IMAGE_VERSION="$(BUILD_IMAGE_VERSION)" \
--file ./buildimage/Dockerfile_MultiVer_NoDirect \
./buildimage
multiver_nodirect_run: force-stop multiver_nodirect_buildimage
docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER_NODIRECT)" \
bash
multiver_nodirect_init: force-stop
@echo "This configuration is expected to generate an error, which is ignored"
-docker run --rm -ti \
--name "$(BUILD_CONTAINER_NAME)" \
--volume $$(pwd):/root/src \
--workdir /root/src \
"$(BUILD_IMAGE_NAME_MULTIVER_NODIRECT)" \
make init
.PHONY: force-stop
force-stop:
@echo "Attempting to stop running local container, if not shutdown properly."
@echo "Normally this will generate an error, which is ignored"
-docker stop "$(BUILD_CONTAINER_NAME)"
## Cleanup Docker
.PHONY: cleanup
cleanup:
docker container prune -f
docker image prune --all -f
docker volume prune -f
docker network prune -f
docker builder prune --all -f