blob: e97238c166c47e321251d3287d85eaaa9fd4c179 [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}
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040028GOADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}-go
29PYTHONADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}-py
30ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openolt-adapter:${DOCKER_TAG}
Matt Jeanneret8b823f62019-05-11 11:01:28 -040031
32## Docker labels. Only set ref and commit date if committed
33DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
34DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
35DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
36
37ifeq ($(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)
39else
40 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
Phaneendra Manda4c62c802019-03-06 21:37:49 +053041endif
42
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040043.PHONY: docker-build openolt_go openolt_python local-protos local-volthago local-pyvoltha
Phaneendra Manda4c62c802019-03-06 21:37:49 +053044
45# This should to be the first and default target in this Makefile
46help:
47 @echo "Usage: make [<target>]"
48 @echo "where available targets are:"
49 @echo
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040050 @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 Jeanneret8b823f62019-05-11 11:01:28 -040053 @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"
56 @echo "test : Run unit tests, if any"
Phaneendra Manda4c62c802019-03-06 21:37:49 +053057 @echo
58
59
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040060## Local Development Helpers
Phaneendra Manda4c62c802019-03-06 21:37:49 +053061
Matt Jeanneret8b823f62019-05-11 11:01:28 -040062local-protos:
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040063 mkdir -p python/local_imports
William Kurkianea869482019-04-09 15:16:11 -040064ifdef LOCAL_PROTOS
65 mkdir -p vendor/github.com/opencord/voltha-protos/go
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040066 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
67 mkdir -p python/local_imports/voltha-protos/dist
68 cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/
69endif
70
71local-pyvoltha:
72 mkdir -p python/local_imports
73ifdef LOCAL_PYVOLTHA
74 mkdir -p python/local_imports/pyvoltha/dist
75 cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/
William Kurkianea869482019-04-09 15:16:11 -040076endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040077
78local-volthago:
William Kurkianea869482019-04-09 15:16:11 -040079ifdef LOCAL_VOLTHAGO
80 mkdir -p vendor/github.com/opencord/voltha-go/
81 cp -rf ${GOPATH}/src/github.com/opencord/voltha-go/ vendor/github.com/opencord/
82 rm -rf vendor/github.com/opencord/voltha-go/vendor
83endif
Matt Jeanneret8b823f62019-05-11 11:01:28 -040084
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -040085
86## Python venv dev environment
87
88VENVDIR := python/venv-openolt
89
90venv: distclean local-protos local-pyvoltha
91 virtualenv ${VENVDIR};\
92 source ./${VENVDIR}/bin/activate ; set -u ;\
93 rm ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
94 pip install -r python/requirements.txt
95
96ifdef LOCAL_PYVOLTHA
97 source ./${VENVDIR}/bin/activate ; set -u ;\
98 pip install python/local_imports/pyvoltha/dist/*.tar.gz
99endif
100ifdef LOCAL_PROTOS
101 source ./${VENVDIR}/bin/activate ; set -u ;\
102 pip install python/local_imports/voltha-protos/dist/*.tar.gz
103endif
104
105
106## Docker targets
107
108build: docker-build
109
110docker-build: openolt_go openolt_python
111
112openolt_go: local-protos local-volthago
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400113 docker build $(DOCKER_BUILD_ARGS) \
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400114 -t ${GOADAPTER_IMAGENAME} \
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400115 --build-arg org_label_schema_version="${VERSION}" \
116 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
117 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
118 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
119 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
120 -f docker/Dockerfile.openolt .
121
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400122openolt_python: local-protos local-pyvoltha
123 docker build $(DOCKER_BUILD_ARGS) \
124 -t ${PYTHONADAPTER_IMAGENAME} \
125 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
126 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
127 --build-arg org_label_schema_version="${VERSION}" \
128 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
129 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
130 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
131 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
132 -f python/docker/Dockerfile.openolt_adapter python
133
134 # Current default image gets the base DOCKER_TAG
135 docker tag ${PYTHONADAPTER_IMAGENAME} ${ADAPTER_IMAGENAME}
136
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400137docker-push:
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400138 docker push ${GOADAPTER_IMAGENAME}
139 docker push ${PYTHONADAPTER_IMAGENAME}
Matt Jeanneret8b823f62019-05-11 11:01:28 -0400140 docker push ${ADAPTER_IMAGENAME}
141
142
143## lint and unit tests
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530144
Matt Jeanneret384d8c92019-05-06 14:27:31 -0400145lint-style:
146ifeq (,$(shell which gofmt))
147 go get -u github.com/golang/go/src/cmd/gofmt
148endif
149 @echo "Running style check..."
150 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
151 if [ ! -z "$$gofmt_out" ]; then \
152 echo "$$gofmt_out" ;\
153 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
154 exit 1 ;\
155 fi
156 @echo "Style check OK"
157
158lint-sanity:
159 @echo "Running sanity check..."
160 @go vet ./...
161 @echo "Sanity check OK"
162
163lint-dep:
164 @echo "Running dependency check..."
165 @dep check
166 @echo "Dependency check OK"
167
168lint: lint-style lint-sanity lint-dep
169
170GO_JUNIT_REPORT:=$(shell which go-junit-report)
171GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
172test:
173ifeq (,$(GO_JUNIT_REPORT))
174 go get -u github.com/jstemmer/go-junit-report
175 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
176endif
177
178ifeq (,$(GOCOVER_COBERTURA))
179 go get -u github.com/t-yuki/gocover-cobertura
180 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
181endif
182
183 @mkdir -p ./tests/results
184
185 @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
186 RETURN=$$? ;\
187 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
188 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
189 exit $$RETURN
190
Matt Jeanneretb5bf10e2019-05-18 15:02:51 -0400191clean:
192 rm -rf python/local_imports
193 find python -name '*.pyc' | xargs rm -f
194
195distclean: clean
196 rm -rf ${VENVDIR}
197
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530198# end file