1+ # The binary to build (just the basename).
2+ MODULE := blueprint
3+
4+ # Where to push the docker image.
5+ REGISTRY ?= docker.pkg.github.com/martinheinz/python-project-blueprint
6+
7+ IMAGE := $(REGISTRY ) /$(MODULE )
8+
9+ # This version-strategy uses git tags to set the version string
10+ TAG := $(shell git describe --tags --always --dirty)
11+
12+ BLUE ='\033[0;34m'
13+ NC ='\033[0m' # No Color
14+
15+ run :
16+ @python -m $(MODULE )
17+
18+ test :
19+ @pytest
20+
21+ # Example: make build-prod VERSION=1.0.0
22+ build-prod :
23+ @echo " \n${BLUE} Building Production image with labels:\n"
24+ @echo " name: $( MODULE) "
25+ @echo " version: $( VERSION) ${NC} \n"
26+ @sed \
27+ -e ' s|{NAME}|$(MODULE)|g' \
28+ -e ' s|{VERSION}|$(VERSION)|g' \
29+ prod.Dockerfile | docker build -t $(IMAGE ) :$(VERSION ) -f- .
30+
31+
32+ build-dev :
33+ @echo " \n${BLUE} Building Development image with labels:\n"
34+ @echo " name: $( MODULE) "
35+ @echo " version: $( TAG) ${NC} \n"
36+ @sed \
37+ -e ' s|{NAME}|$(MODULE)|g' \
38+ -e ' s|{VERSION}|$(TAG)|g' \
39+ dev.Dockerfile | docker build -t $(IMAGE ) :$(TAG ) -f- .
40+
41+ # Example: make shell CMD="-c 'date > datefile'"
42+ shell : build-dev
43+ @echo " \n${BLUE} Launching a shell in the containerized build environment...${NC} \n"
44+ @docker run \
45+ -ti \
46+ --rm \
47+ --entrypoint /bin/bash \
48+ -u $$(id -u ) :$$(id -g ) \
49+ $(IMAGE ) :$(TAG ) \
50+ $(CMD )
51+
52+ # Example: make push VERSION=0.0.2
53+ push : build-prod
54+ @echo " \n${BLUE} Pushing image to GitHub Docker Registry...${NC} \n"
55+ @docker push $(IMAGE ) :$(VERSION )
56+
57+ version :
58+ @echo $(TAG )
59+
60+ .PHONY : clean image-clean build-prod push
61+
62+ clean :
63+ rm -rf .pytest_cache
64+
65+ docker-clean :
66+ @docker system prune --filter " label=name=$( IMAGE) "
0 commit comments