blob: 81f09f38e54946e59a8e320bb1940b1931fd34f7 [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
Matt Jeanneretf880eb62019-07-16 20:08:03 -040023DOCKER_LABEL_VCS_DIRTY = false
24ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
25 DOCKER_LABEL_VCS_DIRTY = true
26endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040027## Docker related
Matt Jeanneretf880eb62019-07-16 20:08:03 -040028DOCKER_EXTRA_ARGS ?=
Matt Jeanneret8b823f62019-05-11 11:01:28 -040029DOCKER_REGISTRY ?=
30DOCKER_REPOSITORY ?=
Matt Jeanneret8b823f62019-05-11 11:01:28 -040031DOCKER_TAG ?= ${VERSION}
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040032GOADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}-go
33PYTHONADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}-py
34ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}
Matt Jeanneret8b823f62019-05-11 11:01:28 -040035
36## Docker labels. Only set ref and commit date if committed
Matt Jeanneretf880eb62019-07-16 20:08:03 -040037DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
38DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
39DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
40DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
Matt Jeanneret8b823f62019-05-11 11:01:28 -040041
Matt Jeanneretf880eb62019-07-16 20:08:03 -040042DOCKER_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
51DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
52 --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \
53 --build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
Phaneendra Manda4c62c802019-03-06 21:37:49 +053054
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040055.PHONY: docker-build openolt_go openolt_python local-protos local-volthago local-pyvoltha
Phaneendra Manda4c62c802019-03-06 21:37:49 +053056
57# This should to be the first and default target in this Makefile
58help:
59 @echo "Usage: make [<target>]"
60 @echo "where available targets are:"
61 @echo
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040062 @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 Jeanneret8b823f62019-05-11 11:01:28 -040065 @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 Gowdru6a80bbd2019-07-02 07:36:09 -070068 @echo "sca : Runs various SCA through golangci-lint tool"
Matt Jeanneret8b823f62019-05-11 11:01:28 -040069 @echo "test : Run unit tests, if any"
Phaneendra Manda4c62c802019-03-06 21:37:49 +053070 @echo
71
72
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040073## Local Development Helpers
Phaneendra Manda4c62c802019-03-06 21:37:49 +053074
Matt Jeanneret8b823f62019-05-11 11:01:28 -040075local-protos:
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040076 mkdir -p python/local_imports
William Kurkianea869482019-04-09 15:16:11 -040077ifdef LOCAL_PROTOS
78 mkdir -p vendor/github.com/opencord/voltha-protos/go
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040079 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/
82endif
83
84local-pyvoltha:
85 mkdir -p python/local_imports
86ifdef LOCAL_PYVOLTHA
87 mkdir -p python/local_imports/pyvoltha/dist
88 cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/
William Kurkianea869482019-04-09 15:16:11 -040089endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040090
91local-volthago:
William Kurkianea869482019-04-09 15:16:11 -040092ifdef 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
96endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040097
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040098
99## Python venv dev environment
100
101VENVDIR := python/venv-openolt
102
103venv: 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
109ifdef LOCAL_PYVOLTHA
110 source ./${VENVDIR}/bin/activate ; set -u ;\
111 pip install python/local_imports/pyvoltha/dist/*.tar.gz
112endif
113ifdef LOCAL_PROTOS
114 source ./${VENVDIR}/bin/activate ; set -u ;\
115 pip install python/local_imports/voltha-protos/dist/*.tar.gz
116endif
117
118
119## Docker targets
120
121build: docker-build
122
123docker-build: openolt_go openolt_python
124
125openolt_go: local-protos local-volthago
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400126 docker build $(DOCKER_BUILD_ARGS) -t ${GOADAPTER_IMAGENAME} -f docker/Dockerfile.openolt .
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400127
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400128openolt_python: local-protos local-pyvoltha
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400129 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${PYTHONADAPTER_IMAGENAME} -f python/docker/Dockerfile.openolt_adapter python
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400130
131 # Current default image gets the base DOCKER_TAG
Matt Jeanneret2a831e92019-08-01 07:02:11 -0400132 docker tag ${GOADAPTER_IMAGENAME} ${ADAPTER_IMAGENAME}
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400133
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400134docker-push:
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400135 docker push ${GOADAPTER_IMAGENAME}
136 docker push ${PYTHONADAPTER_IMAGENAME}
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400137 docker push ${ADAPTER_IMAGENAME}
138
139
140## lint and unit tests
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530141
Matt Jeanneret384d8c92019-05-06 14:27:31 -0400142lint-style:
143ifeq (,$(shell which gofmt))
144 go get -u github.com/golang/go/src/cmd/gofmt
145endif
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
155lint-sanity:
156 @echo "Running sanity check..."
157 @go vet ./...
158 @echo "Sanity check OK"
159
160lint-dep:
161 @echo "Running dependency check..."
162 @dep check
163 @echo "Dependency check OK"
164
165lint: lint-style lint-sanity lint-dep
166
167GO_JUNIT_REPORT:=$(shell which go-junit-report)
168GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
169test:
170ifeq (,$(GO_JUNIT_REPORT))
171 go get -u github.com/jstemmer/go-junit-report
172 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
173endif
174
175ifeq (,$(GOCOVER_COBERTURA))
176 go get -u github.com/t-yuki/gocover-cobertura
177 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
178endif
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 Gowdru6a80bbd2019-07-02 07:36:09 -0700188GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
189sca:
190ifeq (,$(GOLANGCI_LINT_TOOL))
191 @echo "Please install golangci-lint tool to run sca"
192 exit 1
193endif
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 Jeanneretb5bf10e2019-05-18 15:02:51 -0400199clean:
200 rm -rf python/local_imports
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700201 rm -rf sca-report
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400202 find python -name '*.pyc' | xargs rm -f
203
204distclean: clean
205 rm -rf ${VENVDIR}
206
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530207# end file