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