-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
94 lines (77 loc) · 3.37 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
include Makefile.mk
NAME=aws-cloudwatch-log-minder
AWS_REGION=eu-central-1
S3_BUCKET_PREFIX=binxio-public
S3_BUCKET=$(S3_BUCKET_PREFIX)-$(AWS_REGION)
ALL_REGIONS=$(shell aws --region $(AWS_REGION) \
ec2 describe-regions \
--query 'join(`\n`, Regions[?RegionName != `$(AWS_REGION)`].RegionName)' \
--output text)
help:
@echo 'make - builds a zip file to target/.'
@echo 'make release - builds a zip file and deploys it to s3.'
@echo 'make clean - the workspace.'
@echo 'make test - execute the tests, requires a working AWS connection.'
@echo 'make deploy - lambda to bucket $(S3_BUCKET)'
@echo 'make deploy-all-regions - lambda to all regions with bucket prefix $(S3_BUCKET_PREFIX)'
@echo 'make deploy-lambda - deploys the manager.'
@echo 'make delete-lambda - deletes the manager.'
@echo 'make demo - deploys the provider and the demo cloudformation stack.'
@echo 'make delete-demo - deletes the demo cloudformation stack.'
deploy-all-regions: deploy
@for REGION in $(ALL_REGIONS); do \
echo "copying to region $$REGION.." ; \
aws s3 --region $$REGION \
cp --acl public-read \
s3://$(S3_BUCKET_PREFIX)-$(AWS_REGION)/lambdas/$(NAME)-$(VERSION).zip \
s3://$(S3_BUCKET_PREFIX)-$$REGION/lambdas/$(NAME)-$(VERSION).zip; \
aws s3 --region $$REGION \
cp --acl public-read \
s3://$(S3_BUCKET_PREFIX)-$$REGION/lambdas/$(NAME)-$(VERSION).zip \
s3://$(S3_BUCKET_PREFIX)-$$REGION/lambdas/$(NAME)-latest.zip; \
done
do-push: deploy
do-build: Pipfile.lock target/$(NAME)-$(VERSION).zip
upload-dist: Pipfile.lock
pipenv run twine upload dist/*
target/$(NAME)-$(VERSION).zip: setup.py src/*/*.py requirements.txt Dockerfile.lambda
mkdir -p target
rm -rf dist/* target/*
pipenv run python setup.py check
pipenv run python setup.py build
pipenv run python setup.py sdist
docker build --build-arg ZIPFILE=$(NAME)-$(VERSION).zip -t $(NAME)-lambda:$(VERSION) -f Dockerfile.lambda . && \
ID=$$(docker create $(NAME)-lambda:$(VERSION) /bin/true) && \
docker export $$ID | (cd target && tar -xvf - $(NAME)-$(VERSION).zip) && \
docker rm -f $$ID && \
chmod ugo+r target/$(NAME)-$(VERSION).zip
Pipfile.lock: Pipfile requirements.txt test-requirements.txt setup.py
pipenv update -d
clean:
rm -rf venv target
find . -name \*.pyc | xargs rm
test: Pipfile.lock
for i in $$PWD/cloudformation/*; do \
aws cloudformation validate-template --template-body file://$$i > /dev/null || exit 1; \
done
[ -z "$(shell ls -1 tests/test*.py 2>/dev/null)" ] || PYTHONPATH=$(PWD)/src pipenv run pytest ./tests/test*.py
fmt:
black $(shell find src -name \*.py) tests/*.py
deploy: target/$(NAME)-$(VERSION).zip
aws s3 --region $(AWS_REGION) \
cp --acl \
public-read target/$(NAME)-$(VERSION).zip \
s3://$(S3_BUCKET)/lambdas/$(NAME)-$(VERSION).zip
aws s3 --region $(AWS_REGION) \
cp --acl public-read \
s3://$(S3_BUCKET)/lambdas/$(NAME)-$(VERSION).zip \
s3://$(S3_BUCKET)/lambdas/$(NAME)-latest.zip
deploy-lambda: deploy target/$(NAME)-$(VERSION).zip
aws cloudformation deploy \
--capabilities CAPABILITY_IAM \
--stack-name $(NAME) \
--template-file ./cloudformation/aws-cloudwatch-log-minder.yaml \
--parameter-override CFNCustomProviderZipFileName=lambdas/$(NAME)-$(VERSION).zip
delete-lambda:
aws cloudformation delete-stack --stack-name $(NAME)
aws cloudformation wait stack-delete-complete --stack-name $(NAME)