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 | |
| 23 | ## Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openonu-adapter:${DOCKER_TAG} |
Andrea Campanella | 442d7e4 | 2019-12-17 15:27:52 -0800 | [diff] [blame] | 29 | TYPE ?= minimal |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 30 | |
| 31 | ## Docker labels. Only set ref and commit date if committed |
| 32 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 33 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 34 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 35 | |
| 36 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 37 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 38 | else |
| 39 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 40 | endif |
| 41 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 42 | .PHONY: venv docker-build local-protos local-pyvoltha |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 43 | |
| 44 | # This should to be the first and default target in this Makefile |
| 45 | help: |
| 46 | @echo "Usage: make [<target>]" |
| 47 | @echo "where available targets are:" |
| 48 | @echo |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 49 | @echo "build : Build the openonu openomci adapter docker image" |
| 50 | @echo "help : Print this help" |
| 51 | @echo "docker-push : Push the docker images to an external repository" |
| 52 | @echo "venv : Build local Python virtualenv" |
Matt Jeanneret | 18949ae | 2019-02-09 15:00:14 -0500 | [diff] [blame] | 53 | @echo "clean : Remove files created by the build and tests" |
| 54 | @echo "distclean : Remove venv directory" |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 55 | @echo |
| 56 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 57 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 58 | ## Docker targets |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 59 | |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 60 | build: docker-build |
| 61 | |
Zack Williams | d3a56c4 | 2019-05-17 15:44:35 -0700 | [diff] [blame] | 62 | # only test is that the docker container builds |
| 63 | test: docker-build |
| 64 | |
| 65 | local-protos: |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 66 | mkdir -p local_imports |
| 67 | ifdef LOCAL_PROTOS |
| 68 | mkdir -p local_imports/voltha-protos/dist |
William Kurkian | effdbf5 | 2019-11-13 16:01:09 -0500 | [diff] [blame] | 69 | cp ${LOCAL_PROTOS}/dist/*.tar.gz local_imports/voltha-protos/dist/ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 70 | endif |
| 71 | |
| 72 | local-pyvoltha: |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 73 | mkdir -p local_imports |
Matt Jeanneret | 18949ae | 2019-02-09 15:00:14 -0500 | [diff] [blame] | 74 | ifdef LOCAL_PYVOLTHA |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 75 | mkdir -p local_imports/pyvoltha/dist |
William Kurkian | effdbf5 | 2019-11-13 16:01:09 -0500 | [diff] [blame] | 76 | cp ${LOCAL_PYVOLTHA}/dist/*.tar.gz local_imports/pyvoltha/dist/ |
Matt Jeanneret | 18949ae | 2019-02-09 15:00:14 -0500 | [diff] [blame] | 77 | endif |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 78 | |
| 79 | docker-build: local-protos local-pyvoltha |
| 80 | docker build $(DOCKER_BUILD_ARGS) \ |
| 81 | -t ${ADAPTER_IMAGENAME} \ |
| 82 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 83 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 84 | --build-arg org_label_schema_version="${VERSION}" \ |
| 85 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 86 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 87 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 88 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 89 | -f docker/Dockerfile.openonu_adapter . |
| 90 | |
| 91 | docker-push: |
| 92 | docker push ${ADAPTER_IMAGENAME} |
| 93 | |
Andrea Campanella | 442d7e4 | 2019-12-17 15:27:52 -0800 | [diff] [blame] | 94 | docker-kind-load: |
| 95 | @if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi |
| 96 | 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] | 97 | ## Python venv dev environment |
| 98 | |
| 99 | VENVDIR := venv-openonu |
| 100 | |
| 101 | venv: distclean local-protos local-pyvoltha |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 102 | virtualenv --python=python3.6 ${VENVDIR};\ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 103 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 104 | pip install -r requirements.txt |
| 105 | |
| 106 | ifdef LOCAL_PYVOLTHA |
| 107 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 108 | pip install local_imports/pyvoltha/dist/*.tar.gz |
| 109 | endif |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 110 | ifdef LOCAL_PROTOS |
Matt Jeanneret | 134d9e8 | 2019-05-08 15:45:10 -0400 | [diff] [blame] | 111 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 112 | pip install local_imports/voltha-protos/dist/*.tar.gz |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 113 | endif |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 114 | |
| 115 | clean: |
William Kurkian | 0727155 | 2019-04-09 16:52:06 -0400 | [diff] [blame] | 116 | rm -rf local_imports |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 117 | find . -name '*.pyc' | xargs rm -f |
| 118 | |
| 119 | distclean: clean |
| 120 | rm -rf ${VENVDIR} |
| 121 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 122 | # end file |