blob: 59a94ede4d837ad529c709f2a5082aa145a1e6b7 [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
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040021VERSION ?= $(shell cat ./VERSION)
Zack Williams27f59a42019-05-10 09:12:07 -070022
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040023## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28RWCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-rw-core:${DOCKER_TAG}
29ROCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ro-core:${DOCKER_TAG}
David K. Bainbridge1678e192019-05-17 11:48:29 -070030AFROUTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afrouter:${DOCKER_TAG}
31AFROUTERTEST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afroutertest:${DOCKER_TAG}
32AFROUTERD_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-afrouterd:${DOCKER_TAG}
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040033SIMULATEDOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-olt:${DOCKER_TAG}
34SIMULATEDONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-onu:${DOCKER_TAG}
David K. Bainbridge1678e192019-05-17 11:48:29 -070035OFAGENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent:${DOCKER_TAG}
36CLI_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli:${DOCKER_TAG}
37PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt:${DOCKER_TAG}
38PONSIMONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-onu:${DOCKER_TAG}
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040039
40## Docker labels. Only set ref and commit date if committed
41DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
42DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
43DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
44
45ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
46 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
47else
48 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
khenaidoocfee5f42018-07-19 22:47:38 -040049endif
50
David K. Bainbridge1678e192019-05-17 11:48:29 -070051.PHONY: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd local-protos local-pyvoltha
khenaidoocfee5f42018-07-19 22:47:38 -040052
53# This should to be the first and default target in this Makefile
54help:
55 @echo "Usage: make [<target>]"
56 @echo "where available targets are:"
57 @echo
David K. Bainbridge1678e192019-05-17 11:48:29 -070058 @echo "build : Build the docker images."
59 @echo " - If this is the first time you are building, choose 'make build' option."
60 @echo "rw_core : Build the rw_core docker image"
61 @echo "ro_core : Build the ro_core docker image"
62 @echo "afrouter : Build the afrouter docker image"
63 @echo "afrouterTest : Build the afrouterTest docker image"
64 @echo "afrouterd : Build the afrouterd docker image"
65 @echo "simulated_olt : Build the simulated_olt docker image"
66 @echo "simulated_onu : Build the simulated_onu docker image"
67 @echo "ofagent : Build the openflow agent docker image"
68 @echo "cli : Build the voltha CLI docker image"
69 @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker image"
70 @echo "adapter_ponsim_onu : Build the ponsim onu adapter docker image"
71 @echo "venv : Build local Python virtualenv"
72 @echo "clean : Remove files created by the build and tests"
73 @echo "distclean : Remove venv directory"
74 @echo "docker-push : Push the docker images to an external repository"
75 @echo "lint-style : Verify code is properly gofmt-ed"
76 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
77 @echo "lint-dep : Verify the integrity of the 'dep' files"
78 @echo "lint : Shorthand for lint-style & lint-sanity"
79 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040080 @echo
81
David K. Bainbridge1678e192019-05-17 11:48:29 -070082## Local Development Helpers
83local-protos:
84 mkdir -p python/local_imports
85ifdef LOCAL_PROTOS
86 mkdir -p vendor/github.com/opencord/voltha-protos/go
87 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
88 mkdir -p python/local_imports/voltha-protos/dist
89 cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/
90endif
91
92local-pyvoltha:
93 mkdir -p python/local_imports
94ifdef LOCAL_PYVOLTHA
95 mkdir -p python/local_imports/pyvoltha/dist
96 cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/
97endif
98
99## Python venv dev environment
100
101VENVDIR := python/venv-volthago
102
103venv: distclean local-protos local-pyvoltha
104 virtualenv ${VENVDIR};\
105 source ./${VENVDIR}/bin/activate ; set -u ;\
106 rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
107 pip install -r python/requirements.txt
108ifdef LOCAL_PYVOLTHA
109 source ./${VENVDIR}/bin/activate ; set -u ;\
110 pip install python/local_imports/pyvoltha/dist/*.tar.gz
111endif
112ifdef LOCAL_PROTOS
113 source ./${VENVDIR}/bin/activate ; set -u ;\
114 pip install python/local_imports/voltha-protos/dist/*.tar.gz
115endif
khenaidoocfee5f42018-07-19 22:47:38 -0400116
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400117## Docker targets
khenaidoocfee5f42018-07-19 22:47:38 -0400118
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400119build: docker-build
khenaidoocfee5f42018-07-19 22:47:38 -0400120
David K. Bainbridge1678e192019-05-17 11:48:29 -0700121docker-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 -0400122
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400123afrouter: local-protos
124 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700125 -t ${AFROUTER_IMAGENAME} \
126 --build-arg org_label_schema_version="${VERSION}" \
127 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
128 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
129 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
130 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
131 -f docker/Dockerfile.afrouter .
sslobodra3ea7d42019-01-16 15:03:16 -0500132
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400133afrouterTest: local-protos
134 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700135 -t ${AFROUTERTEST_IMAGENAME} \
136 --build-arg org_label_schema_version="${VERSION}" \
137 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
138 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
139 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
140 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
141 -f docker/Dockerfile.afrouterTest .
sslobodrd6e07e72019-01-31 16:07:20 -0500142
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400143afrouterd: local-protos
144 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700145 -t ${AFROUTERD_IMAGENAME} \
146 --build-arg org_label_schema_version="${VERSION}" \
147 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
148 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
149 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
150 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
151 -f docker/Dockerfile.afrouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500152
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400153rw_core: local-protos
154 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700155 -t ${RWCORE_IMAGENAME} \
156 --build-arg org_label_schema_version="${VERSION}" \
157 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
158 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
159 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
160 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
161 -f docker/Dockerfile.rw_core .
khenaidoocfee5f42018-07-19 22:47:38 -0400162
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400163ro_core: local-protos
164 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700165 -t ${ROCORE_IMAGENAME} \
166 --build-arg org_label_schema_version="${VERSION}" \
167 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
168 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
169 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
170 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
171 -f docker/Dockerfile.ro_core .
Stephane Barbariea75791c2019-01-24 10:58:06 -0500172
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400173simulated_olt: local-protos
174 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700175 -t ${SIMULATEDOLT_IMAGENAME} \
176 --build-arg org_label_schema_version="${VERSION}" \
177 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
178 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
179 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
180 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
181 -f docker/Dockerfile.simulated_olt .
khenaidood2b6df92018-12-13 16:37:20 -0500182
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400183simulated_onu: local-protos
184 docker build $(DOCKER_BUILD_ARGS) \
David K. Bainbridge1678e192019-05-17 11:48:29 -0700185 -t ${SIMULATEDONU_IMAGENAME} \
186 --build-arg org_label_schema_version="${VERSION}" \
187 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
188 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
189 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
190 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
191 -f docker/Dockerfile.simulated_onu .
192
193ofagent: local-protos local-pyvoltha
194 docker build $(DOCKER_BUILD_ARGS) \
195 -t ${OFAGENT_IMAGENAME} \
196 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
197 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
198 --build-arg org_label_schema_version="${VERSION}" \
199 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
200 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
201 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
202 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
203 -f python/docker/Dockerfile.ofagent python
204
205cli: local-protos local-pyvoltha
206 docker build $(DOCKER_BUILD_ARGS) \
207 -t ${CLI_IMAGENAME} \
208 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
209 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
210 --build-arg org_label_schema_version="${VERSION}" \
211 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
212 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
213 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
214 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
215 -f python/docker/Dockerfile.cli python
216
217adapter_ponsim_olt: local-protos local-pyvoltha
218 docker build $(DOCKER_BUILD_ARGS) \
219 -t ${PONSIMOLT_IMAGENAME} \
220 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
221 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
222 --build-arg org_label_schema_version="${VERSION}" \
223 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
224 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
225 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
226 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
227 -f python/docker/Dockerfile.adapter_ponsim_olt python
228
229adapter_ponsim_onu: local-protos local-pyvoltha
230 docker build $(DOCKER_BUILD_ARGS) \
231 -t ${PONSIMONU_IMAGENAME} \
232 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
233 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
234 --build-arg org_label_schema_version="${VERSION}" \
235 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
236 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
237 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
238 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
239 -f python/docker/Dockerfile.adapter_ponsim_onu python
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400240
241docker-push:
242 docker push ${AFROUTER_IMAGENAME}
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400243 docker push ${AFROUTERD_IMAGENAME}
244 docker push ${RWCORE_IMAGENAME}
245 docker push ${ROCORE_IMAGENAME}
246 docker push ${SIMULATEDOLT_IMAGENAME}
247 docker push ${SIMULATEDONU_IMAGENAME}
David K. Bainbridge1678e192019-05-17 11:48:29 -0700248 docker push ${OFAGENT_IMAGENAME}
249 docker push ${CLI_IMAGENAME}
250 docker push ${PONSIMOLT_IMAGENAME}
251 docker push ${PONSIMONU_IMAGENAME}
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400252
253## lint and unit tests
khenaidood2b6df92018-12-13 16:37:20 -0500254
Kent Hagerman074d0e02019-04-24 17:58:16 -0400255lint-style:
Zack Williams7cf78002019-04-30 21:45:35 -0700256ifeq (,$(shell which gofmt))
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400257 go get -u github.com/golang/go/src/cmd/gofmt
Zack Williams7cf78002019-04-30 21:45:35 -0700258endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400259 @echo "Running style check..."
260 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700261 if [ ! -z "$$gofmt_out" ]; then \
262 echo "$$gofmt_out" ;\
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400263 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700264 exit 1 ;\
Kent Hagerman074d0e02019-04-24 17:58:16 -0400265 fi
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400266 @echo "Style check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400267
268lint-sanity:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400269 @echo "Running sanity check..."
270 @go vet ./...
271 @echo "Sanity check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400272
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400273lint-dep:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400274 @echo "Running dependency check..."
275 @dep check
276 @echo "Dependency check OK"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400277
278lint: lint-style lint-sanity lint-dep
Kent Hagerman074d0e02019-04-24 17:58:16 -0400279
Zack Williams7cf78002019-04-30 21:45:35 -0700280GO_JUNIT_REPORT:=$(shell which go-junit-report)
281GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
David K. Bainbridge1678e192019-05-17 11:48:29 -0700282
Kent Hagerman074d0e02019-04-24 17:58:16 -0400283test:
Zack Williams7cf78002019-04-30 21:45:35 -0700284ifeq (,$(GO_JUNIT_REPORT))
285 go get -u github.com/jstemmer/go-junit-report
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400286 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
Zack Williams7cf78002019-04-30 21:45:35 -0700287endif
Zack Williams7cf78002019-04-30 21:45:35 -0700288ifeq (,$(GOCOVER_COBERTURA))
289 go get -u github.com/t-yuki/gocover-cobertura
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400290 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
Zack Williams7cf78002019-04-30 21:45:35 -0700291endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400292 @mkdir -p ./tests/results
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400293 @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 -0700294 RETURN=$$? ;\
295 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
296 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
297 exit $$RETURN
Kent Hagerman074d0e02019-04-24 17:58:16 -0400298
David K. Bainbridge1678e192019-05-17 11:48:29 -0700299clean:
300 rm -rf python/local_imports
301 find python -name '*.pyc' | xargs rm -f
302
303distclean: clean
304 rm -rf ${VENVDIR}
305
khenaidoocfee5f42018-07-19 22:47:38 -0400306# end file