blob: 8e54fc44e3f6e59efe2fcfc185b6f4e8165c38ea [file] [log] [blame]
Shad Ansari1dcfdb32022-01-24 23:13:06 +00001#
2# SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
3# SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
4#
5define PROJECT_HELP_MSG
6Usage:
7 make help show this message
8 make clean remove intermediate files
9 make test
10endef
11export PROJECT_HELP_MSG
12
13SHELL = bash -eu -o pipefail
14
15VERSION ?= $(shell cat ./VERSION)
16CONTAINER_NAME ?= $(notdir $(abspath .))
17
18DOCKER_REGISTRY ?=
19DOCKER_REPOSITORY ?=
20DOCKER_BUILD_ARGS ?= --rm --force-rm
21DOCKER_TAG ?= ${VERSION}
22DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
23
24DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
25DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
26DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
27DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
28
29VENV = venv
30PYTHON = $(VENV)/bin/python3
31PIP = $(VENV)/bin/pip
32
33all: test
34
35help:
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
49freeze:
50 pip3 freeze | grep -v "pkg-resources" > requirements.txt
51
52docker-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
62docker-push:
63 docker push $(DOCKER_IMAGENAME)
64
65docker-run:
66 docker run \
67 -itu root:root \
68 --privileged \
69 --network host \
70 --name $(CONTAINER_NAME) \
71 --rm \
72 $(DOCKER_IMAGENAME)
73
74lint:
75 flake8 --exclude=.tox network_diag
76
77test: docker-build
78
79
80CLEANUP = *.pyc $(VENV)
81clean:
82 rm -rf ${CLEANUP}
83
84.PHONY: run clean
85