blob: 3ac69365d01b4013e10fb8d67a40fee39dd241c5 [file] [log] [blame]
William Kurkian6f436d02019-02-06 16:25:01 -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
William Kurkian6f436d02019-02-06 16:25:01 -050017ifeq ($(TAG),)
18TAG := latest
19endif
20
21ifeq ($(TARGET_TAG),)
22TARGET_TAG := latest
23endif
24
William Kurkian6f436d02019-02-06 16:25:01 -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 Jeanneretf35be112019-03-05 10:58:57 -050046DOCKER_IMAGE_LIST = \
47 voltha-openolt-adapter-base \
48 voltha-openolt-adapter
49
William Kurkian6f436d02019-02-06 16:25:01 -050050VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
51
Matt Jeanneretf35be112019-03-05 10:58:57 -050052.PHONY: $(DIRS) $(DIRS_CLEAN) base openolt_adapter
William Kurkian6f436d02019-02-06 16:25:01 -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 Jeanneretf35be112019-03-05 10:58:57 -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"
67 @echo "openolt_adapter : Build the openolt adapter docker container"
68 @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"
William Kurkian6f436d02019-02-06 16:25:01 -050071 @echo
72
William Kurkian44cd7bb2019-02-11 16:39:12 -050073build: containers
William Kurkian6f436d02019-02-06 16:25:01 -050074
Matt Jeanneretf35be112019-03-05 10:58:57 -050075containers: base openolt_adapter
William Kurkian44cd7bb2019-02-11 16:39:12 -050076
77base:
78ifdef LOCAL_PYVOLTHA
79 mkdir -p pyvoltha/dist
80 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
81 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-base:${TAG} -f docker/Dockerfile.base_local .
82else
Matt Jeanneretf35be112019-03-05 10:58:57 -050083 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-base:${TAG} -f docker/Dockerfile.base .
William Kurkian44cd7bb2019-02-11 16:39:12 -050084endif
85
Matt Jeanneretf35be112019-03-05 10:58:57 -050086openolt_adapter: base
William Kurkian44cd7bb2019-02-11 16:39:12 -050087 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter:${TAG} -f docker/Dockerfile.openolt_adapter .
William Kurkian6f436d02019-02-06 16:25:01 -050088
89tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST))
90
91push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST))
92
93pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST))
94
95%.tag:
96 docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG}
97
98%.push:
99 docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG}
100
101%.pull:
102 docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
103
William Kurkian6f436d02019-02-06 16:25:01 -0500104clean:
Matt Jeanneret5e807e52019-02-12 15:19:42 -0500105 rm -rf pyvoltha
William Kurkian6f436d02019-02-06 16:25:01 -0500106 find . -name '*.pyc' | xargs rm -f
William Kurkian6f436d02019-02-06 16:25:01 -0500107
108distclean: clean
109 rm -rf ${VENVDIR}
110
William Kurkian6f436d02019-02-06 16:25:01 -0500111purge-venv:
112 rm -fr ${VENVDIR}
113
114rebuild-venv: purge-venv venv
115
William Kurkian6f436d02019-02-06 16:25:01 -0500116venv: ${VENVDIR}/.built
William Kurkian6f436d02019-02-06 16:25:01 -0500117
118${VENVDIR}/.built:
119 @ virtualenv ${VENVDIR}
120 @ . ${VENVDIR}/bin/activate && \
121 pip install --upgrade pip; \
122 if ! pip install -r requirements.txt; \
123 then \
124 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
125 echo "see the BUILD.md file for a workaround"; \
126 else \
127 uname -s > ${VENVDIR}/.built; \
128 fi
129
William Kurkian44cd7bb2019-02-11 16:39:12 -0500130ifdef LOCAL_PYVOLTHA
131 mkdir -p pyvoltha/dist
132 cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
133 @ . ${VENVDIR}/bin/activate && \
Matt Jeanneretf35be112019-03-05 10:58:57 -0500134 pip install pyvoltha/dist/*.tar.gz
William Kurkian44cd7bb2019-02-11 16:39:12 -0500135endif
136
William Kurkian6f436d02019-02-06 16:25:01 -0500137# end file