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