blob: e4d78bed3299a38e28c2b5136d813ddb3d5de4cc [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 \
Shad Ansari1dcfdb32022-01-24 23:13:06 +000067 --name $(CONTAINER_NAME) \
68 --rm \
Shad Ansarif44f3f22022-01-31 20:26:30 +000069 $(DOCKER_IMAGENAME) \
70 --user="abc" --password="xyz"
Shad Ansari1dcfdb32022-01-24 23:13:06 +000071
72lint:
73 flake8 --exclude=.tox network_diag
74
75test: docker-build
76
77
78CLEANUP = *.pyc $(VENV)
79clean:
80 rm -rf ${CLEANUP}
81
82.PHONY: run clean
83