-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (53 loc) · 1.46 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
.DEFAULT_GOAL := help
# Variables
AWS_PROFILE := $(AWS_PROFILE)
ACCOUNT_ID ?= $(shell aws sts get-caller-identity | jq -r .Account)
REGION ?= eu-north-1
APPLICATION ?= hello
ECR_URL := $(ACCOUNT_ID).dkr.ecr.$(REGION).amazonaws.com
DOCKER_IMAGE ?= $(ECR_URL)/$(APPLICATION)
# Commands
AWS = aws
VENV = venv
PYTHON = $(VENV)/bin/python
PIP = $(VENV)/bin/pip --disable-pip-version-check
FLAKE8 = $(VENV)/bin/flake8
DOCKER = docker
# Targets
$(PIP):
@python3 -m venv $(VENV) || true
$(FLAKE8): $(PIP)
@$(PIP) install -q flake8==4.0.1
## lint: Lint Python code.
lint: $(FLAKE8)
$(call blue, " Linting lambda...")
@$(FLAKE8) --ignore=W605,E501 hello.py
## docker.build: Build the docker image in service
docker.build: lint
$(call blue,"# Running docker build...")
@docker build -t $(DOCKER_IMAGE) .
## docker.login: Login to ECR
docker.login:
$(AWS) ecr get-login-password --region $(REGION) | \
docker login --username AWS --password-stdin $(ACCOUNT_ID).dkr.ecr.$(REGION).amazonaws.com
## docker.push: Push an image to ECR
docker.push:
$(DOCKER) push $(DOCKER_IMAGE)
## create-repo: Create the ECR repository
create-repo:
$(AWS) ecr create-repository --region $(REGION) \
--repository-name $(APPLICATION)
## help: prints this help message
.PHONY: help
help: Makefile
@echo
$(call blue, " Choose a command run:")
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
# -- Helper Functions --
define blue
@tput setaf 4
@echo $1
@tput sgr0
endef