Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 17 | # set default shell |
| 18 | SHELL = bash -e -o pipefail |
| 19 | |
| 20 | # Variables |
| 21 | VERSION ?= $(shell cat ../VERSION) |
| 22 | |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 23 | DOCKER_LABEL_VCS_DIRTY = false |
| 24 | ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 25 | DOCKER_LABEL_VCS_DIRTY = true |
| 26 | endif |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 27 | ## Docker related |
| 28 | DOCKER_REGISTRY ?= |
| 29 | DOCKER_REPOSITORY ?= |
| 30 | DOCKER_BUILD_ARGS ?= |
| 31 | DOCKER_TAG ?= ${VERSION} |
| 32 | ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openonu-adapter:${DOCKER_TAG} |
Andrea Campanella | 442d7e4 | 2019-12-17 15:27:52 -0800 | [diff] [blame] | 33 | TYPE ?= minimal |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 34 | |
| 35 | ## Docker labels. Only set ref and commit date if committed |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 36 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 37 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 38 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 39 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 40 | |
Andrey Pozolotin | 9981e83 | 2020-08-14 02:50:12 +0200 | [diff] [blame^] | 41 | ## Python tox tests |
| 42 | VOLTHA_TOOLS_VERSION ?= 2.3.0 |
| 43 | TOX = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-python tox |
| 44 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 45 | .PHONY: venv docker-build local-protos local-pyvoltha |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 46 | |
| 47 | # This should to be the first and default target in this Makefile |
| 48 | help: |
| 49 | @echo "Usage: make [<target>]" |
| 50 | @echo "where available targets are:" |
| 51 | @echo |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 52 | @echo "build : Build the openonu openomci adapter docker image" |
| 53 | @echo "help : Print this help" |
| 54 | @echo "docker-push : Push the docker images to an external repository" |
| 55 | @echo "venv : Build local Python virtualenv" |
Matt Jeanneret | 18949ae | 2019-02-09 15:00:14 -0500 | [diff] [blame] | 56 | @echo "clean : Remove files created by the build and tests" |
| 57 | @echo "distclean : Remove venv directory" |
Andrey Pozolotin | 9981e83 | 2020-08-14 02:50:12 +0200 | [diff] [blame^] | 58 | @echo "sca : Starts sca checks" |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 59 | @echo |
| 60 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 61 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 62 | ## Docker targets |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 63 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 64 | build: docker-build |
| 65 | |
Zack Williams | d3a56c4 | 2019-05-17 15:44:35 -0700 | [diff] [blame] | 66 | # only test is that the docker container builds |
| 67 | test: docker-build |
| 68 | |
| 69 | local-protos: |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 70 | mkdir -p local_imports |
| 71 | ifdef LOCAL_PROTOS |
| 72 | mkdir -p local_imports/voltha-protos/dist |
Matt Jeanneret | 5d93626 | 2020-01-29 05:04:14 -0500 | [diff] [blame] | 73 | rm -f local_imports/voltha-protos/dist/*.tar.gz |
William Kurkian | effdbf5 | 2019-11-13 16:01:09 -0500 | [diff] [blame] | 74 | cp ${LOCAL_PROTOS}/dist/*.tar.gz local_imports/voltha-protos/dist/ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 75 | endif |
| 76 | |
| 77 | local-pyvoltha: |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 78 | mkdir -p local_imports |
Matt Jeanneret | 18949ae | 2019-02-09 15:00:14 -0500 | [diff] [blame] | 79 | ifdef LOCAL_PYVOLTHA |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 80 | mkdir -p local_imports/pyvoltha/dist |
Matt Jeanneret | 5d93626 | 2020-01-29 05:04:14 -0500 | [diff] [blame] | 81 | rm -f local_imports/pyvoltha/dist/*.tar.gz |
William Kurkian | effdbf5 | 2019-11-13 16:01:09 -0500 | [diff] [blame] | 82 | cp ${LOCAL_PYVOLTHA}/dist/*.tar.gz local_imports/pyvoltha/dist/ |
Matt Jeanneret | 18949ae | 2019-02-09 15:00:14 -0500 | [diff] [blame] | 83 | endif |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 84 | |
| 85 | docker-build: local-protos local-pyvoltha |
| 86 | docker build $(DOCKER_BUILD_ARGS) \ |
| 87 | -t ${ADAPTER_IMAGENAME} \ |
| 88 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 89 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 90 | --build-arg org_label_schema_version="${VERSION}" \ |
| 91 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 92 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 93 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 94 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
Matt Jeanneret | 08a8e86 | 2019-12-20 14:02:32 -0500 | [diff] [blame] | 95 | --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}" \ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 96 | -f docker/Dockerfile.openonu_adapter . |
| 97 | |
| 98 | docker-push: |
| 99 | docker push ${ADAPTER_IMAGENAME} |
| 100 | |
Andrea Campanella | 442d7e4 | 2019-12-17 15:27:52 -0800 | [diff] [blame] | 101 | docker-kind-load: |
| 102 | @if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi |
| 103 | kind load docker-image ${ADAPTER_IMAGENAME} --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//') |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 104 | ## Python venv dev environment |
| 105 | |
| 106 | VENVDIR := venv-openonu |
| 107 | |
| 108 | venv: distclean local-protos local-pyvoltha |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 109 | virtualenv --python=python3.6 ${VENVDIR};\ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 110 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 111 | pip install -r requirements.txt |
| 112 | |
| 113 | ifdef LOCAL_PYVOLTHA |
| 114 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 115 | pip install local_imports/pyvoltha/dist/*.tar.gz |
| 116 | endif |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 117 | ifdef LOCAL_PROTOS |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 118 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 119 | pip install local_imports/voltha-protos/dist/*.tar.gz |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 120 | endif |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 121 | |
| 122 | clean: |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 123 | rm -rf local_imports |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 124 | find . -name '*.pyc' | xargs rm -f |
| 125 | |
| 126 | distclean: clean |
| 127 | rm -rf ${VENVDIR} |
| 128 | |
Andrey Pozolotin | 9981e83 | 2020-08-14 02:50:12 +0200 | [diff] [blame^] | 129 | sca: |
| 130 | @rm -rf ./sca-report |
| 131 | @mkdir -p ./sca-report |
| 132 | @echo "Running static code analysis..." |
| 133 | @$(TOX) --result-json ./sca-report/sca-report.json |
| 134 | @echo "" |
| 135 | @echo "Static code analysis OK" |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 136 | # end file |