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