-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
49 lines (38 loc) · 1.23 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
DEPLOY_CONFIG ?= deploy.jsonnet
STACK_CONFIG ?= stack.jsonnet
CODE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CWD := ${CURDIR}
BINPATH := build/main
TEMPLATE_FILE := template.json
SAM_FILE := sam.yml
BASE_FILE := $(CODE_DIR)/template.libsonnet
ifdef TAGS
TAGOPT=--tags $(TAGS)
else
TAGOPT=
endif
all: deploy
test:
go test -v
clean:
rm build/main
build: $(BINPATH)
$(BINPATH): $(CODE_DIR)/*.go
cd $(CODE_DIR) && env GOARCH=amd64 GOOS=linux go build -o $(CWD)/build/main && cd $(CWD)
$(TEMPLATE_FILE): $(STACK_CONFIG) $(BASE_FILE)
jsonnet -J $(CODE_DIR) $(STACK_CONFIG) -o $(TEMPLATE_FILE)
$(SAM_FILE): $(TEMPLATE_FILE) $(BINPATH)
aws cloudformation package \
--region $(shell jsonnet $(DEPLOY_CONFIG) | jq .Region) \
--template-file $(TEMPLATE_FILE) \
--s3-bucket $(shell jsonnet $(DEPLOY_CONFIG) | jq .CodeS3Bucket) \
--s3-prefix $(shell jsonnet $(DEPLOY_CONFIG) | jq .CodeS3Prefix) \
--output-template-file $(SAM_FILE)
deploy: $(SAM_FILE)
aws cloudformation deploy \
--region $(shell jsonnet $(DEPLOY_CONFIG) | jq .Region) \
--template-file $(SAM_FILE) \
--stack-name $(shell jsonnet $(DEPLOY_CONFIG) | jq .StackName) \
--capabilities CAPABILITY_IAM \
$(TAGOPT) \
--no-fail-on-empty-changeset