William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -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 | 8b823f6 | 2019-05-11 11:01:28 -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-openolt-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 |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 39 | endif |
| 40 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 41 | .PHONY: venv docker-build local-protos local-pyvoltha |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -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 | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 48 | @echo "build : Build the openolt 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 | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 52 | @echo "clean : Remove files created by the build and tests" |
| 53 | @echo "distclean : Remove venv directory" |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 54 | @echo |
| 55 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 56 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 57 | ## Docker targets |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 58 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 59 | build: docker-build |
| 60 | |
| 61 | local-protos: |
| 62 | mkdir -p local_imports |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame] | 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 |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 67 | |
| 68 | local-pyvoltha: |
| 69 | mkdir -p local_imports |
| 70 | ifdef LOCAL_PYVOLTHA |
| 71 | mkdir -p local_imports/pyvoltha/dist |
| 72 | cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/ |
| 73 | endif |
| 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.openolt_adapter . |
| 86 | |
| 87 | docker-push: |
| 88 | docker push ${ADAPTER_IMAGENAME} |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame] | 89 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 90 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 91 | ## Python venv dev environment |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 92 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 93 | VENVDIR := venv-openolt |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 94 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 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 |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 100 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 101 | ifdef LOCAL_PYVOLTHA |
| 102 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 103 | pip install local_imports/pyvoltha/dist/*.tar.gz |
| 104 | endif |
| 105 | ifdef LOCAL_PROTOS |
| 106 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 107 | pip install local_imports/voltha-protos/dist/*.tar.gz |
| 108 | endif |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 109 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 110 | clean: |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame] | 111 | rm -rf local_imports |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 112 | find . -name '*.pyc' | xargs rm -f |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 113 | |
| 114 | distclean: clean |
| 115 | rm -rf ${VENVDIR} |
| 116 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 117 | # end file |