blob: a78ecda381693b895d76a214270522732602bdd6 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050017ifeq ($(TAG),)
18TAG := latest
19endif
20
21ifeq ($(TARGET_TAG),)
22TARGET_TAG := latest
23endif
24
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050025ifneq ($(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
William Kurkian07271552019-04-09 16:52:06 -040046DOCKER_BUILD_EXTRA_ARGS = \
47 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
48 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS)
49
Matt Jeanneret18949ae2019-02-09 15:00:14 -050050DOCKER_IMAGE_LIST = \
51 voltha-openonu-adapter-base \
52 voltha-openonu-adapter
53
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050054VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
55
Matt Jeanneret18949ae2019-02-09 15:00:14 -050056.PHONY: $(DIRS) $(DIRS_CLEAN) base openonu_adapter
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057
58# This should to be the first and default target in this Makefile
59help:
60 @echo "Usage: make [<target>]"
61 @echo "where available targets are:"
62 @echo
Matt Jeanneret18949ae2019-02-09 15:00:14 -050063 @echo "build : Build the adapter."
64 @echo "clean : Remove files created by the build and tests"
65 @echo "distclean : Remove venv directory"
66 @echo "help : Print this help"
67 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
68 @echo "venv : Build local Python virtualenv if did not exist yet"
69 @echo "containers : Build all the docker containers"
70 @echo "base : Build a base docker image with a modern version of pip and requirements.txt installed"
Matt Jeanneret76c98b12019-03-05 11:09:37 -050071 @echo "openonu_adapter : Build the openonu openomci adapter docker container"
Matt Jeanneret18949ae2019-02-09 15:00:14 -050072 @echo "tag : Tag a set of images"
73 @echo "push : Push the docker images to an external repository"
74 @echo "pull : Pull the docker images from a repository"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050075 @echo
76
Matt Jeanneret18949ae2019-02-09 15:00:14 -050077build: containers
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050078
Matt Jeanneret18949ae2019-02-09 15:00:14 -050079containers: base openonu_adapter
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050080
81base:
William Kurkian07271552019-04-09 16:52:06 -040082 mkdir -p local_imports
Matt Jeanneret18949ae2019-02-09 15:00:14 -050083ifdef LOCAL_PYVOLTHA
William Kurkian07271552019-04-09 16:52:06 -040084 mkdir -p local_imports/pyvoltha/dist
85 cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
Matt Jeanneret18949ae2019-02-09 15:00:14 -050086endif
William Kurkian07271552019-04-09 16:52:06 -040087ifdef LOCAL_PROTOS
88 mkdir -p local_imports/voltha-protos/dist
89 cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
90endif
91 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base .
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050092
Matt Jeanneret18949ae2019-02-09 15:00:14 -050093openonu_adapter: base
94ifdef PYVOLTHA_BASE_IMAGE
95 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter:${TAG} -f docker/Dockerfile.openonu_adapter_pyvoltha .
96else
97 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter:${TAG} -f docker/Dockerfile.openonu_adapter .
98endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050099
100tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST))
101
102push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST))
103
104pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST))
105
106%.tag:
107 docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG}
108
109%.push:
110 docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG}
111
112%.pull:
113 docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
114
115clean:
William Kurkian07271552019-04-09 16:52:06 -0400116 rm -rf local_imports
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500117 find . -name '*.pyc' | xargs rm -f
118
119distclean: clean
120 rm -rf ${VENVDIR}
121
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500122purge-venv:
123 rm -fr ${VENVDIR}
124
125rebuild-venv: purge-venv venv
126
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500127venv: ${VENVDIR}/.built
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500128
129${VENVDIR}/.built:
Matt Jeannereta32441c2019-03-07 05:16:37 -0500130 virtualenv -v ${VENVDIR}
131 # these are just symlinks to the other folders in the venv. this makes it appear as if there are duplicate definitions in PYTHONPATH. venv bug?
132 rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include
133 . ${VENVDIR}/bin/activate && \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500134 pip install --upgrade pip; \
135 if ! pip install -r requirements.txt; \
136 then \
137 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
138 echo "see the BUILD.md file for a workaround"; \
139 else \
140 uname -s > ${VENVDIR}/.built; \
141 fi
142
Matt Jeanneret18949ae2019-02-09 15:00:14 -0500143ifdef LOCAL_PYVOLTHA
William Kurkian07271552019-04-09 16:52:06 -0400144 mkdir -p local_imports/pyvoltha/dist
145 cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
Matt Jeannereta32441c2019-03-07 05:16:37 -0500146 . ${VENVDIR}/bin/activate && \
William Kurkian07271552019-04-09 16:52:06 -0400147 pip install local_imports/pyvoltha/dist/*.tar.gz
148endif
149ifdef LOCAL_PROTOS
150 mkdir -p local_imports/voltha-protos/dist
151 cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
152 . ${VENVDIR}/bin/activate && \
153 pip install local_protos/voltha-protos/dist/*.tar.gz
Matt Jeanneret18949ae2019-02-09 15:00:14 -0500154endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500155# end file