-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
330 lines (296 loc) · 13 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# -----------------------------------------------------------------------------
# MAKEFILE RUNNING COMMAND
# -----------------------------------------------------------------------------
# Author : DevOps Engineer ([email protected])
# License : Apache v2
# -----------------------------------------------------------------------------
# Notes:
# use [TAB] instead [SPACE]
export PATH_APP=`pwd`
export PATH_WORKSPACE="src"
export PATH_SCRIPT="scripts"
export PATH_COMPOSE="."
export PATH_DOCKER="."
export PROJECT_NAME="terraform-infra"
export TF_PATH="terraform/environment/providers/aws/infra"
export TF_CORE="$(TF_PATH)/core"
export TF_RESOURCES="$(TF_PATH)/resources"
export TF_STATE="$(TF_PATH)/tfstate"
export TF_MODULES="terraform/modules/providers/aws"
export CI_REGISTRY ?= $(ARGS).dkr.ecr.ap-southeast-1.amazonaws.com
export CI_PROJECT_PATH ?= devopscorner
export CI_PROJECT_NAME ?= terraform-infra
IMAGE = $(CI_REGISTRY)/${CI_PROJECT_PATH}/${CI_PROJECT_NAME}
DIR = $(shell pwd)
VERSION ?= 1.3.0
export BASE_IMAGE=alpine
export BASE_VERSION=3.16
export ALPINE_VERSION=3.16
export UBUNTU_VERSION=22.04
export CODEBUILD_VERSION=4.0
# =============== #
# GET MODULES #
# =============== #
.PHONY: sub-officials sub-community sub-all codebuild-modules
sub-officials:
@echo "============================================================"
@echo " Task : Get Official Submodules "
@echo " Date/Time : `date` "
@echo "============================================================"
@mkdir -p $(TF_MODULES)/officials
@cd $(PATH_APP) && ./get-officials.sh
sub-community:
@echo "============================================================"
@echo " Task : Get Community Submodules "
@echo " Date/Time : `date` "
@echo "============================================================"
@mkdir -p $(TF_MODULES)/community
@cd $(PATH_APP) && ./get-community.sh
sub-all:
@make sub-officials
@echo ''
@make sub-community
@echo ''
@echo '---'
@echo '- ALL DONE -'
codebuild-modules:
@echo "============================================================"
@echo " Task : Get CodeBuild Modules "
@echo " Date/Time : `date` "
@echo "============================================================"
@./get-modules-codebuild.sh
# ==================== #
# CLONE REPOSITORY #
# ==================== #
.PHONY: git-clone
git-clone:
@echo "============================================================"
@echo " Task : Clone Repository Sources "
@echo " Date/Time : `date` "
@echo "============================================================"
@./git-clone.sh $(SOURCE) $(TARGET)
@echo '- DONE -'
# ============================= #
# BUILD CONTAINER TERRAFORM #
# ============================= #
# ./dockerhub-build.sh Dockerfile [DOCKERHUB_IMAGE_PATH] [alpine|ubuntu|codebuild] [version|latest|tags] [custom-tags]
# ./ecr-build.sh [AWS_ACCOUNT] Dockerfile [ECR_PATH] [alpine|ubuntu|codebuild] [version|latest|tags] [custom-tags]
.PHONY: build-tf-infra build-tf-alpine build-tf-ubuntu build-tf-codebuild
build-tf-infra:
@echo "============================================================"
@echo " Task : Create Container Image Terraform "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-build.sh $(ARGS) Dockerfile.alpine $(CI_PATH) alpine ${ALPINE_VERSION}
@echo '- DONE -'
build-tf-alpine:
@echo "============================================================"
@echo " Task : Create Container Image Terraform Alpine "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-build.sh $(ARGS) Dockerfile.alpine $(CI_PATH) alpine ${ALPINE_VERSION}
@echo '- DONE -'
build-tf-ubuntu:
@echo "============================================================"
@echo " Task : Create Container Image Terraform Ubuntu "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-build.sh $(ARGS) Dockerfile.ubuntu $(CI_PATH) ubuntu ${UBUNTU_VERSION}
@echo '- DONE -'
build-tf-codebuild:
@echo "============================================================"
@echo " Task : Create Container Image Terraform CodeBuild "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-build.sh $(ARGS) Dockerfile.codebuild $(CI_PATH) codebuild ${CODEBUILD_VERSION}
@echo '- DONE -'
# ============================ #
# TAGS CONTAINER TERRAFORM #
# ============================ #
# ./dockerhub-tag.sh [DOCKERHUB_IMAGE_PATH] [alpine|ubuntu|codebuild] [version|latest|tags] [custom-tags]
# ./ecr-tag.sh [AWS_ACCOUNT] [ECR_PATH] [alpine|ubuntu|codebuild] [version|latest|tags] [custom-tags]
.PHONY: tag-tf-infra tag-tf-alpine tag-tf-ubuntu tag-tf-codebuild
tag-tf-infra:
@echo "============================================================"
@echo " Task : Set Tags Image Terraform "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-tag.sh $(ARGS) $(CI_PATH) alpine ${ALPINE_VERSION}
@echo '- DONE -'
tag-tf-alpine:
@echo "============================================================"
@echo " Task : Set Tags Image Terraform Alpine "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-tag.sh $(ARGS) $(CI_PATH) alpine ${ALPINE_VERSION}
@echo '- DONE -'
tag-tf-ubuntu:
@echo "============================================================"
@echo " Task : Set Tags Image Terraform Ubuntu "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-tag.sh $(ARGS) $(CI_PATH) ubuntu ${UBUNTU_VERSION}
@echo '- DONE -'
tag-tf-codebuild:
@echo "============================================================"
@echo " Task : Set Tags Image Terraform CodeBuild "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-tag.sh $(ARGS) $(CI_PATH) codebuild ${CODEBUILD_VERSION}
@echo '- DONE -'
# ============================ #
# PUSH CONTAINER TERRAFORM #
# ============================ #
# ./dockerhub-tag.sh [DOCKERHUB_IMAGE_PATH] [alpine|ubuntu|codebuild] [version|latest|tags] [custom-tags]
# ./ecr-push.sh [AWS_ACCOUNT] [ECR_PATH] [alpine|ubuntu|codebuild|version|latest|tags|custom-tags]
.PHONY: push-tf-infra push-tf-alpine push-tf-ubuntu push-tf-codebuild
push-tf-infra:
@echo "============================================================"
@echo " Task : Push Container Image Terraform "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-push.sh $(ARGS) $(CI_PATH) alpine
@echo '- DONE -'
push-tf-alpine:
@echo "============================================================"
@echo " Task : Push Container Image Terraform Alpine "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-push.sh $(ARGS) $(CI_PATH) alpine
@echo '- DONE -'
push-tf-ubuntu:
@echo "============================================================"
@echo " Task : Push Container Image Terraform Ubuntu "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-push.sh $(ARGS) $(CI_PATH) ubuntu
@echo '- DONE -'
push-tf-codebuild:
@echo "============================================================"
@echo " Task : Push Container Image Terraform CodeBuild "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-push.sh $(ARGS) $(CI_PATH) codebuild
@echo '- DONE -'
# ============================ #
# PULL CONTAINER TERRAFORM #
# ============================ #
# ./ecr-pull.sh [AWS_ACCOUNT] [ECR_PATH] [alpine|ubuntu|codebuild|version|latest|tags|custom-tags]
.PHONY: pull-tf-infra pull-tf-alpine pull-tf-ubuntu pull-tf-codebuild
pull-tf-infra:
@echo "============================================================"
@echo " Task : Pull Container Image Terraform "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-pull.sh $(ARGS) $(CI_PATH) alpine
@echo '- DONE -'
pull-tf-alpine:
@echo "============================================================"
@echo " Task : Pull Container Image Terraform Alpine "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-pull.sh $(ARGS) $(CI_PATH) alpine
@echo '- DONE -'
pull-tf-ubuntu:
@echo "============================================================"
@echo " Task : Pull Container Image Terraform Ubuntu "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-pull.sh $(ARGS) $(CI_PATH) ubuntu
@echo '- DONE -'
pull-tf-codebuild:
@echo "============================================================"
@echo " Task : Pull Container Image Terraform CodeBuild "
@echo " Date/Time : `date` "
@echo "============================================================"
@sh ./ecr-pull.sh $(ARGS) $(CI_PATH) codebuild
@echo '- DONE -'
# =========================== #
# PROVISIONING INFRA CORE #
# =========================== #
.PHONY: tf-core-init tf-core-create-workspace tf-core-select-workspace tf-core-plan tf-core-apply
tf-core-init:
@echo "============================================================"
@echo " Task : Terraform Init "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_CORE) && terraform init $(ARGS)
@echo '- DONE -'
tf-core-create-workspace:
@echo "============================================================"
@echo " Task : Terraform Create Workspace "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_CORE) && terraform workspace new $(ARGS)
@echo '- DONE -'
tf-core-select-workspace:
@echo "============================================================"
@echo " Task : Terraform Select Workspace "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_CORE) && terraform workspace select $(ARGS)
@echo '- DONE -'
tf-core-plan:
@echo "============================================================"
@echo " Task : Terraform Plan Provisioning "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_CORE) && terraform plan $(ARGS)
@echo '- DONE -'
tf-core-apply:
@echo "============================================================"
@echo " Task : Provisioning Terraform "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_CORE) && terraform apply -auto-approve
@echo '- DONE -'
# ================================ #
# PROVISIONING RESOURCES INFRA #
# ================================ #
.PHONY: tf-infra-init tf-infra-create-workspace tf-infra-select-workspace tf-infra-plan tf-infra-apply tf-infra-resource
tf-infra-init:
@echo "============================================================"
@echo " Task : Terraform Init "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_RESOURCES)/$(INFRA_RESOURCES) && terraform init $(ARGS)
@echo '- DONE -'
tf-infra-create-workspace:
@echo "============================================================"
@echo " Task : Terraform Create Workspace "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_RESOURCES)/$(INFRA_RESOURCES) && terraform workspace new $(ARGS)
@echo '- DONE -'
tf-infra-select-workspace:
@echo "============================================================"
@echo " Task : Terraform Select Workspace "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_RESOURCES)/$(INFRA_RESOURCES) && terraform workspace select $(ARGS)
@echo '- DONE -'
tf-infra-plan:
@echo "============================================================"
@echo " Task : Terraform Plan Provisioning "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_RESOURCES)/$(INFRA_RESOURCES) && terraform plan $(ARGS)
@echo '- DONE -'
tf-infra-apply:
@echo "============================================================"
@echo " Task : Provisioning Terraform "
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_RESOURCES)/$(INFRA_RESOURCES) && terraform apply -auto-approve $(ARGS)
@echo '- DONE -'
# =============================== #
# PROVISIONING SPESIFIC INFRA #
# =============================== #
.PHONY: tf-infra-resource
tf-infra-resource:
@echo "============================================================"
@echo " Task : Terraform Command $(ARGS)"
@echo " Date/Time : `date` "
@echo "============================================================"
@cd $(TF_RESOURCES)/$(INFRA_RESOURCES) && terraform $(ARGS)
@echo '- DONE -'