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