-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (102 loc) · 4.25 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= .env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
# default: build
# DOCKER TASKS
# Build the container
build: ## Build the container
docker build -t $(APP_NAME):$(VERSION) -t $(APP_NAME):latest .
build-nc: ## Build the container without caching
docker build --no-cache -t $(APP_NAME):$(VERSION) -t $(APP_NAME):latest .
up: ## Up container from registry image
docker-compose -f docker-compose.yml up -d
dev-up: ## Run container with docker-compose.dev.yml
black .
docker-compose -f docker-compose.dev.yml up --build
run: ## Run container docker run -d
docker run -d -t --rm --env-file=.env --name="$(APP_NAME)" $(APP_NAME)
rm: ## Stop and remove a running container
docker rm $(APP_NAME) || true
stop: ## Stop and remove a running container
docker-compose --env-file .env stop
dev-stop: ## Stop and remove a running container
docker-compose --env-file .env -f docker-compose.dev.yml stop
logs: ## view logs
docker logs $(APP_NAME)
log-tail: ## tail log
docker exec -i $(APP_NAME) tail -f $(LOG_PATH)
clean: ## Cleaning up old container images and cache files
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
docker-compose down -v
# docker rmi $(docker images -f "dangling=true"-q)
flake: ## Run flake8 linters
flake8 -v app
pylint: ## Run Pylint linter
pylint app
test: ## Run tests
docker exec $(APP_NAME) pytest -v -p no:warnings /tests/
test-last-failed: ## Run last failed tests only
docker exec $(APP_NAME) pytest -q /tests/ --lf -p no:warnings
#test-dev: ## Run tests with covarege
# python -m pytest -v --cov=src --cov-report term-missing ./tests/unit/ --cov ./src/app
kill: ## Kill a running container
docker kill $(APP_NAME)
#pip-freeze: ## freezing dependencies
# pip freeze > requirements.txt
release: build-nc publish ## Make a release by building and publishing the `{version}` and `latest` tagged containers to registry
# Docker publish
publish: repo-login publish-latest publish-version ## Publish the `{version}` and `latest` tagged containers to registry.
publish-latest: tag-latest ## Publish the `latest` tagged container to ECR
@echo 'publish latest to $(DOCKER_REPO)'
docker push $(DOCKER_REPO):latest
publish-version: tag-version ## Publish the `{version}` tagged container to ECR
@echo 'publish $(VERSION) to $(DOCKER_REPO)'
docker push $(DOCKER_REPO):$(VERSION)
## Docker tagging
tag: tag-latest tag-version ## Generate container tags for the `{version}` ans `latest` tags
tag-latest: ## Generate container `{version}` tag
@echo 'create tag latest'
docker tag $(APP_NAME) $(DOCKER_REPO):latest
tag-version: ## Generate container `latest` tag
@echo 'create tag $(VERSION)'
docker tag $(APP_NAME) $(DOCKER_REPO):$(VERSION)
shell: ## run bash in container
docker exec -i -t $(APP_NAME) bash
sh: ## run sh in container
docker exec -i -t $(APP_NAME) sh
#ask_password:
# @$(eval PASSWORD=$(shell stty -echo; read -p "Password: " pwd; stty echo; echo $$pwd))
#
## login to REGISTRY
#repo-login: ask_password ## login to repo
# docker login --username $(DOCKER_USER) --password $(PASSWORD) $(DOCKER_REGISTRY)
# login to registry
repo-login: ## login to repo
docker login --username $(DOCKER_USER) --password $(DOCKER_PASSWORD) $(DOCKER_REGISTRY)
pull: ## pull latest docker image
docker pull $(DOCKER_REPO)
version: ## Output the current version
@echo $(VERSION)
#send-link:
# ./infra/tg.sh 'https://$(DOCKER_REPO)/v2/$(APP_NAME)/manifests/$(VERSION)/'
# ./infra/tg.sh 'docker pull $(DOCKER_REPO)'
psql: ## database console
docker exec -it db-$(APP_NAME) psql --username=${POSTGRES_USER} --dbname=${POSTGRES_DB}
db-bash: ## bash in database container
docker exec -it db-$(APP_NAME) bash
migrate: ## database migrate
docker exec -i $(APP_NAME) flask db migrate
db-upgrade: ## database upgrade
docker exec -i $(APP_NAME) flask db upgrade
flask-shell: ## flask shell
docker exec -i $(APP_NAME) flask shell