khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 1 | # |
| 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 Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 17 | # set default shell |
| 18 | SHELL = bash -e -o pipefail |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 19 | |
Zack Williams | 27f59a4 | 2019-05-10 09:12:07 -0700 | [diff] [blame] | 20 | # Variables |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 21 | VERSION ?= $(shell cat ./VERSION) |
Zack Williams | 27f59a4 | 2019-05-10 09:12:07 -0700 | [diff] [blame] | 22 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 23 | ## Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | RWCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-rw-core:${DOCKER_TAG} |
| 29 | ROCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ro-core:${DOCKER_TAG} |
| 30 | AFROUTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}afrouter:${DOCKER_TAG} |
| 31 | AFROUTERTEST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}afroutertest:${DOCKER_TAG} |
| 32 | AFROUTERD_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}afrouterd:${DOCKER_TAG} |
| 33 | SIMULATEDOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-olt:${DOCKER_TAG} |
| 34 | SIMULATEDONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-simulated-onu:${DOCKER_TAG} |
| 35 | |
| 36 | ## Docker labels. Only set ref and commit date if committed |
| 37 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 38 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 39 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 40 | |
| 41 | ifeq ($(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) |
| 43 | else |
| 44 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 45 | endif |
| 46 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 47 | .PHONY: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd local-protos |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 48 | |
| 49 | # This should to be the first and default target in this Makefile |
| 50 | help: |
| 51 | @echo "Usage: make [<target>]" |
| 52 | @echo "where available targets are:" |
| 53 | @echo |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 54 | @echo "build : Build the docker images." |
| 55 | @echo " - If this is the first time you are building, choose 'make build' option." |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 56 | @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 Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 64 | @echo "lint-style : Verify code is properly gofmt-ed" |
| 65 | @echo "lint-sanity : Verify that 'go vet' doesn't report any issues" |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 66 | @echo "lint-dep : Verify the integrity of the 'dep' files" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 67 | @echo "lint : Shorthand for lint-style & lint-sanity" |
| 68 | @echo "test : Generate reports for all go tests" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 69 | @echo |
| 70 | |
| 71 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 72 | ## Docker targets |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 73 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 74 | build: docker-build |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 75 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 76 | docker-build: rw_core ro_core simulated_olt simulated_onu afrouter afrouterd |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 77 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 78 | local-protos: |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 79 | ifdef LOCAL_PROTOS |
| 80 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
William Kurkian | 86e1837 | 2019-04-18 15:09:06 -0400 | [diff] [blame] | 81 | cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 82 | endif |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 83 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 84 | afrouter: 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 . |
sslobodr | a3ea7d4 | 2019-01-16 15:03:16 -0500 | [diff] [blame] | 93 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 94 | afrouterTest: 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 . |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 103 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 104 | afrouterd: 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 . |
sslobodr | a3ea7d4 | 2019-01-16 15:03:16 -0500 | [diff] [blame] | 113 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 114 | rw_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 . |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 123 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 124 | ro_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 Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 133 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 134 | simulated_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 . |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 143 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 144 | simulated_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 | |
| 154 | docker-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 |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 165 | |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 166 | lint-style: |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 167 | ifeq (,$(shell which gofmt)) |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 168 | go get -u github.com/golang/go/src/cmd/gofmt |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 169 | endif |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 170 | @echo "Running style check..." |
| 171 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 172 | if [ ! -z "$$gofmt_out" ]; then \ |
| 173 | echo "$$gofmt_out" ;\ |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 174 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 175 | exit 1 ;\ |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 176 | fi |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 177 | @echo "Style check OK" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 178 | |
| 179 | lint-sanity: |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 180 | @echo "Running sanity check..." |
| 181 | @go vet ./... |
| 182 | @echo "Sanity check OK" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 183 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 184 | lint-dep: |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 185 | @echo "Running dependency check..." |
| 186 | @dep check |
| 187 | @echo "Dependency check OK" |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 188 | |
| 189 | lint: lint-style lint-sanity lint-dep |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 190 | |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 191 | GO_JUNIT_REPORT:=$(shell which go-junit-report) |
| 192 | GOCOVER_COBERTURA:=$(shell which gocover-cobertura) |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 193 | test: |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 194 | ifeq (,$(GO_JUNIT_REPORT)) |
| 195 | go get -u github.com/jstemmer/go-junit-report |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 196 | @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 197 | endif |
| 198 | |
| 199 | ifeq (,$(GOCOVER_COBERTURA)) |
| 200 | go get -u github.com/t-yuki/gocover-cobertura |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 201 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 202 | endif |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 203 | |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 204 | @mkdir -p ./tests/results |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 205 | |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 206 | @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 207 | 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 Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 211 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 212 | # end file |