This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
74 lines (62 loc) · 2.12 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
VERSION=0.1.0
ifeq ($(STAGE),staging)
PUBLISH_TO = s3://chainer-cfn-staging
S3_ACL =
endif
ifeq ($(STAGE),production)
PUBLISH_TO = s3://chainer-cfn
S3_ACL = --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
endif
TEST_STACK ?= chainer-cfn-test
KEYPAIR_DIR ?= ~/.ssh
SSH_USER ?= chainer
AWS ?= /usr/local/bin/aws
.PHONY: build pip
pip:
pip install -r requirements.txt
build: pip
mkdir -p build
cd template && \
python main.py > ../build/template.yaml
.PHONY: validate
validate: build
$(AWS) cloudformation validate-template --template-body file://./build/template.yaml
.PHONY: publish
publish: validate
$(AWS) s3 cp build/template.yaml $(PUBLISH_TO)/chainer-cfn-v$(VERSION).template $(S3_ACL)
.PHONY: test
create-stack: validate
$(AWS) cloudformation create-stack \
--capabilities CAPABILITY_IAM \
--stack-name $(TEST_STACK) \
--template-body file://build/template.yaml \
--parameters \
ParameterKey=KeyPairName,ParameterValue=$(KEY_PAIR_NAME) \
ParameterKey=InstanceType,ParameterValue=g2.2xlarge \
ParameterKey=WorkerSize,ParameterValue=2 && \
$(AWS) cloudformation wait stack-create-complete \
--stack-name $(TEST_STACK) && \
$(AWS) cloudformation describe-stacks \
--stack-name $(TEST_STACK) \
--query 'Stacks[*].StackStatus' \
--output text && \
$(AWS) cloudformation describe-stacks \
--stack-name $(TEST_STACK) \
--query '(Stacks[*].Outputs[?OutputKey==`ClusterMasterPublicDNS`][])[0].OutputValue' \
--output text
delete-stack:
$(AWS) s3 rm --recursive s3://$(TEST_STACK)-assets && \
$(AWS) cloudformation delete-stack --stack-name $(TEST_STACK) && \
$(AWS) cloudformation wait stack-delete-complete --stack-name $(TEST_STACK)
.PHONY: stack-master
stack-master:
@$(AWS) cloudformation describe-stacks \
--stack-name $(TEST_STACK) \
--query '(Stacks[*].Outputs[?OutputKey==`ClusterMasterPublicDNS`][])[0].OutputValue' \
--output text
.PHONY: e2e-test
e2e-test:
cat e2e/test.sh | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $(KEYPAIR_DIR)/$(KEY_PAIR_NAME).pem chainer@$$(make stack-master TEST_STACK=$(TEST_STACK))
.PHONY: clean
clean:
rm -rf build/