blob: 147b4052329ba287b6eaa78107df15f6e79d8db2 [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}
30AFROUTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}afrouter:${DOCKER_TAG}
31AFROUTERTEST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}afroutertest:${DOCKER_TAG}
32AFROUTERD_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}afrouterd:${DOCKER_TAG}
33SIMULATEDOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-olt:${DOCKER_TAG}
34SIMULATEDONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-onu:${DOCKER_TAG}
35
36## Docker labels. Only set ref and commit date if committed
37DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
38DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
39DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
40
41ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
42 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
43else
44 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
khenaidoocfee5f42018-07-19 22:47:38 -040045endif
46
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040047.PHONY: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd local-protos
khenaidoocfee5f42018-07-19 22:47:38 -040048
49# This should to be the first and default target in this Makefile
50help:
51 @echo "Usage: make [<target>]"
52 @echo "where available targets are:"
53 @echo
Kent Hagerman074d0e02019-04-24 17:58:16 -040054 @echo "build : Build the docker images."
55 @echo " - If this is the first time you are building, choose 'make build' option."
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040056 @echo "rw_core : Build the rw_core docker image"
57 @echo "ro_core : Build the ro_core docker image"
58 @echo "afrouter : Build the afrouter docker image"
59 @echo "afrouterTest : Build the afrouterTest docker image"
60 @echo "afrouterd : Build the afrouterd docker image"
61 @echo "simulated_olt : Build the simulated_olt docker image"
62 @echo "simulated_onu : Build the simulated_onu docker image"
63 @echo "docker-push : Push the docker images to an external repository"
Kent Hagerman074d0e02019-04-24 17:58:16 -040064 @echo "lint-style : Verify code is properly gofmt-ed"
65 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040066 @echo "lint-dep : Verify the integrity of the 'dep' files"
Kent Hagerman074d0e02019-04-24 17:58:16 -040067 @echo "lint : Shorthand for lint-style & lint-sanity"
68 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040069 @echo
70
71
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040072## Docker targets
khenaidoocfee5f42018-07-19 22:47:38 -040073
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040074build: docker-build
khenaidoocfee5f42018-07-19 22:47:38 -040075
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040076docker-build: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd
khenaidoocfee5f42018-07-19 22:47:38 -040077
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040078local-protos:
William Kurkiandaa6bb22019-03-07 12:26:28 -050079ifdef LOCAL_PROTOS
80 mkdir -p vendor/github.com/opencord/voltha-protos/go
William Kurkian86e18372019-04-18 15:09:06 -040081 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
William Kurkiandaa6bb22019-03-07 12:26:28 -050082endif
khenaidoocfee5f42018-07-19 22:47:38 -040083
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040084afrouter: local-protos
85 docker build $(DOCKER_BUILD_ARGS) \
86 -t ${AFROUTER_IMAGENAME} \
87 --build-arg org_label_schema_version="${VERSION}" \
88 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
89 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
90 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
91 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
92 -f docker/Dockerfile.afrouter .
sslobodra3ea7d42019-01-16 15:03:16 -050093
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040094afrouterTest: local-protos
95 docker build $(DOCKER_BUILD_ARGS) \
96 -t ${AFROUTERTEST_IMAGENAME} \
97 --build-arg org_label_schema_version="${VERSION}" \
98 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
99 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
100 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
101 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
102 -f docker/Dockerfile.afrouterTest .
sslobodrd6e07e72019-01-31 16:07:20 -0500103
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400104afrouterd: local-protos
105 docker build $(DOCKER_BUILD_ARGS) \
106 -t ${AFROUTERD_IMAGENAME} \
107 --build-arg org_label_schema_version="${VERSION}" \
108 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
109 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
110 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
111 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
112 -f docker/Dockerfile.afrouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500113
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400114rw_core: local-protos
115 docker build $(DOCKER_BUILD_ARGS) \
116 -t ${RWCORE_IMAGENAME} \
117 --build-arg org_label_schema_version="${VERSION}" \
118 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
119 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
120 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
121 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
122 -f docker/Dockerfile.rw_core .
khenaidoocfee5f42018-07-19 22:47:38 -0400123
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400124ro_core: local-protos
125 docker build $(DOCKER_BUILD_ARGS) \
126 -t ${ROCORE_IMAGENAME} \
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 docker/Dockerfile.ro_core .
Stephane Barbariea75791c2019-01-24 10:58:06 -0500133
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400134simulated_olt: local-protos
135 docker build $(DOCKER_BUILD_ARGS) \
136 -t ${SIMULATEDOLT_IMAGENAME} \
137 --build-arg org_label_schema_version="${VERSION}" \
138 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
139 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
140 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
141 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
142 -f docker/Dockerfile.simulated_olt .
khenaidood2b6df92018-12-13 16:37:20 -0500143
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400144simulated_onu: local-protos
145 docker build $(DOCKER_BUILD_ARGS) \
146 -t ${SIMULATEDONU_IMAGENAME} \
147 --build-arg org_label_schema_version="${VERSION}" \
148 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
149 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
150 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
151 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
152 -f docker/Dockerfile.simulated_onu .
153
154docker-push:
155 docker push ${AFROUTER_IMAGENAME}
156 docker push ${AFROUTERTEST_IMAGENAME}
157 docker push ${AFROUTERD_IMAGENAME}
158 docker push ${RWCORE_IMAGENAME}
159 docker push ${ROCORE_IMAGENAME}
160 docker push ${SIMULATEDOLT_IMAGENAME}
161 docker push ${SIMULATEDONU_IMAGENAME}
162
163
164## lint and unit tests
khenaidood2b6df92018-12-13 16:37:20 -0500165
Kent Hagerman074d0e02019-04-24 17:58:16 -0400166lint-style:
Zack Williams7cf78002019-04-30 21:45:35 -0700167ifeq (,$(shell which gofmt))
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400168 go get -u github.com/golang/go/src/cmd/gofmt
Zack Williams7cf78002019-04-30 21:45:35 -0700169endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400170 @echo "Running style check..."
171 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700172 if [ ! -z "$$gofmt_out" ]; then \
173 echo "$$gofmt_out" ;\
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400174 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700175 exit 1 ;\
Kent Hagerman074d0e02019-04-24 17:58:16 -0400176 fi
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400177 @echo "Style check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400178
179lint-sanity:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400180 @echo "Running sanity check..."
181 @go vet ./...
182 @echo "Sanity check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400183
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400184lint-dep:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400185 @echo "Running dependency check..."
186 @dep check
187 @echo "Dependency check OK"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400188
189lint: lint-style lint-sanity lint-dep
Kent Hagerman074d0e02019-04-24 17:58:16 -0400190
Zack Williams7cf78002019-04-30 21:45:35 -0700191GO_JUNIT_REPORT:=$(shell which go-junit-report)
192GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
Kent Hagerman074d0e02019-04-24 17:58:16 -0400193test:
Zack Williams7cf78002019-04-30 21:45:35 -0700194ifeq (,$(GO_JUNIT_REPORT))
195 go get -u github.com/jstemmer/go-junit-report
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400196 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
Zack Williams7cf78002019-04-30 21:45:35 -0700197endif
198
199ifeq (,$(GOCOVER_COBERTURA))
200 go get -u github.com/t-yuki/gocover-cobertura
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400201 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
Zack Williams7cf78002019-04-30 21:45:35 -0700202endif
Kent Hagerman074d0e02019-04-24 17:58:16 -0400203
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400204 @mkdir -p ./tests/results
Zack Williams7cf78002019-04-30 21:45:35 -0700205
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400206 @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 -0700207 RETURN=$$? ;\
208 $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
209 $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
210 exit $$RETURN
Kent Hagerman074d0e02019-04-24 17:58:16 -0400211
khenaidoocfee5f42018-07-19 22:47:38 -0400212# end file