blob: 4fd5fe221f7349e999805b5ac6f8cb1184d9d257 [file] [log] [blame]
khenaidoo9a468962018-09-19 15:33:13 -04001#
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 Jeanneret2e3051a2019-05-11 15:01:46 -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}
28OFAGENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent:${DOCKER_TAG}
29CLI_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli:${DOCKER_TAG}
30PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt:${DOCKER_TAG}
31PONSIMONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-onu:${DOCKER_TAG}
32
33## Docker labels. Only set ref and commit date if committed
34DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
35DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
36DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
37
38ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
39 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
40else
41 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
khenaidoo9a468962018-09-19 15:33:13 -040042endif
43
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040044.PHONY: venv ofagent cli adapter_ponsim_olt adapter_ponsim_onu local-protos local-pyvoltha
khenaidoo9a468962018-09-19 15:33:13 -040045
46# This should to be the first and default target in this Makefile
47help:
48 @echo "Usage: make [<target>]"
49 @echo "where available targets are:"
50 @echo
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040051 @echo "build : Build all docker images"
52 @echo " - If this is the first time you are building, choose 'make build' option."
53 @echo "help : Print this help"
54 @echo "ofagent : Build the openflow agent docker image"
55 @echo "cli : Build the voltha CLI docker image"
56 @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker image"
57 @echo "adapter_ponsim_onu : Build the ponsim onu adapter docker image"
58 @echo "docker-push : Push the docker images to an external repository"
59 @echo "venv : Build local Python virtualenv"
60 @echo "clean : Remove files created by the build and tests"
61 @echo "distclean : Remove venv directory"
khenaidoo9a468962018-09-19 15:33:13 -040062 @echo
63
khenaidoo9a468962018-09-19 15:33:13 -040064
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040065## Docker targets
khenaidoo9a468962018-09-19 15:33:13 -040066
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040067build: docker-build
khenaidoo9a468962018-09-19 15:33:13 -040068
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040069docker-build: ofagent cli adapter_ponsim_olt adapter_ponsim_onu
khenaidoo9a468962018-09-19 15:33:13 -040070
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040071local-protos:
72 mkdir -p local_imports
73ifdef LOCAL_PROTOS
74 mkdir -p local_imports/voltha-protos/dist
75 cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
76endif
khenaidoo9a468962018-09-19 15:33:13 -040077
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040078local-pyvoltha:
William Kurkianfc0dcda2019-04-08 16:54:36 -040079 mkdir -p local_imports
Arun Aroraed4b7602019-04-02 18:42:37 +000080ifdef LOCAL_PYVOLTHA
William Kurkianfc0dcda2019-04-08 16:54:36 -040081 mkdir -p local_imports/pyvoltha/dist
82 cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
Arun Aroraed4b7602019-04-02 18:42:37 +000083endif
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040084
85ofagent: local-protos local-pyvoltha
86 docker build $(DOCKER_BUILD_ARGS) \
87 -t ${OFAGENT_IMAGENAME} \
88 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
89 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
90 --build-arg org_label_schema_version="${VERSION}" \
91 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
92 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
93 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
94 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
95 -f docker/Dockerfile.ofagent .
96
97cli: local-protos local-pyvoltha
98 docker build $(DOCKER_BUILD_ARGS) \
99 -t ${CLI_IMAGENAME} \
100 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
101 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
102 --build-arg org_label_schema_version="${VERSION}" \
103 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
104 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
105 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
106 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
107 -f docker/Dockerfile.cli .
108
109adapter_ponsim_olt: local-protos local-pyvoltha
110 docker build $(DOCKER_BUILD_ARGS) \
111 -t ${PONSIMOLT_IMAGENAME} \
112 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
113 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
114 --build-arg org_label_schema_version="${VERSION}" \
115 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
116 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
117 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
118 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
119 -f docker/Dockerfile.adapter_ponsim_olt .
120
121adapter_ponsim_onu: local-protos local-pyvoltha
122 docker build $(DOCKER_BUILD_ARGS) \
123 -t ${PONSIMONU_IMAGENAME} \
124 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
125 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
126 --build-arg org_label_schema_version="${VERSION}" \
127 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
128 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
129 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
130 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
131 -f docker/Dockerfile.adapter_ponsim_onu .
132
133docker-push:
134 docker push ${OFAGENT_IMAGENAME}
135 docker push ${CLI_IMAGENAME}
136 docker push ${PONSIMOLT_IMAGENAME}
137 docker push ${PONSIMONU_IMAGENAME}
138
139
140## Python venv dev environment
141
142VENVDIR := venv-volthago
143
144venv: distclean local-protos local-pyvoltha
145 virtualenv ${VENVDIR};\
146 source ./${VENVDIR}/bin/activate ; set -u ;\
147 rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
148 pip install -r requirements.txt
149
150ifdef LOCAL_PYVOLTHA
151 source ./${VENVDIR}/bin/activate ; set -u ;\
152 pip install local_imports/pyvoltha/dist/*.tar.gz
William Kurkianfc0dcda2019-04-08 16:54:36 -0400153endif
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400154ifdef LOCAL_PROTOS
155 source ./${VENVDIR}/bin/activate ; set -u ;\
156 pip install local_imports/voltha-protos/dist/*.tar.gz
157endif
khenaidoo9a468962018-09-19 15:33:13 -0400158
khenaidoo9a468962018-09-19 15:33:13 -0400159clean:
William Kurkianfc0dcda2019-04-08 16:54:36 -0400160 rm -rf local_imports
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400161 find . -name '*.pyc' | xargs rm -f
khenaidoo9a468962018-09-19 15:33:13 -0400162
163distclean: clean
164 rm -rf ${VENVDIR}
165
khenaidoo9a468962018-09-19 15:33:13 -0400166# end file