blob: ec8b91d1d4e7143708d6f9593c1e2703f1754c2d [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
Matt Jeanneret18949ae2019-02-09 15:00:14 -050046DOCKER_IMAGE_LIST = \
47 voltha-openonu-adapter-base \
48 voltha-openonu-adapter
49
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050050VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
51
Matt Jeanneret18949ae2019-02-09 15:00:14 -050052.PHONY: $(DIRS) $(DIRS_CLEAN) base openonu_adapter
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050053
54# This should to be the first and default target in this Makefile
55help:
56 @echo "Usage: make [<target>]"
57 @echo "where available targets are:"
58 @echo
Matt Jeanneret18949ae2019-02-09 15:00:14 -050059 @echo "build : Build the adapter."
60 @echo "clean : Remove files created by the build and tests"
61 @echo "distclean : Remove venv directory"
62 @echo "help : Print this help"
63 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
64 @echo "venv : Build local Python virtualenv if did not exist yet"
65 @echo "containers : Build all the docker containers"
66 @echo "base : Build a base docker image with a modern version of pip and requirements.txt installed"
Matt Jeanneret76c98b12019-03-05 11:09:37 -050067 @echo "openonu_adapter : Build the openonu openomci adapter docker container"
Matt Jeanneret18949ae2019-02-09 15:00:14 -050068 @echo "tag : Tag a set of images"
69 @echo "push : Push the docker images to an external repository"
70 @echo "pull : Pull the docker images from a repository"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050071 @echo
72
Matt Jeanneret18949ae2019-02-09 15:00:14 -050073build: containers
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050074
Matt Jeanneret18949ae2019-02-09 15:00:14 -050075containers: base openonu_adapter
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050076
77base:
Matt Jeanneret18949ae2019-02-09 15:00:14 -050078ifdef LOCAL_PYVOLTHA
79 mkdir -p pyvoltha/dist
80 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
William Kurkian8235c1e2019-03-05 12:58:28 -050081 mkdir -p voltha-protos/dist
82 cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
Matt Jeanneret18949ae2019-02-09 15:00:14 -050083 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base_local .
84else
85 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base .
86endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087
Matt Jeanneret18949ae2019-02-09 15:00:14 -050088openonu_adapter: base
89ifdef PYVOLTHA_BASE_IMAGE
90 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter:${TAG} -f docker/Dockerfile.openonu_adapter_pyvoltha .
91else
92 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter:${TAG} -f docker/Dockerfile.openonu_adapter .
93endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094
95tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST))
96
97push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST))
98
99pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST))
100
101%.tag:
102 docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG}
103
104%.push:
105 docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG}
106
107%.pull:
108 docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
109
110clean:
Matt Jeanneret18949ae2019-02-09 15:00:14 -0500111 rm -rf pyvoltha
William Kurkian8235c1e2019-03-05 12:58:28 -0500112 rm -rf voltha-protos
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500113 find . -name '*.pyc' | xargs rm -f
114
115distclean: clean
116 rm -rf ${VENVDIR}
117
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500118purge-venv:
119 rm -fr ${VENVDIR}
120
121rebuild-venv: purge-venv venv
122
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500123venv: ${VENVDIR}/.built
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500124
125${VENVDIR}/.built:
Matt Jeannereta32441c2019-03-07 05:16:37 -0500126 virtualenv -v ${VENVDIR}
127 # 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?
128 rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include
129 . ${VENVDIR}/bin/activate && \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500130 pip install --upgrade pip; \
131 if ! pip install -r requirements.txt; \
132 then \
133 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
134 echo "see the BUILD.md file for a workaround"; \
135 else \
136 uname -s > ${VENVDIR}/.built; \
137 fi
138
Matt Jeanneret18949ae2019-02-09 15:00:14 -0500139ifdef LOCAL_PYVOLTHA
140 mkdir -p pyvoltha/dist
141 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
William Kurkian8235c1e2019-03-05 12:58:28 -0500142 mkdir -p voltha-protos/dist
143 cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
Matt Jeannereta32441c2019-03-07 05:16:37 -0500144 . ${VENVDIR}/bin/activate && \
William Kurkian8235c1e2019-03-05 12:58:28 -0500145 pip install pyvoltha/dist/*.tar.gz && \
146 pip install voltha-protos/dist/*.tar.gz
Matt Jeanneret18949ae2019-02-09 15:00:14 -0500147endif
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500148# end file