blob: 6833f4b8099ecaa160e4fabfcee97f591dc2686a [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
46VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
47VENV_BIN ?= virtualenv
48VENV_OPTS ?=
49
50PYVOLTHA_DIR ?= ../pyvoltha
51
52DOCKER_IMAGE_LIST = \
53 voltha-adtran-base \
54 voltha-adapter-adtran-onu \
55 voltha-adapter-adtran-olt
56
57.PHONY: base adtran_olt adtran_onu tag push pull
58
59# This should to be the first and default target in this Makefile
60help:
61 @echo "Usage: make [<target>]"
62 @echo "where available targets are:"
63 @echo
64 @echo "build : Build the Adapter and docker images.\n\
65 If this is the first time you are building, choose \"make build\" option."
66 @echo "clean : Remove files created by the build and tests"
67 @echo "distclean : Remove venv directory"
68 @echo "fetch : Pre-fetch artifacts for subsequent local builds"
69 @echo "help : Print this help"
70 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
71 @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
83containers: base adapter_adtran_olt adapter_adtran_onu
84
85base:
86ifdef LOCAL_PYVOLTHA
87 @rm -f pyvoltha/dist/*
88 @mkdir -p pyvoltha/dist
89 cp $(PYVOLTHA_DIR)/dist/*.tar.gz pyvoltha/dist/
90 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adtran-base-local:${TAG} -f docker/Dockerfile.base_local .
91else
92 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adtran-base:${TAG} -f docker/Dockerfile.base .
93endif
94
95adapter_adtran_olt: base
96ifdef PYVOLTHA_BASE_IMAGE
97 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-olt:${TAG} -f docker/Dockerfile.adapter_adtran_olt_pyvoltha .
98else
99 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-olt:${TAG} -f docker/Dockerfile.adapter_adtran_olt .
100endif
101
102adapter_adtran_onu: base
103ifdef PYVOLTHA_BASE_IMAGE
104 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-onu:${TAG} -f docker/Dockerfile.adapter_adtran_onu_pyvoltha .
105else
106 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-adtran-onu:${TAG} -f docker/Dockerfile.adapter_adtran_onu .
107endif
108
109tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST))
110
111push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST))
112
113pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST))
114
115%.tag:
116 docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG}
117
118%.push:
119 docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG}
120
121%.pull:
122 docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
123
124clean:
125 find . -name '*.pyc' | xargs rm -f
126 rm -rf pyvoltha
127
128distclean: clean
129 rm -rf ${VENVDIR}
130
131purge-venv:
132 rm -fr ${VENVDIR}
133
134rebuild-venv: purge-venv venv
135
136venv: ${VENVDIR}/.built
137
138${VENVDIR}/.built:
139 @ $(VENV_BIN) ${VENV_OPTS} ${VENVDIR}
140 @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR}
141 @ . ${VENVDIR}/bin/activate && \
142 pip install --upgrade pip; \
143 if ! pip install -r requirements.txt; \
144 then \
145 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
146 echo "see the BUILD.md file for a workaround"; \
147 else \
148 uname -s > ${VENVDIR}/.built; \
149 fi
150 @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR}
151
152ifdef LOCAL_PYVOLTHA
153 mkdir -p pyvoltha/dist
154 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
155 @ . ${VENVDIR}/bin/activate && \
156 pip install pyvoltha/dist/*.tar.gz
157endif
158
159# end file