-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (46 loc) · 2.49 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
.PHONY: build deploy image lint tests
SERVICE=$(shell basename $(shell git rev-parse --show-toplevel))
REGISTRY=registry.openculinary.org
PROJECT=reciperadar
IMAGE_NAME=${REGISTRY}/${PROJECT}/${SERVICE}
IMAGE_COMMIT := $(shell git rev-parse --short HEAD)
IMAGE_TAG := $(strip $(if $(shell git status --porcelain --untracked-files=no), latest, ${IMAGE_COMMIT}))
build: image
deploy:
kubectl apply -f k8s
kubectl set image deployments -l app=${SERVICE} ${SERVICE}=${IMAGE_NAME}:${IMAGE_TAG}
image:
$(eval container=$(shell buildah from docker.io/library/python:3.12-alpine))
buildah copy $(container) 'web' 'web'
buildah copy $(container) 'requirements.txt'
buildah run $(container) -- adduser -h /srv/ -s /sbin/nologin -D -H gunicorn --
buildah run $(container) -- chown gunicorn /srv/ --
buildah run --user gunicorn $(container) -- pip install --no-deps --no-warn-script-location --only-binary lxml --progress-bar off --requirement requirements.txt --user --
# Begin: HACK: For rootless compatibility across podman and k8s environments, unset file ownership and grant read+exec to binaries
buildah run $(container) -- chown -R nobody:nobody /srv/ --
buildah run $(container) -- chmod -R a+rx /srv/.local/bin/ --
buildah run $(container) -- find /srv/ -type d -exec chmod a+rx {} \;
# End: HACK
buildah config --env IMAGE_VERSION=${IMAGE_TAG} $(container)
buildah config --env PYTHONDONTWRITEBYTECODE=1 $(container)
buildah config --cmd '/srv/.local/bin/gunicorn web.app:app --bind :8000' --port 8000 --user gunicorn $(container)
buildah commit --quiet --rm --squash $(container) ${IMAGE_NAME}:${IMAGE_TAG}
# Virtualenv Makefile pattern derived from https://github.com/bottlepy/bottle/
venv: venv/.installed requirements.txt requirements-dev.txt
venv/bin/pip install --requirement requirements-dev.txt --quiet
touch venv
venv/.installed:
python3 -m venv venv
venv/bin/pip install pip-tools
touch venv/.installed
requirements.txt: requirements.in
venv/bin/pip-compile --allow-unsafe --generate-hashes --no-config --no-header --output-file requirements.txt --quiet --strip-extras requirements.in
requirements-dev.txt: requirements.in requirements-dev.in
venv/bin/pip-compile --allow-unsafe --generate-hashes --no-config --no-header --output-file requirements-dev.txt --quiet --strip-extras requirements.in requirements-dev.in
lint: venv
venv/bin/black --check --quiet tests
venv/bin/black --check --quiet web
venv/bin/flake8 tests
venv/bin/flake8 web
tests: venv
IMAGE_VERSION=${IMAGE_TAG} venv/bin/pytest tests