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