This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
generated from openculinary/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
54 lines (44 loc) · 2.27 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
.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.11-slim))
buildah copy $(container) 'web' 'web'
buildah copy $(container) 'requirements.txt'
buildah run $(container) -- useradd --home-dir /srv/ --no-create-home gunicorn --shell /sbin/nologin --
buildah run $(container) -- chown gunicorn /srv/ --
buildah run --user gunicorn $(container) -- pip install --no-deps --no-warn-script-location --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:nogroup /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 --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 --quiet --strip-extras requirements.in
requirements-dev.txt: requirements.txt requirements-dev.in
venv/bin/pip-compile --allow-unsafe --generate-hashes --no-config --no-header --quiet --strip-extras 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
venv/bin/pytest tests