forked from buildkite/elastic-ci-stack-for-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (53 loc) · 2.4 KB
/
Makefile
File metadata and controls
71 lines (53 loc) · 2.4 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
.PHONY: all clean build build-ami upload create-stack create-stack-and-wait update-stack update-stack-and-wait download-mappings
BUILDKITE_STACK_BUCKET ?= buildkite-aws-stack
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
STACK_NAME =? buildkite
SHELL=/bin/bash -o pipefail
all: setup build
build: build/aws-stack.json
build/aws-stack.json: $(wildcard templates/*.yml) templates/mappings.yml
-mkdir -p build/
bundle exec cfoo $^ > $@
setup:
bundle check || ((which bundle || gem install bundler --no-ri --no-rdoc) && bundle install --path vendor/bundle)
clean:
-rm -f build/*
templates/mappings.yml:
$(error Either run `make build-ami` to build the ami, or `make download-mappings` to download the latest public mappings)
download-mappings:
echo "Downloading templates/mappings.yml for branch ${BRANCH}"
curl -Lf -o templates/mappings.yml https://s3.amazonaws.com/buildkite-aws-stack/${BRANCH}/mappings.yml
touch templates/mappings.yml
build-ami:
cd packer/; packer build buildkite-ami.json | tee ../packer.output
cp templates/mappings.yml.template templates/mappings.yml
sed -i.bak "s/packer_image_id/$(shell grep -Eo 'us-east-1: (ami-.+)' packer.output | cut -d' ' -f2)/" templates/mappings.yml
upload: build/aws-stack.json
aws s3 sync --acl public-read build s3://${BUILDKITE_STACK_BUCKET}/
config.json:
test -s config.json || $(error Please create a config.json file)
create-stack-and-wait: create-stack wait-for-ceate-stack-complete
wait-for-ceate-stack-complete:
aws cloudformation wait stack-create-complete --stack-name ${STACK_NAME}
create-stack: config.json build/aws-stack.json
aws cloudformation create-stack \
--output text \
--stack-name ${STACK_NAME} \
--disable-rollback \
--template-body "file://${PWD}/build/aws-stack.json" \
--capabilities CAPABILITY_IAM \
--parameters '$(shell cat config.json)'
validate: build/aws-stack.json
aws cloudformation validate-template \
--output table \
--template-body "file://${PWD}/build/aws-stack.json"
update-stack-and-wait: update-stack wait-for-update-stack-complete
wait-for-update-stack-complete:
aws cloudformation wait stack-update-complete --stack-name ${STACK_NAME}
update-stack: config.json templates/mappings.yml build/aws-stack.json
aws cloudformation update-stack \
--output text \
--stack-name ${STACK_NAME} \
--template-body "file://${PWD}/build/aws-stack.json" \
--capabilities CAPABILITY_IAM \
--parameters '$(shell cat config.json)'