-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (102 loc) · 3.09 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
#!/usr/bin/env bash
VCS_REF ?= $(shell git describe --dirty --abbrev=10 --tags --always 2>/dev/null)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= 1.0.1
PROJECT_TEAM ?= cyrbil
PROJECT_NAME ?= covid19-bot
PROJECT_ROOT ?= $(abspath $(dir $(lastword ${MAKEFILE_LIST})))
DOCKER_IMAGE ?= ${PROJECT_TEAM}/${PROJECT_NAME}:${VERSION}-${VCS_REF}
.PHONY: clean
clean:
docker stop "${PROJECT_NAME}_dev-tools" "${PROJECT_NAME}" || true
docker wait "${PROJECT_NAME}_dev-tools" "${PROJECT_NAME}" || true
docker rm "${PROJECT_NAME}_dev-tools" "${PROJECT_NAME}" || true
.PHONY: init
init:
docker run \
--detach \
--name "${PROJECT_NAME}_dev-tools" \
--volume "${PROJECT_ROOT}:/app" \
--workdir "/app" \
--env "TERM=xterm-256color" \
python:3.8-buster \
/bin/bash -c 'trap : TERM INT; sleep infinity & wait' \
|| exit 0 \
&& docker exec "${PROJECT_NAME}_dev-tools" \
/bin/bash -c ' \
apt-get update \
&& apt-get install -y make git \
&& python3 -m pip install \
--no-deps \
--no-cache \
--require-hashes \
--requirement dev-requirements.txt \
--requirement requirements.txt' \
&& echo -e "#!/bin/bash\nmake precommit" > "${PROJECT_ROOT}/.git/hooks/pre-commit"
.PHONY: install
install:
python3 -m pip install \
--no-deps \
--no-cache \
--require-hashes \
--requirement dev-requirements.txt \
--requirement requirements.txt
.PHONY: precommit
precommit:
docker exec --tty "${PROJECT_NAME}_dev-tools" \
python3 -m pre_commit run --all
.PHONY: build
build:
docker build --rm --tag "${DOCKER_IMAGE}" \
--build-arg "BUILD_DATE=${BUILD_DATE}" \
--build-arg "VCS_REF=${VCS_REF}" \
--build-arg "VERSION=${VERSION}" \
.
.PHONY: run
run:
docker run \
--rm -ti \
--name "${PROJECT_NAME}" \
--env "SLACK_WEBHOOK=$${SLACK_WEBHOOK}" \
--env "CHANNEL=$${CHANNEL}" \
"${DOCKER_IMAGE}"
lock.run%:
docker exec --tty "${PROJECT_NAME}_dev-tools" \
python3 -m piptools compile \
--generate-hashes \
${REQUIREMENTS_IN}
.PHONY: lock
lock: export REQUIREMENTS_IN=requirements.in
lock: lock.run.prod
.PHONY: lock.dev
lock.dev: export REQUIREMENTS_IN=dev-requirements.in
lock.dev: lock.run.dev
.PHONY: checks
checks: check.syntax check.lint check.type check.doc check.imports check.security check.requirements check.ci
.PHONY: check.security
check.security:
python3 -m bandit -r .
.PHONY: check.syntax
check.syntax:
python3 -m black --line-length=120 --diff --check --verbose app.py
.PHONY: check.type
check.type:
python3 -m mypy app.py
.PHONY: check.imports
check.imports:
python3 -m isort --diff app.py
.PHONY: check.doc
check.doc:
python3 -m pydocstyle app.py
.PHONY: check.lint
check.lint:
python3 -m pylint \
--jobs=0 \
--disable=missing-class-docstring \
--disable=missing-module-docstring \
--disable=missing-function-docstring \
--max-line-length=120 \
app.py
.PHONY: check.requirements
check.requirements:
python3 -m safety check --bare