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} |
| 28 | ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter-go:${DOCKER_TAG} |
| 29 | |
| 30 | ## Docker labels. Only set ref and commit date if committed |
| 31 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 32 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 33 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 34 | |
| 35 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 36 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 37 | else |
| 38 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 39 | endif |
| 40 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 41 | .PHONY: docker-build local-protos local-volthago |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 42 | |
| 43 | # This should to be the first and default target in this Makefile |
| 44 | help: |
| 45 | @echo "Usage: make [<target>]" |
| 46 | @echo "where available targets are:" |
| 47 | @echo |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 48 | @echo "build : Build the openolt adapter docker image" |
| 49 | @echo "help : Print this help" |
| 50 | @echo "docker-push : Push the docker images to an external repository" |
| 51 | @echo "lint : Run lint verification, depenancy, gofmt and reference check" |
| 52 | @echo "test : Run unit tests, if any" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 53 | @echo |
| 54 | |
| 55 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 56 | ## Docker targets |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 57 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 58 | build: docker-build |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 59 | |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 60 | local-protos: |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 61 | ifdef LOCAL_PROTOS |
| 62 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
| 63 | cp -rf ${GOPATH}/src/github.com/opencord/voltha-protos/go/ vendor/github.com/opencord/voltha-protos |
| 64 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 65 | |
| 66 | local-volthago: |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 67 | ifdef LOCAL_VOLTHAGO |
| 68 | mkdir -p vendor/github.com/opencord/voltha-go/ |
| 69 | cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/ |
| 70 | rm -rf vendor/github.com/opencord/voltha-go/vendor |
| 71 | endif |
Matt Jeanneret | 8b823f6 | 2019-05-11 11:01:28 -0400 | [diff] [blame^] | 72 | |
| 73 | docker-build: local-protos local-volthago |
| 74 | docker build $(DOCKER_BUILD_ARGS) \ |
| 75 | -t ${ADAPTER_IMAGENAME} \ |
| 76 | --build-arg org_label_schema_version="${VERSION}" \ |
| 77 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 78 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 79 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 80 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 81 | -f docker/Dockerfile.openolt . |
| 82 | |
| 83 | docker-push: |
| 84 | docker push ${ADAPTER_IMAGENAME} |
| 85 | |
| 86 | |
| 87 | ## lint and unit tests |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 88 | |
Matt Jeanneret | 384d8c9 | 2019-05-06 14:27:31 -0400 | [diff] [blame] | 89 | lint-style: |
| 90 | ifeq (,$(shell which gofmt)) |
| 91 | go get -u github.com/golang/go/src/cmd/gofmt |
| 92 | endif |
| 93 | @echo "Running style check..." |
| 94 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 95 | if [ ! -z "$$gofmt_out" ]; then \ |
| 96 | echo "$$gofmt_out" ;\ |
| 97 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 98 | exit 1 ;\ |
| 99 | fi |
| 100 | @echo "Style check OK" |
| 101 | |
| 102 | lint-sanity: |
| 103 | @echo "Running sanity check..." |
| 104 | @go vet ./... |
| 105 | @echo "Sanity check OK" |
| 106 | |
| 107 | lint-dep: |
| 108 | @echo "Running dependency check..." |
| 109 | @dep check |
| 110 | @echo "Dependency check OK" |
| 111 | |
| 112 | lint: lint-style lint-sanity lint-dep |
| 113 | |
| 114 | GO_JUNIT_REPORT:=$(shell which go-junit-report) |
| 115 | GOCOVER_COBERTURA:=$(shell which gocover-cobertura) |
| 116 | test: |
| 117 | ifeq (,$(GO_JUNIT_REPORT)) |
| 118 | go get -u github.com/jstemmer/go-junit-report |
| 119 | @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
| 120 | endif |
| 121 | |
| 122 | ifeq (,$(GOCOVER_COBERTURA)) |
| 123 | go get -u github.com/t-yuki/gocover-cobertura |
| 124 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
| 125 | endif |
| 126 | |
| 127 | @mkdir -p ./tests/results |
| 128 | |
| 129 | @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
| 130 | RETURN=$$? ;\ |
| 131 | $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 132 | $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 133 | exit $$RETURN |
| 134 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 135 | # end file |