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 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 17 | ifeq ($(TAG),) |
| 18 | TAG := latest |
| 19 | endif |
| 20 | |
| 21 | ifeq ($(TARGET_TAG),) |
| 22 | TARGET_TAG := latest |
| 23 | endif |
| 24 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 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 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 46 | DOCKER_IMAGE_LIST = \ |
| 47 | voltha-openolt-adapter-base \ |
| 48 | voltha-openolt-adapter |
| 49 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 50 | VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 51 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 52 | .PHONY: $(DIRS) $(DIRS_CLEAN) base openolt_adapter |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 53 | |
| 54 | # This should to be the first and default target in this Makefile |
| 55 | help: |
| 56 | @echo "Usage: make [<target>]" |
| 57 | @echo "where available targets are:" |
| 58 | @echo |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 59 | @echo "build : Build the adapter." |
| 60 | @echo "clean : Remove files created by the build and tests" |
| 61 | @echo "distclean : Remove venv directory" |
| 62 | @echo "help : Print this help" |
| 63 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 64 | @echo "venv : Build local Python virtualenv if did not exist yet" |
| 65 | @echo "containers : Build all the docker containers" |
| 66 | @echo "base : Build a base docker image with a modern version of pip and requirements.txt installed" |
| 67 | @echo "openolt_adapter : Build the openolt adapter docker container" |
| 68 | @echo "tag : Tag a set of images" |
| 69 | @echo "push : Push the docker images to an external repository" |
| 70 | @echo "pull : Pull the docker images from a repository" |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 71 | @echo |
| 72 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 73 | build: containers |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 74 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 75 | containers: base openolt_adapter |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 76 | |
| 77 | base: |
| 78 | ifdef LOCAL_PYVOLTHA |
| 79 | mkdir -p pyvoltha/dist |
| 80 | cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/ |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 81 | mkdir -p voltha-protos/dist |
| 82 | cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/ |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 83 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-base:${TAG} -f docker/Dockerfile.base_local . |
| 84 | else |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 85 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openolt-adapter-base:${TAG} -f docker/Dockerfile.base . |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 86 | endif |
| 87 | |
Matt Jeanneret | f35be11 | 2019-03-05 10:58:57 -0500 | [diff] [blame] | 88 | openolt_adapter: base |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 89 | 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] | 90 | |
| 91 | tag: $(patsubst %,%.tag,$(DOCKER_IMAGE_LIST)) |
| 92 | |
| 93 | push: tag $(patsubst %,%.push,$(DOCKER_IMAGE_LIST)) |
| 94 | |
| 95 | pull: $(patsubst %,%.pull,$(DOCKER_IMAGE_LIST)) |
| 96 | |
| 97 | %.tag: |
| 98 | docker tag ${REGISTRY}${REPOSITORY}voltha-$(subst .tag,,$@):${TAG} ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .tag,,$@):${TARGET_TAG} |
| 99 | |
| 100 | %.push: |
| 101 | docker push ${TARGET_REGISTRY}${TARGET_REPOSITORY}voltha-$(subst .push,,$@):${TARGET_TAG} |
| 102 | |
| 103 | %.pull: |
| 104 | docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG} |
| 105 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 106 | clean: |
Matt Jeanneret | 5e807e5 | 2019-02-12 15:19:42 -0500 | [diff] [blame] | 107 | rm -rf pyvoltha |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 108 | rm -rf voltha-protos |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 109 | find . -name '*.pyc' | xargs rm -f |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 110 | |
| 111 | distclean: clean |
| 112 | rm -rf ${VENVDIR} |
| 113 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 114 | purge-venv: |
| 115 | rm -fr ${VENVDIR} |
| 116 | |
| 117 | rebuild-venv: purge-venv venv |
| 118 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 119 | venv: ${VENVDIR}/.built |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 120 | |
| 121 | ${VENVDIR}/.built: |
| 122 | @ virtualenv ${VENVDIR} |
| 123 | @ . ${VENVDIR}/bin/activate && \ |
| 124 | pip install --upgrade pip; \ |
| 125 | if ! pip install -r requirements.txt; \ |
| 126 | then \ |
| 127 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 128 | echo "see the BUILD.md file for a workaround"; \ |
| 129 | else \ |
| 130 | uname -s > ${VENVDIR}/.built; \ |
| 131 | fi |
| 132 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 133 | ifdef LOCAL_PYVOLTHA |
| 134 | mkdir -p pyvoltha/dist |
| 135 | cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/ |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 136 | mkdir -p voltha-protos/dist |
| 137 | cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/ |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 138 | @ . ${VENVDIR}/bin/activate && \ |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 139 | pip install pyvoltha/dist/*.tar.gz \ |
| 140 | pip install voltha-protos/dist/*.tar.gz |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 141 | endif |
| 142 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 143 | # end file |