This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
83 lines (71 loc) · 2.41 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
name = s3fc
GO?=$(shell which go)
SAM?=$(shell which sam)
AWS?=$(shell which aws)
S3FC_INSTANCE_NAME ?= default
s3_stack_name = $(name)-s3-${S3FC_INSTANCE_NAME}
stack_name = $(name)-${S3FC_INSTANCE_NAME}
SOURCE=$(shell find . -name '*.go')
BUCKET=$(shell $(AWS) cloudformation describe-stacks \
--stack-name ${s3_stack_name} \
--query 'Stacks[0].Outputs[?OutputKey==`S3FCBucketName`].OutputValue' \
--output text 2>/dev/null)
S3FCBucketARN=$(shell $(AWS) cloudformation describe-stacks \
--stack-name ${s3_stack_name} \
--query 'Stacks[0].Outputs[?OutputKey==`S3FCBucketARN`].OutputValue' \
--output text 2>/dev/null)
KMS_KEY=$(shell $(AWS) cloudformation describe-stacks \
--stack-name ${s3_stack_name} \
--query 'Stacks[0].Outputs[?OutputKey==`S3FCKey`].OutputValue' \
--output text 2>/dev/null)
.PHONY: all
all: build init install
artifacts:
mkdir -p artifacts
artifacts/$(name).zip: $(SOURCE) | artifacts
GOOS=linux GOARCH=amd64 $(GO) build -ldflags="-s -w" -o artifacts/$(name) $(name)
cd artifacts && zip $(name).zip $(name)
.PHONY: build
build: artifacts/$(name).zip
.PHONY: test
test:
$(GO) test -race -cover ./...
.PHONY: init
init:
$(AWS) cloudformation deploy \
--template-file cloudformation/s3_cloudformation.yaml \
--stack-name $(s3_stack_name) \
--capabilities CAPABILITY_NAMED_IAM \
--no-fail-on-empty-changeset \
--parameter-overrides \
AppName=$(name) \
InstanceName=$(S3FC_INSTANCE_NAME)
.PHONY: install
install:
$(SAM) package \
--template-file cloudformation/app_cloudformation.yaml \
--output-template-file cloudformation/app_cloudformation_deploy.yaml \
--s3-bucket $(BUCKET) \
--s3-prefix sam-artifacts
$(SAM) deploy \
--template-file cloudformation/app_cloudformation_deploy.yaml \
--stack-name $(stack_name) \
--capabilities CAPABILITY_NAMED_IAM \
--no-fail-on-empty-changeset \
--parameter-overrides \
AppName=$(name) \
InstanceName=$(S3FC_INSTANCE_NAME) \
Bucket=$(S3FCBucketARN) \
KMSKey=$(KMS_KEY)
.PHONY: uninstall
uninstall:
scripts/empty_bucket.sh $(AWS) $(BUCKET)
$(AWS) cloudformation delete-stack --stack-name $(stack_name)
$(AWS) cloudformation wait stack-delete-complete --stack-name $(stack_name)
$(AWS) cloudformation delete-stack --stack-name $(s3_stack_name)
$(AWS) cloudformation wait stack-delete-complete --stack-name $(s3_stack_name)
.PHONY: clean
clean:
rm -f artifacts/$(name)
rm -f artifacts/$(name).zip
rm -f cloudformation_deploy.yaml