Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016 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 | 8b823f6 | 2019-05-11 11:01:28 -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} |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 28 | GOADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}-go |
| 29 | PYTHONADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}-py |
| 30 | ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG} |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 31 | |
| 32 | ## Docker labels. Only set ref and commit date if committed |
| 33 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 34 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 35 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 36 | |
| 37 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 38 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 39 | else |
| 40 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 41 | endif |
| 42 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 43 | .PHONY: docker-build openolt_go openolt_python local-protos local-volthago local-pyvoltha |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 44 | |
| 45 | # This should to be the first and default target in this Makefile |
| 46 | help: |
| 47 | @echo "Usage: make [<target>]" |
| 48 | @echo "where available targets are:" |
| 49 | @echo |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 50 | @echo "build : Build both openolt adapter docker images" |
| 51 | @echo "openolt_go : Build Golang openolt adapter docker image" |
| 52 | @echo "openolt_python : Build Python openolt adapter docker image" |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 53 | @echo "help : Print this help" |
| 54 | @echo "docker-push : Push the docker images to an external repository" |
| 55 | @echo "lint : Run lint verification, depenancy, gofmt and reference check" |
| 56 | @echo "test : Run unit tests, if any" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 57 | @echo |
| 58 | |
| 59 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 60 | ## Local Development Helpers |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 61 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 62 | local-protos: |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 63 | mkdir -p python/local_imports |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 64 | ifdef LOCAL_PROTOS |
| 65 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 66 | cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go |
| 67 | mkdir -p python/local_imports/voltha-protos/dist |
| 68 | cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/ |
| 69 | endif |
| 70 | |
| 71 | local-pyvoltha: |
| 72 | mkdir -p python/local_imports |
| 73 | ifdef LOCAL_PYVOLTHA |
| 74 | mkdir -p python/local_imports/pyvoltha/dist |
| 75 | cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/ |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 76 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 77 | |
| 78 | local-volthago: |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 79 | ifdef LOCAL_VOLTHAGO |
| 80 | mkdir -p vendor/github.com/opencord/voltha-go/ |
| 81 | cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/ |
| 82 | rm -rf vendor/github.com/opencord/voltha-go/vendor |
| 83 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 84 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 85 | |
| 86 | ## Python venv dev environment |
| 87 | |
| 88 | VENVDIR := python/venv-openolt |
| 89 | |
| 90 | venv: distclean local-protos local-pyvoltha |
| 91 | virtualenv ${VENVDIR};\ |
| 92 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 93 | rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\ |
| 94 | pip install -r python/requirements.txt |
| 95 | |
| 96 | ifdef LOCAL_PYVOLTHA |
| 97 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 98 | pip install python/local_imports/pyvoltha/dist/*.tar.gz |
| 99 | endif |
| 100 | ifdef LOCAL_PROTOS |
| 101 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 102 | pip install python/local_imports/voltha-protos/dist/*.tar.gz |
| 103 | endif |
| 104 | |
| 105 | |
| 106 | ## Docker targets |
| 107 | |
| 108 | build: docker-build |
| 109 | |
| 110 | docker-build: openolt_go openolt_python |
| 111 | |
| 112 | openolt_go: local-protos local-volthago |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 113 | docker build $(DOCKER_BUILD_ARGS) \ |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 114 | -t ${GOADAPTER_IMAGENAME} \ |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 115 | --build-arg org_label_schema_version="${VERSION}" \ |
| 116 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 117 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 118 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 119 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 120 | -f docker/Dockerfile.openolt . |
| 121 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 122 | openolt_python: local-protos local-pyvoltha |
| 123 | docker build $(DOCKER_BUILD_ARGS) \ |
| 124 | -t ${PYTHONADAPTER_IMAGENAME} \ |
| 125 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 126 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 127 | --build-arg org_label_schema_version="${VERSION}" \ |
| 128 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 129 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 130 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 131 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 132 | -f python/docker/Dockerfile.openolt_adapter python |
| 133 | |
| 134 | # Current default image gets the base DOCKER_TAG |
| 135 | docker tag ${PYTHONADAPTER_IMAGENAME} ${ADAPTER_IMAGENAME} |
| 136 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 137 | docker-push: |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 138 | docker push ${GOADAPTER_IMAGENAME} |
| 139 | docker push ${PYTHONADAPTER_IMAGENAME} |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 140 | docker push ${ADAPTER_IMAGENAME} |
| 141 | |
| 142 | |
| 143 | ## lint and unit tests |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 144 | |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 145 | lint-style: |
| 146 | ifeq (,$(shell which gofmt)) |
| 147 | go get -u github.com/golang/go/src/cmd/gofmt |
| 148 | endif |
| 149 | @echo "Running style check..." |
| 150 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 151 | if [ ! -z "$$gofmt_out" ]; then \ |
| 152 | echo "$$gofmt_out" ;\ |
| 153 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 154 | exit 1 ;\ |
| 155 | fi |
| 156 | @echo "Style check OK" |
| 157 | |
| 158 | lint-sanity: |
| 159 | @echo "Running sanity check..." |
| 160 | @go vet ./... |
| 161 | @echo "Sanity check OK" |
| 162 | |
| 163 | lint-dep: |
| 164 | @echo "Running dependency check..." |
| 165 | @dep check |
| 166 | @echo "Dependency check OK" |
| 167 | |
| 168 | lint: lint-style lint-sanity lint-dep |
| 169 | |
| 170 | GO_JUNIT_REPORT:=$(shell which go-junit-report) |
| 171 | GOCOVER_COBERTURA:=$(shell which gocover-cobertura) |
| 172 | test: |
| 173 | ifeq (,$(GO_JUNIT_REPORT)) |
| 174 | go get -u github.com/jstemmer/go-junit-report |
| 175 | @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
| 176 | endif |
| 177 | |
| 178 | ifeq (,$(GOCOVER_COBERTURA)) |
| 179 | go get -u github.com/t-yuki/gocover-cobertura |
| 180 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
| 181 | endif |
| 182 | |
| 183 | @mkdir -p ./tests/results |
| 184 | |
| 185 | @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
| 186 | RETURN=$$? ;\ |
| 187 | $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 188 | $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 189 | exit $$RETURN |
| 190 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame^] | 191 | clean: |
| 192 | rm -rf python/local_imports |
| 193 | find python -name '*.pyc' | xargs rm -f |
| 194 | |
| 195 | distclean: clean |
| 196 | rm -rf ${VENVDIR} |
| 197 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 198 | # end file |