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