blob: 9c81ed04eb1aed531f141e36f11f03de3abd6b90 [file] [log] [blame]
William Kurkian6f436d02019-02-06 16:25:01 -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 Jeanneret8b823f62019-05-11 11:01:28 -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-openolt-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
William Kurkian6f436d02019-02-06 16:25:01 -050039endif
40
Matt Jeanneret8b823f62019-05-11 11:01:28 -040041.PHONY: venv docker-build local-protos local-pyvoltha
William Kurkian6f436d02019-02-06 16:25:01 -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 Jeanneret8b823f62019-05-11 11:01:28 -040048 @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 Jeanneretf35be112019-03-05 10:58:57 -050052 @echo "clean : Remove files created by the build and tests"
53 @echo "distclean : Remove venv directory"
William Kurkian6f436d02019-02-06 16:25:01 -050054 @echo
55
William Kurkian6f436d02019-02-06 16:25:01 -050056
Matt Jeanneret8b823f62019-05-11 11:01:28 -040057## Docker targets
William Kurkian44cd7bb2019-02-11 16:39:12 -050058
Matt Jeanneret8b823f62019-05-11 11:01:28 -040059build: docker-build
60
61local-protos:
62 mkdir -p local_imports
William Kurkiane5301042019-04-09 16:49:36 -040063ifdef LOCAL_PROTOS
64 mkdir -p local_imports/voltha-protos/dist
65 cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
66endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040067
68local-pyvoltha:
69 mkdir -p local_imports
70ifdef LOCAL_PYVOLTHA
71 mkdir -p local_imports/pyvoltha/dist
72 cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
73endif
74
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.openolt_adapter .
86
87docker-push:
88 docker push ${ADAPTER_IMAGENAME}
William Kurkiane5301042019-04-09 16:49:36 -040089
William Kurkian44cd7bb2019-02-11 16:39:12 -050090
Matt Jeanneret8b823f62019-05-11 11:01:28 -040091## Python venv dev environment
William Kurkian6f436d02019-02-06 16:25:01 -050092
Matt Jeanneret8b823f62019-05-11 11:01:28 -040093VENVDIR := venv-openolt
William Kurkian6f436d02019-02-06 16:25:01 -050094
Matt Jeanneret8b823f62019-05-11 11:01:28 -040095venv: 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 Kurkian6f436d02019-02-06 16:25:01 -0500100
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400101ifdef LOCAL_PYVOLTHA
102 source ./${VENVDIR}/bin/activate ; set -u ;\
103 pip install local_imports/pyvoltha/dist/*.tar.gz
104endif
105ifdef LOCAL_PROTOS
106 source ./${VENVDIR}/bin/activate ; set -u ;\
107 pip install local_imports/voltha-protos/dist/*.tar.gz
108endif
William Kurkian6f436d02019-02-06 16:25:01 -0500109
William Kurkian6f436d02019-02-06 16:25:01 -0500110clean:
William Kurkiane5301042019-04-09 16:49:36 -0400111 rm -rf local_imports
William Kurkian6f436d02019-02-06 16:25:01 -0500112 find . -name '*.pyc' | xargs rm -f
William Kurkian6f436d02019-02-06 16:25:01 -0500113
114distclean: clean
115 rm -rf ${VENVDIR}
116
William Kurkian6f436d02019-02-06 16:25:01 -0500117# end file