-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
93 lines (70 loc) · 6.02 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
NETWORK_SOURCE_TEMPLATE_PATH = aws/cloudformation/prerequisites/network/network.yml
GENERATED_NETWORK_TEMPLATE_ABSOLUTE_PATH = $(shell pwd)/dist/$(NETWORK_SOURCE_TEMPLATE_PATH)
STATIC_SOURCE_TEMPLATE_PATH = aws/cloudformation/prerequisites/static/static.yml
GENERATED_STATIC_TEMPLATE_ABSOLUTE_PATH = $(shell pwd)/dist/$(STATIC_SOURCE_TEMPLATE_PATH)
FLAG_SOURCE_TEMPLATE_PATH = aws/cloudformation/challenges/flag.yml
GENERATED_FLAG_TEMPLATE_ABSOLUTE_PATH = $(shell pwd)/dist/$(FLAG_SOURCE_TEMPLATE_PATH)
CHALLENGES_SOURCE_TEMPLATE_PATH = aws/cloudformation/challenges/prodserver.yml
GENERATED_CHALLENGES_TEMPLATE_ABSOLUTE_PATH = $(shell pwd)/dist/$(CHALLENGES_SOURCE_TEMPLATE_PATH)
CHALLENGES_DEVSERVER_SOURCE_TEMPLATE_PATH = aws/cloudformation/challenges/devserver.yml
GENERATED_CHALLENGES_DEVSERVER_TEMPLATE_ABSOLUTE_PATH = $(shell pwd)/dist/$(CHALLENGES_DEVSERVER_SOURCE_TEMPLATE_PATH)
BUCKET_NAME=cf-template-`aws sts get-caller-identity --output text --query 'Account'`-`aws configure get region`
package-network:
aws cloudformation package --template-file $(NETWORK_SOURCE_TEMPLATE_PATH) --s3-bucket $(BUCKET_NAME) --s3-prefix cloudformation/hf-ctf --output-template-file $(GENERATED_NETWORK_TEMPLATE_ABSOLUTE_PATH)
package-ecs:
aws cloudformation package --template-file $(STATIC_SOURCE_TEMPLATE_PATH) --s3-bucket $(BUCKET_NAME) --s3-prefix cloudformation/hf-ctf --output-template-file $(GENERATED_STATIC_TEMPLATE_ABSOLUTE_PATH)
package-challenges:
aws cloudformation package --template-file $(CHALLENGES_SOURCE_TEMPLATE_PATH) --s3-bucket $(BUCKET_NAME) --s3-prefix cloudformation/hf-ctf --output-template-file $(GENERATED_CHALLENGES_TEMPLATE_ABSOLUTE_PATH)
package-flag:
aws cloudformation package --template-file $(FLAG_SOURCE_TEMPLATE_PATH) --s3-bucket $(BUCKET_NAME) --s3-prefix cloudformation/hf-ctf --output-template-file $(GENERATED_FLAG_TEMPLATE_ABSOLUTE_PATH)
package-devserver:
aws cloudformation package --template-file $(CHALLENGES_DEVSERVER_SOURCE_TEMPLATE_PATH) --s3-bucket $(BUCKET_NAME) --s3-prefix cloudformation/hf-ctf --output-template-file $(GENERATED_CHALLENGES_DEVSERVER_TEMPLATE_ABSOLUTE_PATH)
challenges: package-challenges update-challenges clean
aws ssm put-parameter --name 'Flag1' --type "SecureString" --value $(FLAG_1)
aws ssm put-parameter --name 'Flag2' --type "SecureString" --value $(FLAG_2)
aws ssm put-parameter --name 'Flag3' --type "SecureString" --value $(FLAG_3)
aws ssm put-parameter --name 'Flag4' --type "SecureString" --value $(FLAG_4)
aws ssm put-parameter --name 'Flag5' --type "SecureString" --value $(FLAG_5)
aws ssm put-parameter --name 'Flag6' --type "SecureString" --value $(FLAG_6)
aws ssm put-parameter --name 'Flag7' --type "SecureString" --value $(FLAG_7)
aws ssm put-parameter --name 'SecretServerIp' --type "SecureString" --value $(SECRETSERVER_IP)
-aws cloudformation deploy --template-file $(GENERATED_CHALLENGES_TEMPLATE_ABSOLUTE_PATH) --stack-name HF-CTF-Challenges --parameter-overrides DomainName=$(DOMAIN_NAME) Certificate=$(CERTIFICATE) HostedZoneId=$(HOSTED_ZONE) Flag=$(FLAG_3) --capabilities CAPABILITY_IAM
devserver: package-devserver build-and-push-container update-devserver
-aws cloudformation deploy --template-file $(GENERATED_CHALLENGES_DEVSERVER_TEMPLATE_ABSOLUTE_PATH) --stack-name HF-CTF-DevServer --parameter-overrides DomainName=$(DOMAIN_NAME) Certificate=$(CERTIFICATE) HostedZoneId=$(HOSTED_ZONE) --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM
update-challenges: export CTF_BUCKET_NAME=$(shell aws cloudformation list-exports --no-paginate --query "Exports[?Name=='HF-CTF-ProdServer-Bucket'].Value | [0]" --output text)
update-challenges:
aws s3 sync ctf/ s3://$(CTF_BUCKET_NAME)/ctf --exclude "*/.DS_Store"
update-devserver: export DEVSERVER_BUCKET_NAME=$(shell aws cloudformation list-exports --no-paginate --query "Exports[?Name=='HF-CTF-DevServer-Bucket'].Value | [0]" --output text)
update-devserver:
touch ctf/devserver/$(FLAG_9)
aws s3 sync ctf/devserver/ s3://$(DEVSERVER_BUCKET_NAME) --exclude "*/.DS_Store"
rm ctf/devserver/$(FLAG_9)
build-and-push-container:
cd ctf/devserver/backend && docker build -t hf-ctf-fargate-backend .
docker tag hf-ctf-fargate-backend:latest $(shell aws sts get-caller-identity --output text --query 'Account').dkr.ecr.$(shell aws configure get region).amazonaws.com/hf-ctf-fargate-backend:latest
$(shell aws ecr get-login --no-include-email --region us-east-1) && docker push $(shell aws sts get-caller-identity --output text --query 'Account').dkr.ecr.$(shell aws configure get region).amazonaws.com/hf-ctf-fargate-backend:latest
delete-challenges:
aws cloudformation delete-stack --stack-name HF-CTF-Challenges
ecs: package-ecs
-aws cloudformation deploy --template-file $(GENERATED_STATIC_TEMPLATE_ABSOLUTE_PATH) --parameter-overrides DomainName=$(DOMAIN_NAME) --stack-name HF-CTF-StaticResources
network: package-network
-aws cloudformation deploy --template-file $(GENERATED_NETWORK_TEMPLATE_ABSOLUTE_PATH) --stack-name HF-CTF-Network --parameter-overrides DomainName=$(DOMAIN_NAME) Certificate=$(CERTIFICATE) HostedZoneId=$(HOSTED_ZONE) --capabilities CAPABILITY_IAM
flag: package-flag
aws cloudformation deploy --template-file $(GENERATED_FLAG_TEMPLATE_ABSOLUTE_PATH) --stack-name HF-CTF-Flag --parameter-overrides Secret=$(FLAG_10) --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM
prerequisites: network ecs update-challenges
all: prerequisites challenges devserver clean
empty-bucket: export CTF_BUCKET_NAME=$(shell aws cloudformation list-exports --no-paginate --query "Exports[?Name=='HF-CTF-Bucket'].Value | [0]" --output text)
empty-bucket:
aws s3 rm s3://$(CTF_BUCKET_NAME) --recursive
clean:
-aws ssm delete-parameter --name 'Flag1'
-aws ssm delete-parameter --name 'Flag2'
-aws ssm delete-parameter --name 'Flag3'
-aws ssm delete-parameter --name 'Flag4'
-aws ssm delete-parameter --name 'Flag5'
-aws ssm delete-parameter --name 'Flag6'
-aws ssm delete-parameter --name 'Flag7'
-aws ssm delete-parameter --name 'Flag8'
-aws ssm delete-parameter --name 'Flag9'
-aws ssm delete-parameter --name 'Flag10'
-aws ssm delete-parameter --name 'SecretServerIp'