khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [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 | |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 58 | DOCKER_BUILD_EXTRA_ARGS = \ |
| 59 | --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \ |
| 60 | --build-arg LOCAL_PROTOS=${LOCAL_PROTOS} |
| 61 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 62 | VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 63 | |
| 64 | DOCKER_IMAGE_LIST = \ |
| 65 | base \ |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 66 | adapter-ponsim-olt \ |
Matt Jeanneret | f4d4d35 | 2019-02-14 11:26:13 -0500 | [diff] [blame] | 67 | adapter-ponsim-onu |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 68 | |
| 69 | # The following list was scavanged from the compose / stack files as well as |
| 70 | # from the Dockerfiles. If nothing else it highlights that VOLTHA is not |
| 71 | # using consistent versions for some of the containers. |
| 72 | |
| 73 | FETCH_BUILD_IMAGE_LIST = \ |
| 74 | alpine:3.6 \ |
| 75 | centos:7 \ |
| 76 | centurylink/ca-certs:latest \ |
| 77 | grpc/python:latest \ |
| 78 | ubuntu:xenial |
| 79 | |
| 80 | FETCH_COMPOSE_IMAGE_LIST = \ |
| 81 | wurstmeister/kafka:latest \ |
| 82 | wurstmeister/zookeeper:latest |
| 83 | |
| 84 | # 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' |
| 85 | # Manually remove some image from this list as they don't reflect the new |
| 86 | # naming conventions for the VOLTHA build |
| 87 | FETCH_K8S_IMAGE_LIST = \ |
| 88 | wurstmeister/kafka:1.0.0 \ |
| 89 | zookeeper:3.4.11 |
| 90 | |
| 91 | FETCH_IMAGE_LIST = $(shell echo $(FETCH_BUILD_IMAGE_LIST) $(FETCH_COMPOSE_IMAGE_LIST) $(FETCH_K8S_IMAGE_LIST) | tr ' ' '\n' | sort -u) |
| 92 | |
Matt Jeanneret | f4d4d35 | 2019-02-14 11:26:13 -0500 | [diff] [blame] | 93 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 base ponsim_olt ponsim_onu protos cli ofagent kafka common start stop tag push pull |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 94 | |
| 95 | # This should to be the first and default target in this Makefile |
| 96 | help: |
| 97 | @echo "Usage: make [<target>]" |
| 98 | @echo "where available targets are:" |
| 99 | @echo |
| 100 | @echo "build : Build the Adapters protos and docker images.\n\ |
| 101 | If this is the first time you are building, choose \"make build\" option." |
| 102 | @echo "clean : Remove files created by the build and tests" |
| 103 | @echo "distclean : Remove venv directory" |
| 104 | @echo "fetch : Pre-fetch artifacts for subsequent local builds" |
| 105 | @echo "help : Print this help" |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 106 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 107 | @echo "venv : Build local Python virtualenv if did not exist yet" |
| 108 | @echo "containers : Build all the docker containers" |
| 109 | @echo "base : Build the base docker container used by all other dockers" |
| 110 | @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker container" |
| 111 | @echo "adapter_ponsim_onu : Build the ponsim olt adapter docker container" |
Matt Jeanneret | 13643e0 | 2019-01-30 16:49:03 -0500 | [diff] [blame] | 112 | @echo "ofagent : Build the openflow agent docker container" |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 113 | @echo "tag : Tag a set of images" |
| 114 | @echo "push : Push the docker images to an external repository" |
| 115 | @echo "pull : Pull the docker images from a repository" |
| 116 | @echo |
| 117 | |
| 118 | ## New directories can be added here |
| 119 | #DIRS:= |
| 120 | |
| 121 | ## If one directory depends on another directory that |
| 122 | ## dependency can be expressed here |
| 123 | ## |
| 124 | ## For example, if the Tibit directory depended on the eoam |
| 125 | ## directory being built first, then that can be expressed here. |
| 126 | ## driver/tibit: eoam |
| 127 | |
| 128 | # Parallel Build |
| 129 | $(DIRS): |
| 130 | @echo " MK $@" |
| 131 | $(Q)$(MAKE) -C $@ |
| 132 | |
| 133 | # Parallel Clean |
| 134 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 135 | $(DIRS_CLEAN): |
| 136 | @echo " CLEAN $(basename $@)" |
| 137 | $(Q)$(MAKE) -C $(basename $@) clean |
| 138 | |
| 139 | # Parallel Flake8 |
| 140 | DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS)) |
| 141 | $(DIRS_FLAKE8): |
| 142 | @echo " FLAKE8 $(basename $@)" |
| 143 | -$(Q)$(MAKE) -C $(basename $@) flake8 |
| 144 | |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 145 | build: containers |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 146 | |
Matt Jeanneret | f4d4d35 | 2019-02-14 11:26:13 -0500 | [diff] [blame] | 147 | containers: base adapter_ponsim_olt adapter_ponsim_onu ofagent cli |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 148 | |
| 149 | base: |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 150 | mkdir -p local_imports |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 151 | ifdef LOCAL_PYVOLTHA |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 152 | mkdir -p local_imports/pyvoltha/dist |
| 153 | cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/ |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 154 | endif |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 155 | ifdef LOCAL_PROTOS |
| 156 | mkdir -p local_imports/voltha-protos/dist |
| 157 | cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/ |
| 158 | endif |
| 159 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-base:${TAG} -f docker/Dockerfile.base . |
| 160 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 161 | |
| 162 | adapter_ponsim_olt: |
| 163 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-ponsim-olt:${TAG} -f docker/Dockerfile.adapter_ponsim_olt . |
| 164 | |
| 165 | adapter_ponsim_onu: |
| 166 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-ponsim-onu:${TAG} -f docker/Dockerfile.adapter_ponsim_onu . |
| 167 | |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 168 | ofagent: |
| 169 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ofagent:${TAG} -f docker/Dockerfile.ofagent . |
| 170 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 171 | cli: |
| 172 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-cli:${TAG} -f docker/Dockerfile.cli . |
| 173 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 174 | tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST)) |
| 175 | |
| 176 | push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST)) |
| 177 | |
| 178 | pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST)) |
| 179 | |
| 180 | %.tag: |
| 181 | docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG} |
| 182 | |
| 183 | %.push: |
| 184 | docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG} |
| 185 | |
| 186 | %.pull: |
| 187 | docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG} |
| 188 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 189 | clean: |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 190 | find . -name '*.pyc' | xargs rm -f |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 191 | rm -rf local_imports |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 192 | |
| 193 | distclean: clean |
| 194 | rm -rf ${VENVDIR} |
| 195 | |
| 196 | fetch: |
| 197 | @bash -c ' \ |
| 198 | for i in $(FETCH_IMAGE_LIST); do \ |
| 199 | docker pull $$i; \ |
| 200 | done' |
| 201 | |
| 202 | purge-venv: |
| 203 | rm -fr ${VENVDIR} |
| 204 | |
| 205 | rebuild-venv: purge-venv venv |
| 206 | |
| 207 | ifneq ($(VOLTHA_BUILD),docker) |
| 208 | venv: ${VENVDIR}/.built |
| 209 | else |
| 210 | venv: |
| 211 | endif |
| 212 | |
| 213 | ${VENVDIR}/.built: |
| 214 | @ virtualenv ${VENVDIR} |
| 215 | @ . ${VENVDIR}/bin/activate && \ |
| 216 | pip install --upgrade pip; \ |
| 217 | if ! pip install -r requirements.txt; \ |
| 218 | then \ |
| 219 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 220 | echo "see the BUILD.md file for a workaround"; \ |
| 221 | else \ |
| 222 | uname -s > ${VENVDIR}/.built; \ |
| 223 | fi |
| 224 | |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 225 | ifdef LOCAL_PYVOLTHA |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 226 | mkdir -p local_imports/pyvoltha/dist |
| 227 | cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/ |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 228 | . ${VENVDIR}/bin/activate && \ |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 229 | pip install local_imports/pyvoltha/dist/*.tar.gz |
| 230 | endif |
| 231 | ifdef LOCAL_PROTOS |
| 232 | mkdir -p local_imports/voltha-protos/dist |
| 233 | cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/ |
| 234 | . ${VENVDIR}/bin/activate && \ |
| 235 | pip install local_imports/voltha-protos/dist/*.tar.gz |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 236 | endif |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 237 | |
| 238 | flake8: $(DIRS_FLAKE8) |
| 239 | |
| 240 | # end file |