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 | |
| 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 | openolt-protos \ |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 62 | openolt-adapter \ |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 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_COMPOSE_IMAGE_LIST = \ |
| 69 | wurstmeister/kafka:latest \ |
| 70 | wurstmeister/zookeeper:latest |
| 71 | |
| 72 | # 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' |
| 73 | # Manually remove some image from this list as they don't reflect the new |
| 74 | # naming conventions for the VOLTHA build |
| 75 | FETCH_K8S_IMAGE_LIST = \ |
| 76 | wurstmeister/kafka:1.0.0 \ |
| 77 | zookeeper:3.4.11 |
| 78 | |
| 79 | FETCH_IMAGE_LIST = $(shell echo $(FETCH_BUILD_IMAGE_LIST) $(FETCH_COMPOSE_IMAGE_LIST) $(FETCH_K8S_IMAGE_LIST) | tr ' ' '\n' | sort -u) |
| 80 | |
| 81 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 base openolt ofagent kafka common start stop tag push pull |
| 82 | |
| 83 | # This should to be the first and default target in this Makefile |
| 84 | help: |
| 85 | @echo "Usage: make [<target>]" |
| 86 | @echo "where available targets are:" |
| 87 | @echo |
| 88 | @echo "build : Build the Adapters protos and docker images.\n\ |
| 89 | If this is the first time you are building, choose \"make build\" option." |
| 90 | @echo "clean : Remove files created by the build and tests" |
| 91 | @echo "distclean : Remove venv directory" |
| 92 | @echo "fetch : Pre-fetch artifacts for subsequent local builds" |
| 93 | @echo "help : Print this help" |
| 94 | @echo "protoc : Build a container with protoc installed" |
| 95 | @echo "protos : Compile all grpc/protobuf files" |
| 96 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 97 | @echo "venv : Build local Python virtualenv if did not exist yet" |
| 98 | @echo "containers : Build all the docker containers" |
| 99 | @echo "base : Build the base docker container used by all other dockers" |
| 100 | @echo "tag : Tag a set of images" |
| 101 | @echo "push : Push the docker images to an external repository" |
| 102 | @echo "pull : Pull the docker images from a repository" |
| 103 | @echo |
| 104 | |
| 105 | ## New directories can be added here |
| 106 | #DIRS:= |
| 107 | |
| 108 | ## If one directory depends on another directory that |
| 109 | ## dependency can be expressed here |
| 110 | ## |
| 111 | ## For example, if the Tibit directory depended on the eoam |
| 112 | ## directory being built first, then that can be expressed here. |
| 113 | ## driver/tibit: eoam |
| 114 | |
| 115 | # Parallel Build |
| 116 | $(DIRS): |
| 117 | @echo " MK $@" |
| 118 | $(Q)$(MAKE) -C $@ |
| 119 | |
| 120 | # Parallel Clean |
| 121 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 122 | $(DIRS_CLEAN): |
| 123 | @echo " CLEAN $(basename $@)" |
| 124 | $(Q)$(MAKE) -C $(basename $@) clean |
| 125 | |
| 126 | # Parallel Flake8 |
| 127 | DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS)) |
| 128 | $(DIRS_FLAKE8): |
| 129 | @echo " FLAKE8 $(basename $@)" |
| 130 | -$(Q)$(MAKE) -C $(basename $@) flake8 |
| 131 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 132 | build: containers |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 133 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 134 | containers: base adapter_openolt |
| 135 | |
| 136 | base: |
| 137 | ifdef LOCAL_PYVOLTHA |
| 138 | mkdir -p pyvoltha/dist |
| 139 | cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/ |
| 140 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-base:${TAG} -f docker/Dockerfile.base_local . |
| 141 | else |
| 142 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base . |
| 143 | endif |
| 144 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 145 | |
| 146 | adapter_openolt: |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 147 | 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] | 148 | |
| 149 | tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST)) |
| 150 | |
| 151 | push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST)) |
| 152 | |
| 153 | pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST)) |
| 154 | |
| 155 | %.tag: |
| 156 | docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG} |
| 157 | |
| 158 | %.push: |
| 159 | docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG} |
| 160 | |
| 161 | %.pull: |
| 162 | docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG} |
| 163 | |
| 164 | openolt_protos: |
| 165 | ifneq ($(VOLTHA_BUILD),docker) |
| 166 | make -C protos |
| 167 | else |
| 168 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-protos:${TAG} -f docker/Dockerfile.openolt_protos . |
| 169 | endif |
| 170 | |
| 171 | install-protoc: |
| 172 | make -C voltha/protos install-protoc |
| 173 | |
| 174 | clean: |
Matt Jeanneret | 5e807e5 | 2019-02-12 15:19:42 -0500 | [diff] [blame^] | 175 | rm -rf pyvoltha |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 176 | find . -name '*.pyc' | xargs rm -f |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 177 | |
| 178 | distclean: clean |
| 179 | rm -rf ${VENVDIR} |
| 180 | |
| 181 | fetch: |
| 182 | @bash -c ' \ |
| 183 | for i in $(FETCH_IMAGE_LIST); do \ |
| 184 | docker pull $$i; \ |
| 185 | done' |
| 186 | |
| 187 | purge-venv: |
| 188 | rm -fr ${VENVDIR} |
| 189 | |
| 190 | rebuild-venv: purge-venv venv |
| 191 | |
| 192 | ifneq ($(VOLTHA_BUILD),docker) |
| 193 | venv: ${VENVDIR}/.built |
| 194 | else |
| 195 | venv: |
| 196 | endif |
| 197 | |
| 198 | ${VENVDIR}/.built: |
| 199 | @ virtualenv ${VENVDIR} |
| 200 | @ . ${VENVDIR}/bin/activate && \ |
| 201 | pip install --upgrade pip; \ |
| 202 | if ! pip install -r requirements.txt; \ |
| 203 | then \ |
| 204 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 205 | echo "see the BUILD.md file for a workaround"; \ |
| 206 | else \ |
| 207 | uname -s > ${VENVDIR}/.built; \ |
| 208 | fi |
| 209 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 210 | ifdef LOCAL_PYVOLTHA |
| 211 | mkdir -p pyvoltha/dist |
| 212 | cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/ |
| 213 | @ . ${VENVDIR}/bin/activate && \ |
| 214 | pip install pyvoltha/dist/*.tar.gz |
| 215 | endif |
| 216 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 217 | |
| 218 | flake8: $(DIRS_FLAKE8) |
| 219 | |
| 220 | # end file |