-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (57 loc) · 2.17 KB
/
Copy pathMakefile
File metadata and controls
77 lines (57 loc) · 2.17 KB
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
COMPOSE_RUN_TERRAFORM = docker-compose run --rm tf
COMPOSE_RUN_BASH = docker-compose run --rm --entrypoint bash tf
COMPOSE_RUN_AWS = docker-compose run --rm --entrypoint aws tf
# GETACCOUNTID = $(shell sh -c "aws sts get-caller-identity --output text --query 'Account'")
# GETREGION = $(shell sh -c "aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]'")
#GETURI = $(IMAGEFULLNAME=$(GETACCOUNTID).dkr.ecr.ap-southeast-2.amazonaws.com/ccr-weather-app:1)
IMAGEFULLNAME = $(AWS_ACCOUNT_ID).dkr.ecr.ap-southeast-2.amazonaws.com/ccr-weather-app:1
.PHONY: run_plan
run_plan: init plan
.PHONY: run_apply
run_apply: init apply
.PHONY: run_destroy_plan
run_destroy_plan: init destroy_plan
.PHONY: run_destroy_apply
run_destroy_apply: init destroy_apply
.PHONY: docker_workflow
docker_workflow: login build push
.PHONY: set_vars
set_vars:
@eval $(GETURI)
$(shell echo $(IMAGEFULLNAME))
.PHONY: version
version:
$(COMPOSE_RUN_TERRAFORM) --version
.PHONY: init
init:
$(COMPOSE_RUN_TERRAFORM) init -input=false
-$(COMPOSE_RUN_TERRAFORM) validate
-$(COMPOSE_RUN_TERRAFORM) fmt
.PHONY: plan
plan:
$(COMPOSE_RUN_TERRAFORM) plan -out=tfplan -input=false -var="image_uri=$(IMAGEFULLNAME)"
.PHONY: apply
apply:
$(COMPOSE_RUN_TERRAFORM) apply "tfplan"
.PHONY: destroy_plan
destroy_plan:
$(COMPOSE_RUN_TERRAFORM) plan -destroy
.PHONY: destroy_apply
destroy_apply:
$(COMPOSE_RUN_TERRAFORM) destroy -auto-approve
.PHONY: build
build:
@echo "Building image with tag ${IMAGEFULLNAME}"
@docker build -t ${IMAGEFULLNAME} -f ./weather-app.dockerfile .
.PHONY: push
push:
@echo "Pushing image with tag ${IMAGEFULLNAME} to DockerHub"
@docker image push ${IMAGEFULLNAME}
.PHONY: login
login:
@echo "Logging into ECR with provided credentials"
@printf ${ECR_PW} | docker login -u AWS \
--password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.ap-southeast-2.amazonaws.com
#@docker login -u AWS -p $(aws ecr get-login-password --region ap-southeast-2) $(AWS_ACCOUNT_ID).dkr.ecr.ap-southeast-2.amazonaws.com
# $(COMPOSE_RUN_AWS) ecr get-login-password --region ap-southeast-2 | docker login -u AWS \
# --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.ap-southeast-2.amazonaws.com