Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -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 | |
| 17 | ifneq ($(VOLTHA_BUILD),docker) |
| 18 | ifeq ($(VOLTHA_BASE)_set,_set) |
| 19 | $(error To get started, please source the env.sh file) |
| 20 | endif |
| 21 | endif |
| 22 | |
| 23 | ifeq ($(TAG),) |
| 24 | TAG := latest |
| 25 | endif |
| 26 | |
| 27 | ifeq ($(TARGET_TAG),) |
| 28 | TARGET_TAG := latest |
| 29 | endif |
| 30 | |
| 31 | # If no DOCKER_HOST_IP is specified grab a v4 IP address associated with |
| 32 | # the default gateway |
| 33 | ifeq ($(DOCKER_HOST_IP),) |
| 34 | DOCKER_HOST_IP := $(shell ifconfig $$(netstat -rn | grep -E '^(default|0.0.0.0)' | head -1 | awk '{print $$NF}') | grep inet | awk '{print $$2}' | sed -e 's/addr://g') |
| 35 | endif |
| 36 | |
| 37 | ifneq ($(http_proxy)$(https_proxy),) |
| 38 | # Include proxies from the environment |
| 39 | DOCKER_PROXY_ARGS = \ |
| 40 | --build-arg http_proxy=$(http_proxy) \ |
| 41 | --build-arg https_proxy=$(https_proxy) \ |
| 42 | --build-arg ftp_proxy=$(ftp_proxy) \ |
| 43 | --build-arg no_proxy=$(no_proxy) \ |
| 44 | --build-arg HTTP_PROXY=$(HTTP_PROXY) \ |
| 45 | --build-arg HTTPS_PROXY=$(HTTPS_PROXY) \ |
| 46 | --build-arg FTP_PROXY=$(FTP_PROXY) \ |
| 47 | --build-arg NO_PROXY=$(NO_PROXY) |
| 48 | endif |
| 49 | |
| 50 | DOCKER_BUILD_ARGS = \ |
| 51 | --build-arg TAG=$(TAG) \ |
| 52 | --build-arg REGISTRY=$(REGISTRY) \ |
| 53 | --build-arg REPOSITORY=$(REPOSITORY) \ |
| 54 | $(DOCKER_PROXY_ARGS) $(DOCKER_CACHE_ARG) \ |
| 55 | --rm --force-rm \ |
| 56 | $(DOCKER_BUILD_EXTRA_ARGS) |
| 57 | |
| 58 | VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 59 | |
| 60 | DOCKER_IMAGE_LIST = \ |
| 61 | base \ |
| 62 | adapter-openonu \ |
| 63 | |
| 64 | # The following list was scavanged from the compose / stack files as well as |
| 65 | # from the Dockerfiles. If nothing else it highlights that VOLTHA is not |
| 66 | # using consistent versions for some of the containers. |
| 67 | |
| 68 | FETCH_BUILD_IMAGE_LIST = \ |
| 69 | alpine:3.6 \ |
| 70 | centos:7 \ |
| 71 | centurylink/ca-certs:latest \ |
| 72 | grpc/python:latest \ |
| 73 | ubuntu:xenial |
| 74 | |
| 75 | FETCH_COMPOSE_IMAGE_LIST = \ |
| 76 | wurstmeister/kafka:latest \ |
| 77 | wurstmeister/zookeeper:latest |
| 78 | |
| 79 | # find k8s -type f | xargs grep image: | awk '{print $NF}' | sed -e 's/\"//g' | sed '/:.*$/!s/$/:latest/g' | sort -u | sed -e 's/^/ /g' -e 's/$/ \\/g' |
| 80 | # Manually remove some image from this list as they don't reflect the new |
| 81 | # naming conventions for the VOLTHA build |
| 82 | FETCH_K8S_IMAGE_LIST = \ |
| 83 | wurstmeister/kafka:1.0.0 \ |
| 84 | zookeeper:3.4.11 |
| 85 | |
| 86 | FETCH_IMAGE_LIST = $(shell echo $(FETCH_BUILD_IMAGE_LIST) $(FETCH_COMPOSE_IMAGE_LIST) $(FETCH_K8S_IMAGE_LIST) | tr ' ' '\n' | sort -u) |
| 87 | |
| 88 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) base protoc protos adapter_openonu |
| 89 | |
| 90 | # This should to be the first and default target in this Makefile |
| 91 | help: |
| 92 | @echo "Usage: make [<target>]" |
| 93 | @echo "where available targets are:" |
| 94 | @echo |
| 95 | @echo "build : Build the Adapters protos and docker images.\n\ |
| 96 | If this is the first time you are building, choose \"make build\" option." |
| 97 | @echo "clean : Remove files created by the build and tests" |
| 98 | @echo "distclean : Remove venv directory" |
| 99 | @echo "fetch : Pre-fetch artifacts for subsequent local builds" |
| 100 | @echo "help : Print this help" |
| 101 | @echo "protoc : Build a container with protoc installed" |
| 102 | @echo "protos : Compile all grpc/protobuf files" |
| 103 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 104 | @echo "venv : Build local Python virtualenv if did not exist yet" |
| 105 | @echo "containers : Build all the docker containers" |
| 106 | @echo "base : Build the base docker container used by all other dockers" |
| 107 | @echo "adapter_openonu : Build the openonu openomci adapter docker container" |
| 108 | @echo "tag : Tag a set of images" |
| 109 | @echo "push : Push the docker images to an external repository" |
| 110 | @echo "pull : Pull the docker images from a repository" |
| 111 | @echo |
| 112 | |
| 113 | ## New directories can be added here |
| 114 | #DIRS:= |
| 115 | |
| 116 | ## If one directory depends on another directory that |
| 117 | ## dependency can be expressed here |
| 118 | ## |
| 119 | ## For example, if the Tibit directory depended on the eoam |
| 120 | ## directory being built first, then that can be expressed here. |
| 121 | ## driver/tibit: eoam |
| 122 | |
| 123 | # Parallel Build |
| 124 | $(DIRS): |
| 125 | @echo " MK $@" |
| 126 | $(Q)$(MAKE) -C $@ |
| 127 | |
| 128 | # Parallel Clean |
| 129 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 130 | $(DIRS_CLEAN): |
| 131 | @echo " CLEAN $(basename $@)" |
| 132 | $(Q)$(MAKE) -C $(basename $@) clean |
| 133 | |
| 134 | # Parallel Flake8 |
| 135 | DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS)) |
| 136 | $(DIRS_FLAKE8): |
| 137 | @echo " FLAKE8 $(basename $@)" |
| 138 | -$(Q)$(MAKE) -C $(basename $@) flake8 |
| 139 | |
| 140 | build: protoc protos containers |
| 141 | |
| 142 | containers: base adapter_openonu |
| 143 | |
| 144 | base: |
| 145 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-base:${TAG} -f docker/Dockerfile.base . |
| 146 | |
| 147 | adapter_openonu: |
| 148 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-openonu:${TAG} -f docker/Dockerfile.adapter_openonu . |
| 149 | |
| 150 | protoc: |
| 151 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-protoc:${TAG} -f docker/Dockerfile.protoc . |
| 152 | |
| 153 | protos: |
| 154 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-protos:${TAG} -f docker/Dockerfile.protos . |
| 155 | |
| 156 | tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST)) |
| 157 | |
| 158 | push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST)) |
| 159 | |
| 160 | pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST)) |
| 161 | |
| 162 | %.tag: |
| 163 | docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG} |
| 164 | |
| 165 | %.push: |
| 166 | docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG} |
| 167 | |
| 168 | %.pull: |
| 169 | docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG} |
| 170 | |
| 171 | clean: |
| 172 | find . -name '*.pyc' | xargs rm -f |
| 173 | |
| 174 | distclean: clean |
| 175 | rm -rf ${VENVDIR} |
| 176 | |
| 177 | fetch: |
| 178 | @bash -c ' \ |
| 179 | for i in $(FETCH_IMAGE_LIST); do \ |
| 180 | docker pull $$i; \ |
| 181 | done' |
| 182 | |
| 183 | purge-venv: |
| 184 | rm -fr ${VENVDIR} |
| 185 | |
| 186 | rebuild-venv: purge-venv venv |
| 187 | |
| 188 | ifneq ($(VOLTHA_BUILD),docker) |
| 189 | venv: ${VENVDIR}/.built |
| 190 | else |
| 191 | venv: |
| 192 | endif |
| 193 | |
| 194 | ${VENVDIR}/.built: |
| 195 | @ virtualenv ${VENVDIR} |
| 196 | @ . ${VENVDIR}/bin/activate && \ |
| 197 | pip install --upgrade pip; \ |
| 198 | if ! pip install -r requirements.txt; \ |
| 199 | then \ |
| 200 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 201 | echo "see the BUILD.md file for a workaround"; \ |
| 202 | else \ |
| 203 | uname -s > ${VENVDIR}/.built; \ |
| 204 | fi |
| 205 | |
| 206 | |
| 207 | flake8: $(DIRS_FLAKE8) |
| 208 | |
| 209 | # end file |