-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
89 lines (71 loc) · 3.09 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
CODE_PATHS := labop_labware_ontology
GITLAB_USERNAME ?=
GITLAB_TOKEN ?=
PYTHON_VERSION ?= 3.9## default python build to 3.9
# Originally CI_PROJECT_NAME came from the CI, but it is safer if this comes directly from pyproject.toml
CI_PROJECT_NAME := $(shell grep -i name pyproject.toml | head -1 | awk -F'"' '{print $$2}' | tr "[A-Z]" "[a-z]" | tr "_" "-")
CI_COMMIT_REF_NAME ?= $(shell git symbolic-ref --short -q HEAD)
CI_COMMIT_REF_NAME := $(subst /,-,$(CI_COMMIT_REF_NAME))
CI_COMMIT_BEFORE_SHA := $(shell git rev-parse HEAD^1)
CI_COMMIT_SHA ?= $(shell git rev-parse HEAD)
CI_COMMIT_SHORT_SHA ?= $(shell git rev-parse --short HEAD)
CURRENT_LOCATION ?= $(shell pwd)
CI_ENVIRONMENT_NAME ?=
CI_DOCKER_BUILD_ARGS ?=
PYPI_URL ?= https://artifactory.aws.gel.ac/artifactory/api/pypi/pypi/simple
CI_REGISTRY ?= registry.gitlab.com
CI_REGISTRY_IMAGE ?= ${CI_REGISTRY}/opensourcelab/labop-labware-ontology
DOCKER_IMAGE_NAMESPACE := ${CI_REGISTRY_IMAGE}/${CI_PROJECT_NAME}
DOCKER_IMAGE_TAG ?= ${DOCKER_IMAGE_NAMESPACE}:py${PYTHON_VERSION}-${CI_COMMIT_REF_NAME}
.PHONY: build test
help: ## Prints this help/overview message
@awk 'BEGIN {FS = ":.*?## "} /^[a-z0-9_-]+:.*?## / {printf "\033[36m%-17s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
_CMD_DOCKER_BUILD := \
docker build \
${CI_DOCKER_BUILD_ARGS} \
## construct the docker image with the git branch inc. into the tag
.build_${PYTHON_VERSION}: Dockerfile labop_labware_ontology clean__py
${_CMD_DOCKER_BUILD} \
--platform linux/amd64 \
--build-arg PYTHON_BASE=${PYTHON_VERSION} \
--build-arg PYPI_URL=${PYPI_URL} \
--cache-from ${DOCKER_IMAGE_TAG} \
--tag ${DOCKER_IMAGE_TAG} \
--target test \
.
touch $@
build: .build_${PYTHON_VERSION} ## build local python3.9 image. Define PYTHON_VERSION to select other python version.
push: build
docker push ${DOCKER_IMAGE_TAG}
pull:
docker pull ${DOCKER_IMAGE_TAG} || echo "No pre-made image available"
test: ## run pytest on mounted-in tests (change tests, no rebuild!)
mkdir -p $(shell pwd)/bin && \
docker run \
--platform linux/amd64 \
--volume $(shell pwd)/bin/:/labop_labware_ontology/bin/ \
--volume $(shell pwd):/labop_labware_ontology:rw \
${DOCKER_IMAGE_TAG} \
pytest --cov-report xml:/labop_labware_ontology/bin/coverage.xml tests/
test_shell: ## enter test docker image Bash
mkdir -p $(shell pwd)/bin && \
docker run -it \
--platform linux/amd64 \
--volume $(shell pwd)/bin/:/labop_labware_ontology/bin/ \
--volume $(shell pwd):/labop_labware_ontology:rw \
${DOCKER_IMAGE_TAG} \
/bin/bash
# cleaning up --------------------------------------------------------
clean: clean__docker clean__py clean__reports
clean__py: ## clean python temp files
find . -iname *.pyc -delete
find . -iname __pycache__ -delete
find . -iname .cache -delete
clean__docker: ## Clean up all docker images generated by this repo
rm -rf .*sentinel
for image in \
$$(docker images --format "{\{.Repository}\}:{\{.Tag}\}\t{\{.ID}\}" | grep -e "${DOCKER_IMAGE_NAMESPACE}" | awk '{print $$2}'); do \
docker rmi -f $$image; \
done
clean__reports:
rm -rf ${PATH_REPORTS}