blob: 63d2f359ca05dd4a2f8588c251f29aeddfd3c1d2 [file] [log] [blame]
khenaidoocfee5f42018-07-19 22:47:38 -04001#
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 Jeanneret2e3051a2019-05-11 15:01:46 -040017# set default shell
18SHELL = bash -e -o pipefail
Kent Hagerman074d0e02019-04-24 17:58:16 -040019
Zack Williams27f59a42019-05-10 09:12:07 -070020# Variables
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040021VERSION ?= $(shell cat ./VERSION)
Zack Williams27f59a42019-05-10 09:12:07 -070022
Kent Hagermanf4a3aab2019-05-22 14:42:34 -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 Jeanneret2e3051a2019-05-11 15:01:46 -040027## Docker related
David K. Bainbridgee14914d2019-05-24 13:43:05 -070028DOCKER_EXTRA_ARGS ?=
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040029DOCKER_REGISTRY ?=
30DOCKER_REPOSITORY ?=
31DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true)
32RWCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-rw-core
33ROCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ro-core
34AFROUTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afrouter
35AFROUTERTEST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afroutertest
36AFROUTERD_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afrouterd
37SIMULATEDOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-olt
38SIMULATEDONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-onu
39OFAGENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent
40CLI_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli
41PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt
42PONSIMONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-onu
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040043
44## Docker labels. Only set ref and commit date if committed
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040045DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
46DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
47DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
48DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040049
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040050DOCKER_BUILD_ARGS ?= \
David K. Bainbridgee14914d2019-05-24 13:43:05 -070051 ${DOCKER_EXTRA_ARGS} \
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040052 --build-arg org_label_schema_version="${VERSION}" \
53 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
54 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
55 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
56 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
57 --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
58
59DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
60 --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \
61 --build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
khenaidoocfee5f42018-07-19 22:47:38 -040062
David K. Bainbridge1678e192019-05-17 11:48:29 -070063.PHONY: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd local-protos local-pyvoltha
khenaidoocfee5f42018-07-19 22:47:38 -040064
65# This should to be the first and default target in this Makefile
66help:
67 @echo "Usage: make [<target>]"
68 @echo "where available targets are:"
69 @echo
David K. Bainbridge1678e192019-05-17 11:48:29 -070070 @echo "build : Build the docker images."
71 @echo " - If this is the first time you are building, choose 'make build' option."
72 @echo "rw_core : Build the rw_core docker image"
73 @echo "ro_core : Build the ro_core docker image"
74 @echo "afrouter : Build the afrouter docker image"
75 @echo "afrouterTest : Build the afrouterTest docker image"
76 @echo "afrouterd : Build the afrouterd docker image"
77 @echo "simulated_olt : Build the simulated_olt docker image"
78 @echo "simulated_onu : Build the simulated_onu docker image"
79 @echo "ofagent : Build the openflow agent docker image"
80 @echo "cli : Build the voltha CLI docker image"
81 @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker image"
82 @echo "adapter_ponsim_onu : Build the ponsim onu adapter docker image"
83 @echo "venv : Build local Python virtualenv"
84 @echo "clean : Remove files created by the build and tests"
85 @echo "distclean : Remove venv directory"
86 @echo "docker-push : Push the docker images to an external repository"
David Bainbridge5f3619c2019-07-10 22:51:09 +000087 @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
David K. Bainbridge1678e192019-05-17 11:48:29 -070088 @echo "lint-style : Verify code is properly gofmt-ed"
89 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
90 @echo "lint-dep : Verify the integrity of the 'dep' files"
91 @echo "lint : Shorthand for lint-style & lint-sanity"
92 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040093 @echo
94
David K. Bainbridge1678e192019-05-17 11:48:29 -070095## Local Development Helpers
96local-protos:
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040097 @mkdir -p python/local_imports
David K. Bainbridge1678e192019-05-17 11:48:29 -070098ifdef LOCAL_PROTOS
99 mkdir -p vendor/github.com/opencord/voltha-protos/go
100 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
101 mkdir -p python/local_imports/voltha-protos/dist
102 cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/
103endif
104
105local-pyvoltha:
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400106 @mkdir -p python/local_imports
David K. Bainbridge1678e192019-05-17 11:48:29 -0700107ifdef LOCAL_PYVOLTHA
108 mkdir -p python/local_imports/pyvoltha/dist
109 cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/
110endif
111
112## Python venv dev environment
113
114VENVDIR := python/venv-volthago
115
116venv: distclean local-protos local-pyvoltha
117 virtualenv ${VENVDIR};\
118 source ./${VENVDIR}/bin/activate ; set -u ;\
119 rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
120 pip install -r python/requirements.txt
121ifdef LOCAL_PYVOLTHA
122 source ./${VENVDIR}/bin/activate ; set -u ;\
123 pip install python/local_imports/pyvoltha/dist/*.tar.gz
124endif
125ifdef LOCAL_PROTOS
126 source ./${VENVDIR}/bin/activate ; set -u ;\
127 pip install python/local_imports/voltha-protos/dist/*.tar.gz
128endif
khenaidoocfee5f42018-07-19 22:47:38 -0400129
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400130## Docker targets
khenaidoocfee5f42018-07-19 22:47:38 -0400131
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400132build: docker-build
khenaidoocfee5f42018-07-19 22:47:38 -0400133
David K. Bainbridge1678e192019-05-17 11:48:29 -0700134docker-build: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd ofagent cli adapter_ponsim_olt adapter_ponsim_onu
khenaidoocfee5f42018-07-19 22:47:38 -0400135
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400136afrouter: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400137 docker build $(DOCKER_BUILD_ARGS) -t ${AFROUTER_IMAGENAME}:${DOCKER_TAG} -t ${AFROUTER_IMAGENAME}:latest -f docker/Dockerfile.afrouter .
sslobodra3ea7d42019-01-16 15:03:16 -0500138
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400139afrouterTest: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400140 docker build $(DOCKER_BUILD_ARGS) -t ${AFROUTERTEST_IMAGENAME}:${DOCKER_TAG} -t ${AFROUTERTEST_IMAGENAME}:latest -f docker/Dockerfile.afrouterTest .
sslobodrd6e07e72019-01-31 16:07:20 -0500141
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400142afrouterd: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400143 docker build $(DOCKER_BUILD_ARGS) -t ${AFROUTERD_IMAGENAME}:${DOCKER_TAG} -t ${AFROUTERD_IMAGENAME}:latest -f docker/Dockerfile.afrouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500144
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400145rw_core: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400146 docker build $(DOCKER_BUILD_ARGS) -t ${RWCORE_IMAGENAME}:${DOCKER_TAG} -t ${RWCORE_IMAGENAME}:latest -f docker/Dockerfile.rw_core .
khenaidoocfee5f42018-07-19 22:47:38 -0400147
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400148ro_core: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400149 docker build $(DOCKER_BUILD_ARGS) -t ${ROCORE_IMAGENAME}:${DOCKER_TAG} -t ${ROCORE_IMAGENAME}:latest -f docker/Dockerfile.ro_core .
Stephane Barbariea75791c2019-01-24 10:58:06 -0500150
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400151simulated_olt: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400152 docker build $(DOCKER_BUILD_ARGS) -t ${SIMULATEDOLT_IMAGENAME}:${DOCKER_TAG} -t ${SIMULATEDOLT_IMAGENAME}:latest -f docker/Dockerfile.simulated_olt .
khenaidood2b6df92018-12-13 16:37:20 -0500153
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400154simulated_onu: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400155 docker build $(DOCKER_BUILD_ARGS) -t ${SIMULATEDONU_IMAGENAME}:${DOCKER_TAG} -t ${SIMULATEDONU_IMAGENAME}:latest -f docker/Dockerfile.simulated_onu .
David K. Bainbridge1678e192019-05-17 11:48:29 -0700156
157ofagent: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400158 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${OFAGENT_IMAGENAME}:${DOCKER_TAG} -t ${OFAGENT_IMAGENAME}:latest -f python/docker/Dockerfile.ofagent python
David K. Bainbridge1678e192019-05-17 11:48:29 -0700159
160cli: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400161 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${CLI_IMAGENAME}:${DOCKER_TAG} -t ${CLI_IMAGENAME}:latest -f python/docker/Dockerfile.cli python
David K. Bainbridge1678e192019-05-17 11:48:29 -0700162
163adapter_ponsim_olt: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400164 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG} -t ${PONSIMOLT_IMAGENAME}:latest -f python/docker/Dockerfile.adapter_ponsim_olt python
David K. Bainbridge1678e192019-05-17 11:48:29 -0700165
166adapter_ponsim_onu: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400167 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${PONSIMONU_IMAGENAME}:${DOCKER_TAG} -t ${PONSIMONU_IMAGENAME}:latest -f python/docker/Dockerfile.adapter_ponsim_onu python
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400168
169docker-push:
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400170 docker push ${AFROUTER_IMAGENAME}:${DOCKER_TAG}
171 docker push ${AFROUTERD_IMAGENAME}:${DOCKER_TAG}
172 docker push ${RWCORE_IMAGENAME}:${DOCKER_TAG}
173 docker push ${ROCORE_IMAGENAME}:${DOCKER_TAG}
174 docker push ${SIMULATEDOLT_IMAGENAME}:${DOCKER_TAG}
175 docker push ${SIMULATEDONU_IMAGENAME}:${DOCKER_TAG}
176 docker push ${OFAGENT_IMAGENAME}:${DOCKER_TAG}
177 docker push ${CLI_IMAGENAME}:${DOCKER_TAG}
178 docker push ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG}
179 docker push ${PONSIMONU_IMAGENAME}:${DOCKER_TAG}
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400180
181## lint and unit tests
khenaidood2b6df92018-12-13 16:37:20 -0500182
David Bainbridge5f3619c2019-07-10 22:51:09 +0000183PATH:=$(GOPATH)/bin:$(PATH)
184HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
185lint-dockerfile:
186ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint))
187 mkdir -p $(GOPATH)/bin
188 curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m)
189 chmod 755 $(GOPATH)/bin/hadolint
190endif
191 @echo "Running Dockerfile lint check ..."
192 @hadolint $$(find . -name "Dockerfile.*")
193 @echo "Dockerfile lint check OK"
194
Kent Hagerman074d0e02019-04-24 17:58:16 -0400195lint-style:
Zack Williams7cf78002019-04-30 21:45:35 -0700196ifeq (,$(shell which gofmt))
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400197 go get -u github.com/golang/go/src/cmd/gofmt
Zack Williams7cf78002019-04-30 21:45:35 -0700198endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400199 @echo "Running style check..."
200 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700201 if [ ! -z "$$gofmt_out" ]; then \
202 echo "$$gofmt_out" ;\
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400203 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700204 exit 1 ;\
Kent Hagerman074d0e02019-04-24 17:58:16 -0400205 fi
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400206 @echo "Style check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400207
208lint-sanity:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400209 @echo "Running sanity check..."
210 @go vet ./...
211 @echo "Sanity check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400212
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400213lint-dep:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400214 @echo "Running dependency check..."
215 @dep check
216 @echo "Dependency check OK"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400217
David Bainbridge5f3619c2019-07-10 22:51:09 +0000218lint: lint-style lint-sanity lint-dep lint-dockerfile
Kent Hagerman074d0e02019-04-24 17:58:16 -0400219
Zack Williams7cf78002019-04-30 21:45:35 -0700220GO_JUNIT_REPORT:=$(shell which go-junit-report)
221GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
David K. Bainbridge1678e192019-05-17 11:48:29 -0700222
Kent Hagerman074d0e02019-04-24 17:58:16 -0400223test:
Zack Williams7cf78002019-04-30 21:45:35 -0700224ifeq (,$(GO_JUNIT_REPORT))
225 go get -u github.com/jstemmer/go-junit-report
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400226 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
Zack Williams7cf78002019-04-30 21:45:35 -0700227endif
Zack Williams7cf78002019-04-30 21:45:35 -0700228ifeq (,$(GOCOVER_COBERTURA))
229 go get -u github.com/t-yuki/gocover-cobertura
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400230 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
Zack Williams7cf78002019-04-30 21:45:35 -0700231endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400232 @mkdir -p ./tests/results
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400233 @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700234 RETURN=$$? ;\
235 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
236 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
237 exit $$RETURN
Kent Hagerman074d0e02019-04-24 17:58:16 -0400238
David K. Bainbridge1678e192019-05-17 11:48:29 -0700239clean:
240 rm -rf python/local_imports
241 find python -name '*.pyc' | xargs rm -f
242
243distclean: clean
244 rm -rf ${VENVDIR}
245
khenaidoocfee5f42018-07-19 22:47:38 -0400246# end file