-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
76 lines (63 loc) · 2.44 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
.DEFAULT_GOAL := help
.PHONY: help
help: ## Print Makefile help
@grep -Eh '^[a-z.A-Z_0-9-]+:.*?## .*$$' ${MAKEFILE_LIST} | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[1;36m%-18s\033[0m %s\n", $$1, $$2}'
IMAGE_NAME ?= quay.io/danielhoherd/plexdl
NO_CACHE ?= false
ORG_PREFIX ?= danielhoherd
GIT_ORIGIN = $(shell git config --get remote.origin.url)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
GIT_SHA_SHORT = $(shell if [ ! -z "`git status --porcelain`" ] ; then echo "DIRTY" ; else git rev-parse --short HEAD ; fi)
BUILD_TIME = $(shell date '+%s')
BUILD_DATE = $(shell date '+%F')
.PHONY: all
all: docker-build
.PHONY: docker-build
docker-build: wheel ## Build the Dockerfile found in PWD
docker build --no-cache="${NO_CACHE}" \
-t "${IMAGE_NAME}:latest" \
-t "${IMAGE_NAME}:${BUILD_DATE}" \
-t "${IMAGE_NAME}:${GIT_BRANCH}" \
-t "${IMAGE_NAME}:${GIT_BRANCH}-${GIT_SHA_SHORT}" \
--label "${ORG_PREFIX}.repo.origin=${GIT_ORIGIN}" \
--label "${ORG_PREFIX}.repo.branch=${GIT_BRANCH}" \
--label "${ORG_PREFIX}.repo.commit=${GIT_SHA_SHORT}" \
--label "${ORG_PREFIX}.build_time=${BUILD_TIME}" \
.
.PHONY: docker-push
docker-push: ## Push built Docker container to Docker Hub
docker images --format="{{.Repository}}:{{.Tag}}" | grep '${IMAGE_NAME}.*DIRTY' | xargs -n1 docker rmi
docker push ${IMAGE_NAME}
.PHONY: clean
clean: ## Delete build artifacts
rm -f .requirements-dev .requirements || true
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
rm -rf dist
.PHONY: poetry-clean
poetry-clean: ## Delete poetry virtualenv
poetry env list 2>/dev/null | awk '{print $$1}' | xargs -n1 poetry env remove || true
rm -fv .requirements
.PHONY: wheel
wheel: ## Build a wheel
poetry build -f wheel
.PHONY: test
test: ## Run tests
tox
.PHONY: requirements-dev
requirements-dev: .requirements-dev ## Install dev requirements
.requirements-dev:
pip3 install --user --upgrade poetry
poetry run pip install --quiet --upgrade pip setuptools wheel
poetry install
touch .requirements-dev .requirements
.PHONY: requirements
requirements: .requirements ## Install requirements
.requirements:
pip3 install --user --upgrade poetry
poetry run pip install --quiet --upgrade pip setuptools wheel
poetry install --no-dev
touch .requirements
.PHONY: generate-setup.py
generate-setup.py: wheel ## Generate the setup.py file from pyproject.toml
tar -xvf dist/*.tar.gz --wildcards --no-anchored '*/setup.py' --strip=1