blob: 6cec29ca0868ad7d0af37fcfd6f325d8b20e8d7a [file] [log] [blame]
Chip Bolingf5af85d2019-02-12 15:36:17 -06001#
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
17ifeq ($(TAG),)
18TAG := latest
19endif
20
21ifeq ($(TARGET_TAG),)
22TARGET_TAG := latest
23endif
24
25ifneq ($(http_proxy)$(https_proxy),)
26# Include proxies from the environment
27DOCKER_PROXY_ARGS = \
28 --build-arg http_proxy=$(http_proxy) \
29 --build-arg https_proxy=$(https_proxy) \
30 --build-arg ftp_proxy=$(ftp_proxy) \
31 --build-arg no_proxy=$(no_proxy) \
32 --build-arg HTTP_PROXY=$(HTTP_PROXY) \
33 --build-arg HTTPS_PROXY=$(HTTPS_PROXY) \
34 --build-arg FTP_PROXY=$(FTP_PROXY) \
35 --build-arg NO_PROXY=$(NO_PROXY)
36endif
37
38DOCKER_BUILD_ARGS = \
39 --build-arg TAG=$(TAG) \
40 --build-arg REGISTRY=$(REGISTRY) \
41 --build-arg REPOSITORY=$(REPOSITORY) \
42 $(DOCKER_PROXY_ARGS) $(DOCKER_CACHE_ARG) \
43 --rm --force-rm \
44 $(DOCKER_BUILD_EXTRA_ARGS)
45
Chip Bolingf5af85d2019-02-12 15:36:17 -060046DOCKER_IMAGE_LIST = \
47 voltha-adtran-base \
Chip Bolingf5af85d2019-02-12 15:36:17 -060048 voltha-adapter-adtran-olt
Chip Bolingd2d7a4d2019-03-14 14:34:56 -050049 # voltha-adapter-adtran-onu \
Chip Bolingf5af85d2019-02-12 15:36:17 -060050
Chip Bolingd2d7a4d2019-03-14 14:34:56 -050051VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
52VENV_BIN ?= virtualenv
53VENV_OPTS ?= -v
54
55PYVOLTHA_DIR ?= ../pyvoltha
56VOLTHA_PROTO_DIR ?= ../voltha-protos
57
58.PHONY: $(DIRS) $(DIRS_CLEAN) base adtran_olt adtran_onu tag push pull
Chip Bolingf5af85d2019-02-12 15:36:17 -060059
60# This should to be the first and default target in this Makefile
61help:
62 @echo "Usage: make [<target>]"
63 @echo "where available targets are:"
64 @echo
65 @echo "build : Build the Adapter and docker images.\n\
66 If this is the first time you are building, choose \"make build\" option."
67 @echo "clean : Remove files created by the build and tests"
68 @echo "distclean : Remove venv directory"
Chip Bolingf5af85d2019-02-12 15:36:17 -060069 @echo "help : Print this help"
Chip Bolingd2d7a4d2019-03-14 14:34:56 -050070 @echo "rebuild-venv : Rebuild local Pythozn virtualenv from scratch"
Chip Bolingf5af85d2019-02-12 15:36:17 -060071 @echo "venv : Build local Python virtualenv if did not exist yet"
72 @echo "containers : Build all the docker containers"
73 @echo "base : Build the base docker container used by all other dockers"
74 @echo "adapter_adtran_olt : Build the ADTRAN olt adapter docker container"
75 @echo "adapter_adtran_onu : Build the ADTRAN olt adapter docker container"
76 @echo "tag : Tag a set of images"
77 @echo "push : Push the docker images to an external repository"
78 @echo "pull : Pull the docker images from a repository"
79 @echo
80
81build: containers
82
Chip Bolingd2d7a4d2019-03-14 14:34:56 -050083# containers: base adapter_adtran_olt adapter_adtran_onu olt_only onu_only
84containers: base adapter_adtran_olt olt_only
Chip Bolingf5af85d2019-02-12 15:36:17 -060085
86base:
87ifdef LOCAL_PYVOLTHA
88 @rm -f pyvoltha/dist/*
89 @mkdir -p pyvoltha/dist
90 cp $(PYVOLTHA_DIR)/dist/*.tar.gz pyvoltha/dist/
Chip Bolingd2d7a4d2019-03-14 14:34:56 -050091 @rm -f voltha-protos/*
92 mkdir -p voltha-protos/dist
93 cp $(VOLTHA_PROTO_DIR)/dist/*.tar.gz voltha-protos/dist/
Chip Bolingf5af85d2019-02-12 15:36:17 -060094 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adtran-base-local:${TAG} -f docker/Dockerfile.base_local .
95else
96 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adtran-base:${TAG} -f docker/Dockerfile.base .
97endif
98
99adapter_adtran_olt: base
100ifdef PYVOLTHA_BASE_IMAGE
101 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-olt:${TAG} -f docker/Dockerfile.adapter_adtran_olt_pyvoltha .
102else
103 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-olt:${TAG} -f docker/Dockerfile.adapter_adtran_olt .
104endif
105
106adapter_adtran_onu: base
107ifdef PYVOLTHA_BASE_IMAGE
108 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-onu:${TAG} -f docker/Dockerfile.adapter_adtran_onu_pyvoltha .
109else
110 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-onu:${TAG} -f docker/Dockerfile.adapter_adtran_onu .
111endif
112
Chip Bolingd2d7a4d2019-03-14 14:34:56 -0500113olt_only: base
114ifdef PYVOLTHA_BASE_IMAGE
115 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-olt:${TAG} -f docker/Dockerfile.adapter_adtran_olt_pyvoltha .
116else
117 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-olt:${TAG} -f docker/Dockerfile.adapter_adtran_olt .
118endif
119
120onu_only:
121ifdef PYVOLTHA_BASE_IMAGE
122 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-onu:${TAG} -f docker/Dockerfile.adapter_adtran_onu_pyvoltha .
123else
124 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-onu:${TAG} -f docker/Dockerfile.adapter_adtran_onu .
125endif
126
Chip Bolingf5af85d2019-02-12 15:36:17 -0600127tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST))
128
129push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST))
130
131pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST))
132
133%.tag:
134 docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG}
135
136%.push:
137 docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG}
138
139%.pull:
140 docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
141
142clean:
Chip Bolingf5af85d2019-02-12 15:36:17 -0600143 rm -rf pyvoltha
Chip Bolingd2d7a4d2019-03-14 14:34:56 -0500144 rm -rf voltha-protos
145 find . -name '*.pyc' | xargs rm -f
Chip Bolingf5af85d2019-02-12 15:36:17 -0600146
147distclean: clean
148 rm -rf ${VENVDIR}
149
150purge-venv:
151 rm -fr ${VENVDIR}
152
153rebuild-venv: purge-venv venv
154
155venv: ${VENVDIR}/.built
156
157${VENVDIR}/.built:
158 @ $(VENV_BIN) ${VENV_OPTS} ${VENVDIR}
159 @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR}
160 @ . ${VENVDIR}/bin/activate && \
161 pip install --upgrade pip; \
162 if ! pip install -r requirements.txt; \
163 then \
164 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
165 echo "see the BUILD.md file for a workaround"; \
166 else \
167 uname -s > ${VENVDIR}/.built; \
168 fi
169 @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR}
170
171ifdef LOCAL_PYVOLTHA
172 mkdir -p pyvoltha/dist
Chip Bolingd2d7a4d2019-03-14 14:34:56 -0500173 cp $(PYVOLTHA_DIR)/dist/*.tar.gz pyvoltha/dist/
174 mkdir -p voltha-protos/dist
175 cp $(VOLTHA_PROTO_DIR)/dist/*.tar.gz voltha-protos/dist/
Chip Bolingf5af85d2019-02-12 15:36:17 -0600176 @ . ${VENVDIR}/bin/activate && \
Chip Bolingd2d7a4d2019-03-14 14:34:56 -0500177 pip install pyvoltha/dist/*.tar.gz && \
178 pip install voltha-protos/dist/*.tar.gz
Chip Bolingf5af85d2019-02-12 15:36:17 -0600179endif
180
181# end file