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