forked from xpublisher/weasyprint-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
133 lines (110 loc) · 4.43 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
# The binary to build (just the basename).
MODULE := weasyprint-rest
# Where to push the docker image.
DOCKER_REGISTRY ?= xpublisher/weasyprint-rest
GITHUB_REGISTRY ?= docker.pkg.github.com/xpublisher/weasyprint-rest/weasyprint-rest
# VERISON = 0.1.0
VERSION_PATCH := ${VERSION} # 0.1.0
VERSION_MINOR := $(shell echo "${VERSION}" | sed -E 's/.[0-9]+$$//') # 0.1
VERSION_MAJOR := $(shell echo "${VERSION}" | sed -E 's/.[0-9].[0-9]+$$//') # 0.1
ifeq ($(VERSION), main)
VERSION_NAME := "unstable"
else
VERSION_NAME := "latest"
endif
# This version-strategy uses git tags to set the version string
TAG := $(shell git describe --tags --always --dirty)
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo:
@echo ${VERSION_PATCH}
@echo ${VERSION_MINOR}
@echo ${VERSION_MAJOR}
run:
@python -m $(MODULE)
test:
@pytest
docker-test: build-dev
@docker run --env ENABLE_RUNTIME_TEST_ONLY=true -v `pwd`:/app weasyprint-rest:latest
lint:
@echo "\n${BLUE}Running Pylint against source and test files...${NC}\n"
@pylint --rcfile=setup.cfg **/*.py
@echo "\n${BLUE}Running Flake8 against source and test files...${NC}\n"
@flake8
@echo "\n${BLUE}Running Bandit against source files...${NC}\n"
@bandit -r --ini setup.cfg
# Example: make build-prod VERSION=1.0.0
build-prod:
@echo "\n${BLUE}Building Production image with labels:\n"
@echo "name: $(MODULE)"
@echo "version: $(VERSION)${NC}\n"
@sed \
-e 's|{NAME}|$(MODULE)|g' \
-e 's|{VERSION}|$(VERSION)|g' \
prod.Dockerfile | docker build -t weasyprint-rest:latest -f- .
build-dev:
@echo "\n${BLUE}Building Development image with labels:\n"
@echo "name: $(MODULE)"
@echo "version: $(TAG)${NC}\n"
@sed \
-e 's|{NAME}|$(MODULE)|g' \
-e 's|{VERSION}|$(TAG)|g' \
dev.Dockerfile | docker build -t weasyprint-rest:latest -f- .
# Example: make shell CMD="-c 'date > datefile'"
shell: build-dev
@echo "\n${BLUE}Launching a shell in the containerized build environment...${NC}\n"
@docker run \
-ti \
--rm \
--entrypoint /bin/bash \
-u $$(id -u):$$(id -g) \
weasyprint-rest:latest \
$(CMD)
push-all: build-prod
@echo "\n${BLUE}Pushing all images to all registries...${NC}\n"
@docker tag weasyprint-rest:latest $(DOCKER_REGISTRY):$(VERSION_NAME)
@docker push $(DOCKER_REGISTRY):$(VERSION_NAME)
@if [ "${VERSION_NAME}" = 'latest' ]; then \
docker tag weasyprint-rest:latest $(DOCKER_REGISTRY):$(VERSION_MAJOR) ; \
docker push $(DOCKER_REGISTRY):$(VERSION_MAJOR); \
docker tag weasyprint-rest:latest $(DOCKER_REGISTRY):$(VERSION_MINOR) ; \
docker push $(DOCKER_REGISTRY):$(VERSION_MINOR) ; \
docker tag weasyprint-rest:latest $(DOCKER_REGISTRY):$(VERSION_PATCH) ; \
docker push $(DOCKER_REGISTRY):$(VERSION_PATCH) ; \
fi
@docker tag weasyprint-rest:latest $(GITHUB_REGISTRY):$(VERSION_NAME)
@docker push $(GITHUB_REGISTRY):$(VERSION_NAME)
@if [ "${VERSION_NAME}" = 'latest' ]; then \
docker tag weasyprint-rest:latest $(GITHUB_REGISTRY):$(VERSION_MAJOR) ; \
docker push $(GITHUB_REGISTRY):$(VERSION_MAJOR); \
docker tag weasyprint-rest:latest $(GITHUB_REGISTRY):$(VERSION_MINOR) ; \
docker push $(GITHUB_REGISTRY):$(VERSION_MINOR) ; \
docker tag weasyprint-rest:latest $(GITHUB_REGISTRY):$(VERSION_PATCH) ; \
docker push $(GITHUB_REGISTRY):$(VERSION_PATCH) ; \
fi
cluster:
@if [ $$(kind get clusters | wc -l) = 0 ]; then \
kind create cluster --config ./k8s/cluster/kind-config.yaml --name kind; \
fi
@kubectl cluster-info --context kind-kind
@kubectl get nodes
@kubectl config set-context kind-kind --namespace $(MODULE)
deploy-local:
@kubectl rollout restart deployment $(MODULE)
cluster-debug:
@echo "\n${BLUE}Current Pods${NC}\n"
@kubectl describe pods
@echo "\n${BLUE}Recent Logs${NC}\n"
@kubectl logs --since=1h -lapp=$(MODULE)
cluster-rsh:
# if your container has bash available
@kubectl exec -it $$(kubectl get pod -l app=${MODULE} -o jsonpath="{.items[0].metadata.name}") -- /bin/bash
manifest-update:
@kubectl apply -f ./k8s/app.yaml
version:
@echo $(TAG)
.PHONY: clean image-clean build-prod push test
clean:
rm -rf .pytest_cache .coverage .pytest_cache coverage.xml
docker-clean:
@docker system prune -f --filter "label=name=$(MODULE)"