Shad Ansari | 1dcfdb3 | 2022-01-24 23:13:06 +0000 | [diff] [blame^] | 1 | # |
| 2 | # SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org> |
| 3 | # SPDX-License-Identifier: LicenseRef-ONF-Member-1.01 |
| 4 | # |
| 5 | define PROJECT_HELP_MSG |
| 6 | Usage: |
| 7 | make help show this message |
| 8 | make clean remove intermediate files |
| 9 | make test |
| 10 | endef |
| 11 | export PROJECT_HELP_MSG |
| 12 | |
| 13 | SHELL = bash -eu -o pipefail |
| 14 | |
| 15 | VERSION ?= $(shell cat ./VERSION) |
| 16 | CONTAINER_NAME ?= $(notdir $(abspath .)) |
| 17 | |
| 18 | DOCKER_REGISTRY ?= |
| 19 | DOCKER_REPOSITORY ?= |
| 20 | DOCKER_BUILD_ARGS ?= --rm --force-rm |
| 21 | DOCKER_TAG ?= ${VERSION} |
| 22 | DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG} |
| 23 | |
| 24 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 25 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 26 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 27 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 28 | |
| 29 | VENV = venv |
| 30 | PYTHON = $(VENV)/bin/python3 |
| 31 | PIP = $(VENV)/bin/pip |
| 32 | |
| 33 | all: test |
| 34 | |
| 35 | help: |
| 36 | echo "$$PROJECT_HELP_MSG" | less |
| 37 | |
| 38 | $(VENV): $(VENV)/touchfile |
| 39 | |
| 40 | $(VENV)/touchfile: requirements.txt |
| 41 | test -d $(VENV) || python3 -m venv $(VENV) |
| 42 | . $(VENV)/bin/activate; pip install -Ur requirements.txt |
| 43 | touch $(VENV)/touchfile |
| 44 | |
| 45 | $(VENV)/bin/activate: requirements.txt |
| 46 | python3 -m venv $(VENV) |
| 47 | $(PIP) install -r requirements.txt |
| 48 | |
| 49 | freeze: |
| 50 | pip3 freeze | grep -v "pkg-resources" > requirements.txt |
| 51 | |
| 52 | docker-build: $(VENV) |
| 53 | docker build $(DOCKER_BUILD_ARGS) \ |
| 54 | -t $(DOCKER_IMAGENAME) \ |
| 55 | --build-arg org_label_schema_version="${VERSION}" \ |
| 56 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 57 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 58 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 59 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 60 | -f docker/Dockerfile . |
| 61 | |
| 62 | docker-push: |
| 63 | docker push $(DOCKER_IMAGENAME) |
| 64 | |
| 65 | docker-run: |
| 66 | docker run \ |
| 67 | -itu root:root \ |
| 68 | --privileged \ |
| 69 | --network host \ |
| 70 | --name $(CONTAINER_NAME) \ |
| 71 | --rm \ |
| 72 | $(DOCKER_IMAGENAME) |
| 73 | |
| 74 | lint: |
| 75 | flake8 --exclude=.tox network_diag |
| 76 | |
| 77 | test: docker-build |
| 78 | |
| 79 | |
| 80 | CLEANUP = *.pyc $(VENV) |
| 81 | clean: |
| 82 | rm -rf ${CLEANUP} |
| 83 | |
| 84 | .PHONY: run clean |
| 85 | |