blob: 79514ebc999d579e424e38682fe3e638f77cd598 [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
61local-protos:
62 mkdir -p local_imports
63ifdef LOCAL_PROTOS
64 mkdir -p local_imports/voltha-protos/dist
65 cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
66endif
67
68local-pyvoltha:
William Kurkian07271552019-04-09 16:52:06 -040069 mkdir -p local_imports
Matt Jeanneret18949ae2019-02-09 15:00:14 -050070ifdef LOCAL_PYVOLTHA
William Kurkian07271552019-04-09 16:52:06 -040071 mkdir -p local_imports/pyvoltha/dist
72 cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
Matt Jeanneret18949ae2019-02-09 15:00:14 -050073endif
Matt Jeanneret134d9e82019-05-08 15:45:10 -040074
75docker-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
87docker-push:
88 docker push ${ADAPTER_IMAGENAME}
89
90
91## Python venv dev environment
92
93VENVDIR := venv-openonu
94
95venv: 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
101ifdef LOCAL_PYVOLTHA
102 source ./${VENVDIR}/bin/activate ; set -u ;\
103 pip install local_imports/pyvoltha/dist/*.tar.gz
104endif
William Kurkian07271552019-04-09 16:52:06 -0400105ifdef LOCAL_PROTOS
Matt Jeanneret134d9e82019-05-08 15:45:10 -0400106 source ./${VENVDIR}/bin/activate ; set -u ;\
107 pip install local_imports/voltha-protos/dist/*.tar.gz
William Kurkian07271552019-04-09 16:52:06 -0400108endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500109
110clean:
William Kurkian07271552019-04-09 16:52:06 -0400111 rm -rf local_imports
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500112 find . -name '*.pyc' | xargs rm -f
113
114distclean: clean
115 rm -rf ${VENVDIR}
116
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500117# end file