blob: c50531949c7840eef4b6f228307d500795ca1985 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
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 Jeanneret134d9e82019-05-08 15:45:10 -040017# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ../VERSION)
22
23## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openonu-adapter:${DOCKER_TAG}
29
30## Docker labels. Only set ref and commit date if committed
31DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
32DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
33DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
34
35ifeq ($(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)
37else
38 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050039endif
40
Matt Jeanneret134d9e82019-05-08 15:45:10 -040041.PHONY: venv docker-build local-protos local-pyvoltha
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050042
43# This should to be the first and default target in this Makefile
44help:
45 @echo "Usage: make [<target>]"
46 @echo "where available targets are:"
47 @echo
Matt Jeanneret134d9e82019-05-08 15:45:10 -040048 @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 Jeanneret18949ae2019-02-09 15:00:14 -050052 @echo "clean : Remove files created by the build and tests"
53 @echo "distclean : Remove venv directory"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050054 @echo
55
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050056
Matt Jeanneret134d9e82019-05-08 15:45:10 -040057## Docker targets
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050058
Matt Jeanneret134d9e82019-05-08 15:45:10 -040059build: docker-build
60
Zack Williamsd3a56c42019-05-17 15:44:35 -070061# only test is that the docker container builds
62test: docker-build
63
64local-protos:
Matt Jeanneret134d9e82019-05-08 15:45:10 -040065 mkdir -p local_imports
66ifdef LOCAL_PROTOS
67 mkdir -p local_imports/voltha-protos/dist
William Kurkianeffdbf52019-11-13 16:01:09 -050068 cp ${LOCAL_PROTOS}/dist/*.tar.gz local_imports/voltha-protos/dist/
Matt Jeanneret134d9e82019-05-08 15:45:10 -040069endif
70
71local-pyvoltha:
William Kurkian07271552019-04-09 16:52:06 -040072 mkdir -p local_imports
Matt Jeanneret18949ae2019-02-09 15:00:14 -050073ifdef LOCAL_PYVOLTHA
William Kurkian07271552019-04-09 16:52:06 -040074 mkdir -p local_imports/pyvoltha/dist
William Kurkianeffdbf52019-11-13 16:01:09 -050075 cp ${LOCAL_PYVOLTHA}/dist/*.tar.gz local_imports/pyvoltha/dist/
Matt Jeanneret18949ae2019-02-09 15:00:14 -050076endif
Matt Jeanneret134d9e82019-05-08 15:45:10 -040077
78docker-build: local-protos local-pyvoltha
79 docker build $(DOCKER_BUILD_ARGS) \
80 -t ${ADAPTER_IMAGENAME} \
81 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
82 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
83 --build-arg org_label_schema_version="${VERSION}" \
84 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
85 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
86 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
87 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
88 -f docker/Dockerfile.openonu_adapter .
89
90docker-push:
91 docker push ${ADAPTER_IMAGENAME}
92
93
94## Python venv dev environment
95
96VENVDIR := venv-openonu
97
98venv: distclean local-protos local-pyvoltha
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050099 virtualenv --python=python3.6 ${VENVDIR};\
Matt Jeanneret134d9e82019-05-08 15:45:10 -0400100 source ./${VENVDIR}/bin/activate ; set -u ;\
Matt Jeanneret134d9e82019-05-08 15:45:10 -0400101 pip install -r requirements.txt
102
103ifdef LOCAL_PYVOLTHA
104 source ./${VENVDIR}/bin/activate ; set -u ;\
105 pip install local_imports/pyvoltha/dist/*.tar.gz
106endif
William Kurkian07271552019-04-09 16:52:06 -0400107ifdef LOCAL_PROTOS
Matt Jeanneret134d9e82019-05-08 15:45:10 -0400108 source ./${VENVDIR}/bin/activate ; set -u ;\
109 pip install local_imports/voltha-protos/dist/*.tar.gz
William Kurkian07271552019-04-09 16:52:06 -0400110endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500111
112clean:
William Kurkian07271552019-04-09 16:52:06 -0400113 rm -rf local_imports
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500114 find . -name '*.pyc' | xargs rm -f
115
116distclean: clean
117 rm -rf ${VENVDIR}
118
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500119# end file