Skip to content

Commit 3492a40

Browse files
committed
Makefile and Dockerfile updates.
1 parent 0f26b58 commit 3492a40

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

Makefile

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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)"

dev.Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ COPY . /app
1414
WORKDIR /app
1515
RUN /venv/bin/pytest
1616

17-
FROM python:3.8.1-alpine3.11 AS runner
17+
FROM python:3.8.1 AS runner
1818
COPY --from=tester /venv /venv
1919
COPY --from=tester /app /app
2020

2121
WORKDIR /app
2222

2323
ENTRYPOINT ["/venv/bin/python3", "-m", "blueprint"]
2424
USER 1001
25+
26+
LABEL name={NAME}
27+
LABEL version={VERSION}

prod.Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ WORKDIR /app
2222

2323
ENTRYPOINT ["/venv/bin/python3", "-m", "blueprint"]
2424
USER 1001
25+
26+
LABEL name={NAME}
27+
LABEL version={VERSION}

0 commit comments

Comments
 (0)