blob: d7c4a1bc5bf82ea2b66b6adcd2ea500934f72656 [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
17ifneq ($(VOLTHA_BUILD),docker)
18ifeq ($(VOLTHA_BASE)_set,_set)
19$(error To get started, please source the env.sh file)
20endif
21endif
22
23ifeq ($(TAG),)
24TAG := latest
25endif
26
27ifeq ($(TARGET_TAG),)
28TARGET_TAG := latest
29endif
30
31# If no DOCKER_HOST_IP is specified grab a v4 IP address associated with
32# the default gateway
33ifeq ($(DOCKER_HOST_IP),)
34DOCKER_HOST_IP := $(shell ifconfig $$(netstat -rn | grep -E '^(default|0.0.0.0)' | head -1 | awk '{print $$NF}') | grep inet | awk '{print $$2}' | sed -e 's/addr://g')
35endif
36
37ifneq ($(http_proxy)$(https_proxy),)
38# Include proxies from the environment
39DOCKER_PROXY_ARGS = \
40 --build-arg http_proxy=$(http_proxy) \
41 --build-arg https_proxy=$(https_proxy) \
42 --build-arg ftp_proxy=$(ftp_proxy) \
43 --build-arg no_proxy=$(no_proxy) \
44 --build-arg HTTP_PROXY=$(HTTP_PROXY) \
45 --build-arg HTTPS_PROXY=$(HTTPS_PROXY) \
46 --build-arg FTP_PROXY=$(FTP_PROXY) \
47 --build-arg NO_PROXY=$(NO_PROXY)
48endif
49
50DOCKER_BUILD_ARGS = \
51 --build-arg TAG=$(TAG) \
52 --build-arg REGISTRY=$(REGISTRY) \
53 --build-arg REPOSITORY=$(REPOSITORY) \
54 $(DOCKER_PROXY_ARGS) $(DOCKER_CACHE_ARG) \
55 --rm --force-rm \
56 $(DOCKER_BUILD_EXTRA_ARGS)
57
58VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
59
60DOCKER_IMAGE_LIST = \
61 base \
62 protoc \
63 protos \
64 adapter-ponsim-olt \
Matt Jeanneretf4d4d352019-02-14 11:26:13 -050065 adapter-ponsim-onu
khenaidoo9a468962018-09-19 15:33:13 -040066
67# The following list was scavanged from the compose / stack files as well as
68# from the Dockerfiles. If nothing else it highlights that VOLTHA is not
69# using consistent versions for some of the containers.
70
71FETCH_BUILD_IMAGE_LIST = \
72 alpine:3.6 \
73 centos:7 \
74 centurylink/ca-certs:latest \
75 grpc/python:latest \
76 ubuntu:xenial
77
78FETCH_COMPOSE_IMAGE_LIST = \
79 wurstmeister/kafka:latest \
80 wurstmeister/zookeeper:latest
81
82# find k8s -type f | xargs grep image: | awk '{print $NF}' | sed -e 's/\"//g' | sed '/:.*$/!s/$/:latest/g' | sort -u | sed -e 's/^/ /g' -e 's/$/ \\/g'
83# Manually remove some image from this list as they don't reflect the new
84# naming conventions for the VOLTHA build
85FETCH_K8S_IMAGE_LIST = \
86 wurstmeister/kafka:1.0.0 \
87 zookeeper:3.4.11
88
89FETCH_IMAGE_LIST = $(shell echo $(FETCH_BUILD_IMAGE_LIST) $(FETCH_COMPOSE_IMAGE_LIST) $(FETCH_K8S_IMAGE_LIST) | tr ' ' '\n' | sort -u)
90
Matt Jeanneretf4d4d352019-02-14 11:26:13 -050091.PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 base ponsim_olt ponsim_onu protos cli ofagent kafka common start stop tag push pull
khenaidoo9a468962018-09-19 15:33:13 -040092
93# This should to be the first and default target in this Makefile
94help:
95 @echo "Usage: make [<target>]"
96 @echo "where available targets are:"
97 @echo
98 @echo "build : Build the Adapters protos and docker images.\n\
99 If this is the first time you are building, choose \"make build\" option."
100 @echo "clean : Remove files created by the build and tests"
101 @echo "distclean : Remove venv directory"
102 @echo "fetch : Pre-fetch artifacts for subsequent local builds"
103 @echo "help : Print this help"
104 @echo "protoc : Build a container with protoc installed"
105 @echo "protos : Compile all grpc/protobuf files"
106 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
107 @echo "venv : Build local Python virtualenv if did not exist yet"
108 @echo "containers : Build all the docker containers"
109 @echo "base : Build the base docker container used by all other dockers"
110 @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker container"
111 @echo "adapter_ponsim_onu : Build the ponsim olt adapter docker container"
Matt Jeanneret13643e02019-01-30 16:49:03 -0500112 @echo "ofagent : Build the openflow agent docker container"
khenaidoo9a468962018-09-19 15:33:13 -0400113 @echo "tag : Tag a set of images"
114 @echo "push : Push the docker images to an external repository"
115 @echo "pull : Pull the docker images from a repository"
116 @echo
117
118## New directories can be added here
119#DIRS:=
120
121## If one directory depends on another directory that
122## dependency can be expressed here
123##
124## For example, if the Tibit directory depended on the eoam
125## directory being built first, then that can be expressed here.
126## driver/tibit: eoam
127
128# Parallel Build
129$(DIRS):
130 @echo " MK $@"
131 $(Q)$(MAKE) -C $@
132
133# Parallel Clean
134DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
135$(DIRS_CLEAN):
136 @echo " CLEAN $(basename $@)"
137 $(Q)$(MAKE) -C $(basename $@) clean
138
139# Parallel Flake8
140DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS))
141$(DIRS_FLAKE8):
142 @echo " FLAKE8 $(basename $@)"
143 -$(Q)$(MAKE) -C $(basename $@) flake8
144
145build: protoc protos containers
146
Matt Jeanneretf4d4d352019-02-14 11:26:13 -0500147containers: base adapter_ponsim_olt adapter_ponsim_onu ofagent cli
khenaidoo9a468962018-09-19 15:33:13 -0400148
149base:
Arun Aroraed4b7602019-04-02 18:42:37 +0000150ifdef LOCAL_PYVOLTHA
151 mkdir -p pyvoltha/dist
152 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
153 mkdir -p voltha-protos/dist
154 cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
155 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-base:${TAG} -f docker/Dockerfile.base_local .
156else
khenaidoo9a468962018-09-19 15:33:13 -0400157 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-base:${TAG} -f docker/Dockerfile.base .
Arun Aroraed4b7602019-04-02 18:42:37 +0000158endif
khenaidoo9a468962018-09-19 15:33:13 -0400159
160adapter_ponsim_olt:
161 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-ponsim-olt:${TAG} -f docker/Dockerfile.adapter_ponsim_olt .
162
163adapter_ponsim_onu:
164 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-ponsim-onu:${TAG} -f docker/Dockerfile.adapter_ponsim_onu .
165
Stephane Barbariedf5479f2019-01-29 22:13:00 -0500166ofagent:
167 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ofagent:${TAG} -f docker/Dockerfile.ofagent .
168
khenaidoofdbad6e2018-11-06 22:26:38 -0500169cli:
170 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-cli:${TAG} -f docker/Dockerfile.cli .
171
khenaidoo9a468962018-09-19 15:33:13 -0400172tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST))
173
174push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST))
175
176pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST))
177
178%.tag:
179 docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG}
180
181%.push:
182 docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG}
183
184%.pull:
185 docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
186
187protoc:
188ifeq ($(VOLTHA_BUILD),docker)
189 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-protoc:${TAG} -f docker/Dockerfile.protoc .
190endif
191
192protos:
193ifneq ($(VOLTHA_BUILD),docker)
194 make -C protos
195else
William Kurkiandaa6bb22019-03-07 12:26:28 -0500196 #cp ../protos/*.proto ./protos
khenaidoo9a468962018-09-19 15:33:13 -0400197 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-protos:${TAG} -f docker/Dockerfile.protos .
198endif
199
200install-protoc:
201 make -C voltha/protos install-protoc
202
203clean:
khenaidoo79232702018-12-04 11:00:41 -0500204 find . -name '*.pyc' | xargs rm -f
205 rm -f ./protos/*_pb2.py
206 rm -f ./protos/*_pb2_grpc.py
207 rm -f ./protos/*.desc
208 rm -f ./protos/*.proto
Arun Aroraed4b7602019-04-02 18:42:37 +0000209 rm -rf pyvoltha
210 rm -rf voltha-protos
khenaidoo9a468962018-09-19 15:33:13 -0400211
212distclean: clean
213 rm -rf ${VENVDIR}
214
215fetch:
216 @bash -c ' \
217 for i in $(FETCH_IMAGE_LIST); do \
218 docker pull $$i; \
219 done'
220
221purge-venv:
222 rm -fr ${VENVDIR}
223
224rebuild-venv: purge-venv venv
225
226ifneq ($(VOLTHA_BUILD),docker)
227venv: ${VENVDIR}/.built
228else
229venv:
230endif
231
232${VENVDIR}/.built:
233 @ virtualenv ${VENVDIR}
234 @ . ${VENVDIR}/bin/activate && \
235 pip install --upgrade pip; \
236 if ! pip install -r requirements.txt; \
237 then \
238 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
239 echo "see the BUILD.md file for a workaround"; \
240 else \
241 uname -s > ${VENVDIR}/.built; \
242 fi
243
Arun Aroraed4b7602019-04-02 18:42:37 +0000244ifdef LOCAL_PYVOLTHA
245 mkdir -p pyvoltha/dist
246 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
247 mkdir -p voltha-protos/dist
248 cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
249 . ${VENVDIR}/bin/activate && \
250 pip install pyvoltha/dist/*.tar.gz && \
251 pip install voltha-protos/dist/*.tar.gz
252endif
khenaidoo9a468962018-09-19 15:33:13 -0400253
254flake8: $(DIRS_FLAKE8)
255
256# end file