blob: 3632dc2f126912c38d49152ae15fb36df6420172 [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
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040028DOCKER_REGISTRY ?=
29DOCKER_REPOSITORY ?=
30DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true)
31RWCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-rw-core
32ROCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ro-core
33AFROUTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afrouter
34AFROUTERTEST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afroutertest
35AFROUTERD_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afrouterd
36SIMULATEDOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-olt
37SIMULATEDONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-onu
38OFAGENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent
39CLI_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli
40PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt
41PONSIMONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-onu
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040042
43## Docker labels. Only set ref and commit date if committed
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040044DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
45DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
46DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
47DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040048
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040049DOCKER_BUILD_ARGS ?= \
50 --build-arg org_label_schema_version="${VERSION}" \
51 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
52 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
53 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
54 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
55 --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
56
57DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
58 --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \
59 --build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
khenaidoocfee5f42018-07-19 22:47:38 -040060
David K. Bainbridge1678e192019-05-17 11:48:29 -070061.PHONY: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd local-protos local-pyvoltha
khenaidoocfee5f42018-07-19 22:47:38 -040062
63# This should to be the first and default target in this Makefile
64help:
65 @echo "Usage: make [<target>]"
66 @echo "where available targets are:"
67 @echo
David K. Bainbridge1678e192019-05-17 11:48:29 -070068 @echo "build : Build the docker images."
69 @echo " - If this is the first time you are building, choose 'make build' option."
70 @echo "rw_core : Build the rw_core docker image"
71 @echo "ro_core : Build the ro_core docker image"
72 @echo "afrouter : Build the afrouter docker image"
73 @echo "afrouterTest : Build the afrouterTest docker image"
74 @echo "afrouterd : Build the afrouterd docker image"
75 @echo "simulated_olt : Build the simulated_olt docker image"
76 @echo "simulated_onu : Build the simulated_onu docker image"
77 @echo "ofagent : Build the openflow agent docker image"
78 @echo "cli : Build the voltha CLI docker image"
79 @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker image"
80 @echo "adapter_ponsim_onu : Build the ponsim onu adapter docker image"
81 @echo "venv : Build local Python virtualenv"
82 @echo "clean : Remove files created by the build and tests"
83 @echo "distclean : Remove venv directory"
84 @echo "docker-push : Push the docker images to an external repository"
85 @echo "lint-style : Verify code is properly gofmt-ed"
86 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
87 @echo "lint-dep : Verify the integrity of the 'dep' files"
88 @echo "lint : Shorthand for lint-style & lint-sanity"
89 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040090 @echo
91
David K. Bainbridge1678e192019-05-17 11:48:29 -070092## Local Development Helpers
93local-protos:
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040094 @mkdir -p python/local_imports
David K. Bainbridge1678e192019-05-17 11:48:29 -070095ifdef LOCAL_PROTOS
96 mkdir -p vendor/github.com/opencord/voltha-protos/go
97 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
98 mkdir -p python/local_imports/voltha-protos/dist
99 cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/
100endif
101
102local-pyvoltha:
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400103 @mkdir -p python/local_imports
David K. Bainbridge1678e192019-05-17 11:48:29 -0700104ifdef LOCAL_PYVOLTHA
105 mkdir -p python/local_imports/pyvoltha/dist
106 cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/
107endif
108
109## Python venv dev environment
110
111VENVDIR := python/venv-volthago
112
113venv: distclean local-protos local-pyvoltha
114 virtualenv ${VENVDIR};\
115 source ./${VENVDIR}/bin/activate ; set -u ;\
116 rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
117 pip install -r python/requirements.txt
118ifdef LOCAL_PYVOLTHA
119 source ./${VENVDIR}/bin/activate ; set -u ;\
120 pip install python/local_imports/pyvoltha/dist/*.tar.gz
121endif
122ifdef LOCAL_PROTOS
123 source ./${VENVDIR}/bin/activate ; set -u ;\
124 pip install python/local_imports/voltha-protos/dist/*.tar.gz
125endif
khenaidoocfee5f42018-07-19 22:47:38 -0400126
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400127## Docker targets
khenaidoocfee5f42018-07-19 22:47:38 -0400128
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400129build: docker-build
khenaidoocfee5f42018-07-19 22:47:38 -0400130
David K. Bainbridge1678e192019-05-17 11:48:29 -0700131docker-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 -0400132
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400133afrouter: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400134 docker build $(DOCKER_BUILD_ARGS) -t ${AFROUTER_IMAGENAME}:${DOCKER_TAG} -t ${AFROUTER_IMAGENAME}:latest -f docker/Dockerfile.afrouter .
sslobodra3ea7d42019-01-16 15:03:16 -0500135
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400136afrouterTest: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400137 docker build $(DOCKER_BUILD_ARGS) -t ${AFROUTERTEST_IMAGENAME}:${DOCKER_TAG} -t ${AFROUTERTEST_IMAGENAME}:latest -f docker/Dockerfile.afrouterTest .
sslobodrd6e07e72019-01-31 16:07:20 -0500138
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400139afrouterd: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400140 docker build $(DOCKER_BUILD_ARGS) -t ${AFROUTERD_IMAGENAME}:${DOCKER_TAG} -t ${AFROUTERD_IMAGENAME}:latest -f docker/Dockerfile.afrouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500141
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400142rw_core: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400143 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 -0400144
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400145ro_core: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400146 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 -0500147
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400148simulated_olt: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400149 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 -0500150
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400151simulated_onu: local-protos
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400152 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 -0700153
154ofagent: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400155 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 -0700156
157cli: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400158 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 -0700159
160adapter_ponsim_olt: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400161 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 -0700162
163adapter_ponsim_onu: local-protos local-pyvoltha
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400164 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 -0400165
166docker-push:
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400167 docker push ${AFROUTER_IMAGENAME}:${DOCKER_TAG}
168 docker push ${AFROUTERD_IMAGENAME}:${DOCKER_TAG}
169 docker push ${RWCORE_IMAGENAME}:${DOCKER_TAG}
170 docker push ${ROCORE_IMAGENAME}:${DOCKER_TAG}
171 docker push ${SIMULATEDOLT_IMAGENAME}:${DOCKER_TAG}
172 docker push ${SIMULATEDONU_IMAGENAME}:${DOCKER_TAG}
173 docker push ${OFAGENT_IMAGENAME}:${DOCKER_TAG}
174 docker push ${CLI_IMAGENAME}:${DOCKER_TAG}
175 docker push ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG}
176 docker push ${PONSIMONU_IMAGENAME}:${DOCKER_TAG}
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400177
178## lint and unit tests
khenaidood2b6df92018-12-13 16:37:20 -0500179
Kent Hagerman074d0e02019-04-24 17:58:16 -0400180lint-style:
Zack Williams7cf78002019-04-30 21:45:35 -0700181ifeq (,$(shell which gofmt))
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400182 go get -u github.com/golang/go/src/cmd/gofmt
Zack Williams7cf78002019-04-30 21:45:35 -0700183endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400184 @echo "Running style check..."
185 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700186 if [ ! -z "$$gofmt_out" ]; then \
187 echo "$$gofmt_out" ;\
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400188 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700189 exit 1 ;\
Kent Hagerman074d0e02019-04-24 17:58:16 -0400190 fi
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400191 @echo "Style check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400192
193lint-sanity:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400194 @echo "Running sanity check..."
195 @go vet ./...
196 @echo "Sanity check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400197
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400198lint-dep:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400199 @echo "Running dependency check..."
200 @dep check
201 @echo "Dependency check OK"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400202
203lint: lint-style lint-sanity lint-dep
Kent Hagerman074d0e02019-04-24 17:58:16 -0400204
Zack Williams7cf78002019-04-30 21:45:35 -0700205GO_JUNIT_REPORT:=$(shell which go-junit-report)
206GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
David K. Bainbridge1678e192019-05-17 11:48:29 -0700207
Kent Hagerman074d0e02019-04-24 17:58:16 -0400208test:
Zack Williams7cf78002019-04-30 21:45:35 -0700209ifeq (,$(GO_JUNIT_REPORT))
210 go get -u github.com/jstemmer/go-junit-report
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400211 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
Zack Williams7cf78002019-04-30 21:45:35 -0700212endif
Zack Williams7cf78002019-04-30 21:45:35 -0700213ifeq (,$(GOCOVER_COBERTURA))
214 go get -u github.com/t-yuki/gocover-cobertura
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400215 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
Zack Williams7cf78002019-04-30 21:45:35 -0700216endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400217 @mkdir -p ./tests/results
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400218 @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 -0700219 RETURN=$$? ;\
220 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
221 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
222 exit $$RETURN
Kent Hagerman074d0e02019-04-24 17:58:16 -0400223
David K. Bainbridge1678e192019-05-17 11:48:29 -0700224clean:
225 rm -rf python/local_imports
226 find python -name '*.pyc' | xargs rm -f
227
228distclean: clean
229 rm -rf ${VENVDIR}
230
khenaidoocfee5f42018-07-19 22:47:38 -0400231# end file