-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (119 loc) · 4.32 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
###########
### App ###
###########
app-build:
@mvn --batch-mode -T 1C install -DskipTests -DskipITs -Dspring.profiles.active=ci -pl app
app-test:
@mvn --batch-mode -T 1C surefire:test -DskipITs
app-integration-test:
@mvn --batch-mode -T 1C failsafe:integration-test
@mvn --batch-mode -T 1C failsafe:verify
app-verify: app-test app-integration-test
app-container: app-build
$(MAKE) container \
IMAGE_URI=216862985054.dkr.ecr.eu-central-1.amazonaws.com/sama-service \
IMAGE=sama-service \
SOURCE=app/
app-upload-to-ecr:
$(MAKE) upload-to-ecr \
IMAGE_URI=216862985054.dkr.ecr.eu-central-1.amazonaws.com/sama-service \
IMAGE=sama-service \
VERSION=$(VERSION)
app-tag-ecr-image:
$(MAKE) tag-ecr-image IMAGE=sama-service TAG=$(BUILD_VERSION) NEW_TAG=$(VERSION)
#################
### Webserver ###
#################
webserver-container:
$(MAKE) container \
IMAGE_URI=216862985054.dkr.ecr.eu-central-1.amazonaws.com/sama-webserver \
IMAGE=sama-webserver \
SOURCE=webserver/
webserver-upload-to-ecr:
$(MAKE) upload-to-ecr \
IMAGE_URI=216862985054.dkr.ecr.eu-central-1.amazonaws.com/sama-webserver \
IMAGE=sama-webserver \
VERSION=$(VERSION)
webserver-tag-ecr-image:
$(MAKE) tag-ecr-image IMAGE=sama-webserver TAG=$(BUILD_VERSION) NEW_TAG=$(VERSION)
##################
### Versioning ###
##################
version:
@echo -n "b-" && git rev-parse --short HEAD
##############
### Docker ###
##############
container:
docker build -t $(IMAGE) $(SOURCE)
tag-ecr-image:
@echo "Tagging $(IMAGE):$(TAG) with $(NEW_TAG)"
@aws ecr batch-get-image --repository-name $(IMAGE) --image-ids imageTag=$(TAG) --query 'images[].imageManifest' --output text > manifest.json
@aws ecr put-image --repository-name $(IMAGE) --image-tag $(NEW_TAG) --image-manifest file://manifest.json
@rm manifest.json
upload-to-ecr:
docker tag $(IMAGE):latest $(IMAGE_URI):$(VERSION)
docker push $(IMAGE_URI):$(VERSION)
######################
### Deployment ECS ###
######################
ecs-terraform-init:
@terraform -chdir=infra/ecs/terraform init -input=false
@terraform -chdir=infra/ecs/terraform workspace new $(ENV) ||:
ecs-terraform-validate:
terraform -chdir=infra/ecs/terraform fmt -check
ecs-update-infra:
@terraform -chdir=infra/ecs/terraform workspace select $(ENV)
terraform -chdir=infra/ecs/terraform apply -auto-approve
ecs-pull-task-definition:
aws ecs describe-task-definition \
--task-definition sama-service-$(ENV) \
--query taskDefinition > task-definition.json
######################
### Deployment EC2 ###
######################
terraform-init:
@terraform -chdir=infra/ec2/terraform init -input=false
@terraform -chdir=infra/ec2/terraform workspace new $(ENV) ||:
terraform-validate:
terraform -chdir=infra/ec2/terraform fmt -check
current-deployment:
@terraform -chdir=infra/ec2/terraform workspace select $(ENV) > /dev/null
@terraform -chdir=infra/ec2/terraform show -json | \
jq -r '.values.root_module.resources[] | select (.type == "aws_lb_listener_rule") | .values.action[].forward[].target_group[] | select (.weight == 100) | .arn' | \
grep -o -P '(?<=sama-service-).*(?=-tg-$(ENV))'
deploy:
@terraform -chdir=infra/ec2/terraform workspace select $(ENV)
terraform -chdir=infra/ec2/terraform apply -auto-approve \
-var 'enable_green_env=true' \
-var 'enable_blue_env=true' \
-var 'traffic_distribution=split'
destroy-blue:
@terraform -chdir=infra/ec2/terraform workspace select $(ENV)
terraform -chdir=infra/ec2/terraform apply -auto-approve \
-var 'enable_green_env=true' \
-var 'enable_blue_env=false' \
-var 'traffic_distribution=green'
destroy-green:
@terraform -chdir=infra/ec2/terraform workspace select $(ENV)
terraform -chdir=infra/ec2/terraform apply -auto-approve \
-var 'enable_green_env=false' \
-var 'enable_blue_env=true' \
-var 'traffic_distribution=blue'
#################
### Liquibase ###
#################
liquibase-run:
$(MAKE) liquibase-$(ENV) CMD='update'
liquibase-rollback:
$(MAKE) liquibase-$(ENV) CMD='rollback -Dliquibase.rollbackCount=1'
liquibase-local:
$(MAKE) liquibase-cmd ENV=local
liquibase-dev:
@ssh -i $(PATH_TO_PK) -fT -L 15432:$(DB_URI) ubuntu@$(BASTION_IP) sleep 30
$(MAKE) liquibase-cmd ENV=dev
liquibase-prod:
@ssh -i $(PATH_TO_PK) -fT -L 15432:$(DB_URI) ubuntu@$(BASTION_IP) sleep 30
$(MAKE) liquibase-cmd ENV=prod
liquibase-cmd:
@mvn liquibase:$(CMD) -Denv=$(ENV) -pl app