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 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 17 | # set default shell |
| 18 | SHELL = bash -e -o pipefail |
| 19 | |
| 20 | # Variables |
| 21 | VERSION ?= $(shell cat ../VERSION) |
| 22 | |
| 23 | ## Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | OFAGENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent:${DOCKER_TAG} |
| 29 | CLI_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli:${DOCKER_TAG} |
| 30 | PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt:${DOCKER_TAG} |
| 31 | PONSIMONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-onu:${DOCKER_TAG} |
| 32 | |
| 33 | ## Docker labels. Only set ref and commit date if committed |
| 34 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 35 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 36 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 37 | |
| 38 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 39 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 40 | else |
| 41 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 42 | endif |
| 43 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 44 | .PHONY: venv ofagent cli adapter_ponsim_olt adapter_ponsim_onu local-protos local-pyvoltha |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 45 | |
| 46 | # This should to be the first and default target in this Makefile |
| 47 | help: |
| 48 | @echo "Usage: make [<target>]" |
| 49 | @echo "where available targets are:" |
| 50 | @echo |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 51 | @echo "build : Build all docker images" |
| 52 | @echo " - If this is the first time you are building, choose 'make build' option." |
| 53 | @echo "help : Print this help" |
| 54 | @echo "ofagent : Build the openflow agent docker image" |
| 55 | @echo "cli : Build the voltha CLI docker image" |
| 56 | @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker image" |
| 57 | @echo "adapter_ponsim_onu : Build the ponsim onu adapter docker image" |
| 58 | @echo "docker-push : Push the docker images to an external repository" |
| 59 | @echo "venv : Build local Python virtualenv" |
| 60 | @echo "clean : Remove files created by the build and tests" |
| 61 | @echo "distclean : Remove venv directory" |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 62 | @echo |
| 63 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 64 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 65 | ## Docker targets |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 66 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 67 | build: docker-build |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 68 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 69 | docker-build: ofagent cli adapter_ponsim_olt adapter_ponsim_onu |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 70 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 71 | local-protos: |
| 72 | mkdir -p local_imports |
| 73 | ifdef LOCAL_PROTOS |
| 74 | mkdir -p local_imports/voltha-protos/dist |
| 75 | cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/ |
| 76 | endif |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 77 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 78 | local-pyvoltha: |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 79 | mkdir -p local_imports |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 80 | ifdef LOCAL_PYVOLTHA |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 81 | mkdir -p local_imports/pyvoltha/dist |
| 82 | cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/ |
Arun Arora | ed4b760 | 2019-04-02 18:42:37 +0000 | [diff] [blame] | 83 | endif |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 84 | |
| 85 | ofagent: local-protos local-pyvoltha |
| 86 | docker build $(DOCKER_BUILD_ARGS) \ |
| 87 | -t ${OFAGENT_IMAGENAME} \ |
| 88 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 89 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 90 | --build-arg org_label_schema_version="${VERSION}" \ |
| 91 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 92 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 93 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 94 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 95 | -f docker/Dockerfile.ofagent . |
| 96 | |
| 97 | cli: local-protos local-pyvoltha |
| 98 | docker build $(DOCKER_BUILD_ARGS) \ |
| 99 | -t ${CLI_IMAGENAME} \ |
| 100 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 101 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 102 | --build-arg org_label_schema_version="${VERSION}" \ |
| 103 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 104 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 105 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 106 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 107 | -f docker/Dockerfile.cli . |
| 108 | |
| 109 | adapter_ponsim_olt: local-protos local-pyvoltha |
| 110 | docker build $(DOCKER_BUILD_ARGS) \ |
| 111 | -t ${PONSIMOLT_IMAGENAME} \ |
| 112 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 113 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 114 | --build-arg org_label_schema_version="${VERSION}" \ |
| 115 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 116 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 117 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 118 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 119 | -f docker/Dockerfile.adapter_ponsim_olt . |
| 120 | |
| 121 | adapter_ponsim_onu: local-protos local-pyvoltha |
| 122 | docker build $(DOCKER_BUILD_ARGS) \ |
| 123 | -t ${PONSIMONU_IMAGENAME} \ |
| 124 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 125 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 126 | --build-arg org_label_schema_version="${VERSION}" \ |
| 127 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 128 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 129 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 130 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 131 | -f docker/Dockerfile.adapter_ponsim_onu . |
| 132 | |
| 133 | docker-push: |
| 134 | docker push ${OFAGENT_IMAGENAME} |
| 135 | docker push ${CLI_IMAGENAME} |
| 136 | docker push ${PONSIMOLT_IMAGENAME} |
| 137 | docker push ${PONSIMONU_IMAGENAME} |
| 138 | |
| 139 | |
| 140 | ## Python venv dev environment |
| 141 | |
| 142 | VENVDIR := venv-volthago |
| 143 | |
| 144 | venv: distclean local-protos local-pyvoltha |
| 145 | virtualenv ${VENVDIR};\ |
| 146 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 147 | rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\ |
| 148 | pip install -r requirements.txt |
| 149 | |
| 150 | ifdef LOCAL_PYVOLTHA |
| 151 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 152 | pip install local_imports/pyvoltha/dist/*.tar.gz |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 153 | endif |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 154 | ifdef LOCAL_PROTOS |
| 155 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 156 | pip install local_imports/voltha-protos/dist/*.tar.gz |
| 157 | endif |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 158 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 159 | clean: |
William Kurkian | fc0dcda | 2019-04-08 16:54:36 -0400 | [diff] [blame] | 160 | rm -rf local_imports |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame^] | 161 | find . -name '*.pyc' | xargs rm -f |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 162 | |
| 163 | distclean: clean |
| 164 | rm -rf ${VENVDIR} |
| 165 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 166 | # end file |