William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1 | # |
| 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 Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 17 | ifeq ($(TAG),) |
| 18 | TAG := latest |
| 19 | endif |
| 20 | |
| 21 | ifeq ($(TARGET_TAG),) |
| 22 | TARGET_TAG := latest |
| 23 | endif |
| 24 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 25 | ifneq ($(http_proxy)$(https_proxy),) |
| 26 | # Include proxies from the environment |
| 27 | DOCKER_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) |
| 36 | endif |
| 37 | |
| 38 | DOCKER_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 Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 46 | DOCKER_BUILD_EXTRA_ARGS = \ |
| 47 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 48 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) |
| 49 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 50 | DOCKER_IMAGE_LIST = \ |
| 51 | voltha-openolt-adapter-base \ |
| 52 | voltha-openolt-adapter |
| 53 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 54 | VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 55 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 56 | .PHONY: $(DIRS) $(DIRS_CLEAN) base openolt_adapter |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 57 | |
| 58 | # This should to be the first and default target in this Makefile |
| 59 | help: |
| 60 | @echo "Usage: make [<target>]" |
| 61 | @echo "where available targets are:" |
| 62 | @echo |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 63 | @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" |
| 71 | @echo "openolt_adapter : Build the openolt adapter docker container" |
| 72 | @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" |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 75 | @echo |
| 76 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 77 | build: containers |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 78 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 79 | containers: base openolt_adapter |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 80 | |
| 81 | base: |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 82 | mkdir -p local_imports/ |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 83 | ifdef LOCAL_PYVOLTHA |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 84 | mkdir -p local_imports/pyvoltha/dist |
| 85 | cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/ |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 86 | endif |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 87 | ifdef LOCAL_PROTOS |
| 88 | mkdir -p local_imports/voltha-protos/dist |
| 89 | cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/ |
| 90 | endif |
| 91 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-base:${TAG} -f docker/Dockerfile.base . |
| 92 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 93 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 94 | openolt_adapter: base |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 95 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter:${TAG} -f docker/Dockerfile.openolt_adapter . |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 96 | |
| 97 | tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST)) |
| 98 | |
| 99 | push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST)) |
| 100 | |
| 101 | pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST)) |
| 102 | |
| 103 | %.tag: |
| 104 | docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG} |
| 105 | |
| 106 | %.push: |
| 107 | docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG} |
| 108 | |
| 109 | %.pull: |
| 110 | docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG} |
| 111 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 112 | clean: |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 113 | rm -rf local_imports |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 114 | find . -name '*.pyc' | xargs rm -f |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 115 | |
| 116 | distclean: clean |
| 117 | rm -rf ${VENVDIR} |
| 118 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 119 | purge-venv: |
| 120 | rm -fr ${VENVDIR} |
| 121 | |
| 122 | rebuild-venv: purge-venv venv |
| 123 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 124 | venv: ${VENVDIR}/.built |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 125 | |
| 126 | ${VENVDIR}/.built: |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 127 | virtualenv -v ${VENVDIR} |
| 128 | # 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? |
| 129 | rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include |
| 130 | . ${VENVDIR}/bin/activate && \ |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 131 | pip install --upgrade pip; \ |
| 132 | if ! pip install -r requirements.txt; \ |
| 133 | then \ |
| 134 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 135 | echo "see the BUILD.md file for a workaround"; \ |
| 136 | else \ |
| 137 | uname -s > ${VENVDIR}/.built; \ |
| 138 | fi |
| 139 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 140 | ifdef LOCAL_PYVOLTHA |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 141 | mkdir -p local_imports/pyvoltha/dist |
| 142 | cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/ |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 143 | . ${VENVDIR}/bin/activate && \ |
William Kurkian | e530104 | 2019-04-09 16:49:36 -0400 | [diff] [blame^] | 144 | pip install local_imports/pyvoltha/dist/*.tar.gz |
| 145 | endif |
| 146 | ifdef LOCAL_PROTOS |
| 147 | mkdir -p local_imports/voltha-protos/dist |
| 148 | cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/ |
| 149 | . ${VENVDIR}/bin/activate && \ |
| 150 | pip install local_imports/voltha-protos/dist/*.tar.gz |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 151 | endif |
| 152 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 153 | # end file |