blob: 37099bef25b21ceebc66219e4f816d35d52f8278 [file] [log] [blame]
Phaneendra Manda4c62c802019-03-06 21:37:49 +05301#
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 Jeanneret8b823f62019-05-11 11:01:28 -040017# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ./VERSION)
22
23## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter-go:${DOCKER_TAG}
29
30## Docker labels. Only set ref and commit date if committed
31DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
32DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
33DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
34
35ifeq ($(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)
37else
38 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
Phaneendra Manda4c62c802019-03-06 21:37:49 +053039endif
40
Matt Jeanneret8b823f62019-05-11 11:01:28 -040041.PHONY: docker-build local-protos local-volthago
Phaneendra Manda4c62c802019-03-06 21:37:49 +053042
43# This should to be the first and default target in this Makefile
44help:
45 @echo "Usage: make [<target>]"
46 @echo "where available targets are:"
47 @echo
Matt Jeanneret8b823f62019-05-11 11:01:28 -040048 @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 Manda4c62c802019-03-06 21:37:49 +053053 @echo
54
55
Matt Jeanneret8b823f62019-05-11 11:01:28 -040056## Docker targets
Phaneendra Manda4c62c802019-03-06 21:37:49 +053057
Matt Jeanneret8b823f62019-05-11 11:01:28 -040058build: docker-build
Phaneendra Manda4c62c802019-03-06 21:37:49 +053059
Matt Jeanneret8b823f62019-05-11 11:01:28 -040060local-protos:
William Kurkianea869482019-04-09 15:16:11 -040061ifdef 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
64endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040065
66local-volthago:
William Kurkianea869482019-04-09 15:16:11 -040067ifdef 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
71endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040072
73docker-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
83docker-push:
84 docker push ${ADAPTER_IMAGENAME}
85
86
87## lint and unit tests
Phaneendra Manda4c62c802019-03-06 21:37:49 +053088
Matt Jeanneret384d8c92019-05-06 14:27:31 -040089lint-style:
90ifeq (,$(shell which gofmt))
91 go get -u github.com/golang/go/src/cmd/gofmt
92endif
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
102lint-sanity:
103 @echo "Running sanity check..."
104 @go vet ./...
105 @echo "Sanity check OK"
106
107lint-dep:
108 @echo "Running dependency check..."
109 @dep check
110 @echo "Dependency check OK"
111
112lint: lint-style lint-sanity lint-dep
113
114GO_JUNIT_REPORT:=$(shell which go-junit-report)
115GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
116test:
117ifeq (,$(GO_JUNIT_REPORT))
118 go get -u github.com/jstemmer/go-junit-report
119 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
120endif
121
122ifeq (,$(GOCOVER_COBERTURA))
123 go get -u github.com/t-yuki/gocover-cobertura
124 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
125endif
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 Manda4c62c802019-03-06 21:37:49 +0530135# end file