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" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 56 | @echo "sca : Runs various SCA through golangci-lint tool" |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 57 | @echo "test : Run unit tests, if any" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 58 | @echo |
| 59 | |
| 60 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 61 | ## Local Development Helpers |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 62 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 63 | local-protos: |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 64 | mkdir -p python/local_imports |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 65 | ifdef LOCAL_PROTOS |
| 66 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 67 | cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go |
| 68 | mkdir -p python/local_imports/voltha-protos/dist |
| 69 | cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/ |
| 70 | endif |
| 71 | |
| 72 | local-pyvoltha: |
| 73 | mkdir -p python/local_imports |
| 74 | ifdef LOCAL_PYVOLTHA |
| 75 | mkdir -p python/local_imports/pyvoltha/dist |
| 76 | cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/ |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 77 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 78 | |
| 79 | local-volthago: |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 80 | ifdef LOCAL_VOLTHAGO |
| 81 | mkdir -p vendor/github.com/opencord/voltha-go/ |
| 82 | cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/ |
| 83 | rm -rf vendor/github.com/opencord/voltha-go/vendor |
| 84 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 85 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 86 | |
| 87 | ## Python venv dev environment |
| 88 | |
| 89 | VENVDIR := python/venv-openolt |
| 90 | |
| 91 | venv: distclean local-protos local-pyvoltha |
| 92 | virtualenv ${VENVDIR};\ |
| 93 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 94 | rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\ |
| 95 | pip install -r python/requirements.txt |
| 96 | |
| 97 | ifdef LOCAL_PYVOLTHA |
| 98 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 99 | pip install python/local_imports/pyvoltha/dist/*.tar.gz |
| 100 | endif |
| 101 | ifdef LOCAL_PROTOS |
| 102 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 103 | pip install python/local_imports/voltha-protos/dist/*.tar.gz |
| 104 | endif |
| 105 | |
| 106 | |
| 107 | ## Docker targets |
| 108 | |
| 109 | build: docker-build |
| 110 | |
| 111 | docker-build: openolt_go openolt_python |
| 112 | |
| 113 | openolt_go: local-protos local-volthago |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 114 | docker build $(DOCKER_BUILD_ARGS) \ |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 115 | -t ${GOADAPTER_IMAGENAME} \ |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 116 | --build-arg org_label_schema_version="${VERSION}" \ |
| 117 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 118 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 119 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 120 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 121 | -f docker/Dockerfile.openolt . |
| 122 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 123 | openolt_python: local-protos local-pyvoltha |
| 124 | docker build $(DOCKER_BUILD_ARGS) \ |
| 125 | -t ${PYTHONADAPTER_IMAGENAME} \ |
| 126 | --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \ |
| 127 | --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \ |
| 128 | --build-arg org_label_schema_version="${VERSION}" \ |
| 129 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 130 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 131 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 132 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 133 | -f python/docker/Dockerfile.openolt_adapter python |
| 134 | |
| 135 | # Current default image gets the base DOCKER_TAG |
| 136 | docker tag ${PYTHONADAPTER_IMAGENAME} ${ADAPTER_IMAGENAME} |
| 137 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 138 | docker-push: |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 139 | docker push ${GOADAPTER_IMAGENAME} |
| 140 | docker push ${PYTHONADAPTER_IMAGENAME} |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame] | 141 | docker push ${ADAPTER_IMAGENAME} |
| 142 | |
| 143 | |
| 144 | ## lint and unit tests |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 145 | |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 146 | lint-style: |
| 147 | ifeq (,$(shell which gofmt)) |
| 148 | go get -u github.com/golang/go/src/cmd/gofmt |
| 149 | endif |
| 150 | @echo "Running style check..." |
| 151 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 152 | if [ ! -z "$$gofmt_out" ]; then \ |
| 153 | echo "$$gofmt_out" ;\ |
| 154 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 155 | exit 1 ;\ |
| 156 | fi |
| 157 | @echo "Style check OK" |
| 158 | |
| 159 | lint-sanity: |
| 160 | @echo "Running sanity check..." |
| 161 | @go vet ./... |
| 162 | @echo "Sanity check OK" |
| 163 | |
| 164 | lint-dep: |
| 165 | @echo "Running dependency check..." |
| 166 | @dep check |
| 167 | @echo "Dependency check OK" |
| 168 | |
| 169 | lint: lint-style lint-sanity lint-dep |
| 170 | |
| 171 | GO_JUNIT_REPORT:=$(shell which go-junit-report) |
| 172 | GOCOVER_COBERTURA:=$(shell which gocover-cobertura) |
| 173 | test: |
| 174 | ifeq (,$(GO_JUNIT_REPORT)) |
| 175 | go get -u github.com/jstemmer/go-junit-report |
| 176 | @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
| 177 | endif |
| 178 | |
| 179 | ifeq (,$(GOCOVER_COBERTURA)) |
| 180 | go get -u github.com/t-yuki/gocover-cobertura |
| 181 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
| 182 | endif |
| 183 | |
| 184 | @mkdir -p ./tests/results |
| 185 | |
| 186 | @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
| 187 | RETURN=$$? ;\ |
| 188 | $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 189 | $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 190 | exit $$RETURN |
| 191 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 192 | GOLANGCI_LINT_TOOL:=$(shell which golangci-lint) |
| 193 | sca: |
| 194 | ifeq (,$(GOLANGCI_LINT_TOOL)) |
| 195 | @echo "Please install golangci-lint tool to run sca" |
| 196 | exit 1 |
| 197 | endif |
| 198 | @mkdir -p ./sca-report |
| 199 | GO111MODULE=on golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml ;\ |
| 200 | RETURN=$$? ;\ |
| 201 | exit $$RETURN |
| 202 | |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 203 | clean: |
| 204 | rm -rf python/local_imports |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 205 | rm -rf sca-report |
Matt Jeanneret | b5bf10e | 2019-05-18 15:02:51 -0400 | [diff] [blame] | 206 | find python -name '*.pyc' | xargs rm -f |
| 207 | |
| 208 | distclean: clean |
| 209 | rm -rf ${VENVDIR} |
| 210 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 211 | # end file |