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 |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 21 | VERSION ?= $(shell cat ./VERSION) |
Zack Williams | 27f59a4 | 2019-05-10 09:12:07 -0700 | [diff] [blame] | 22 | |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 23 | DOCKER_LABEL_VCS_DIRTY = false |
| 24 | ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 25 | DOCKER_LABEL_VCS_DIRTY = true |
| 26 | endif |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 27 | ## Docker related |
David K. Bainbridge | e14914d | 2019-05-24 13:43:05 -0700 | [diff] [blame] | 28 | DOCKER_EXTRA_ARGS ?= |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 29 | DOCKER_REGISTRY ?= |
| 30 | DOCKER_REPOSITORY ?= |
| 31 | DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true) |
| 32 | RWCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-rw-core |
| 33 | ROCORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ro-core |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 34 | OFAGENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent |
| 35 | CLI_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 36 | |
| 37 | ## Docker labels. Only set ref and commit date if committed |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 38 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 39 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 40 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 41 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 42 | |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 43 | DOCKER_BUILD_ARGS ?= \ |
David K. Bainbridge | e14914d | 2019-05-24 13:43:05 -0700 | [diff] [blame] | 44 | ${DOCKER_EXTRA_ARGS} \ |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 45 | --build-arg org_label_schema_version="${VERSION}" \ |
| 46 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 47 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 48 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 49 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 50 | --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}" |
| 51 | |
| 52 | DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \ |
| 53 | --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \ |
| 54 | --build-arg LOCAL_PROTOS=${LOCAL_PROTOS} |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 55 | |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 56 | .PHONY: rw_core ro_core local-protos local-pyvoltha |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 57 | |
| 58 | # This should to be the first and default target in this Makefile |
| 59 | help: |
| 60 | @echo "Usage: make [<target>]" |
| 61 | @echo "where available targets are:" |
| 62 | @echo |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 63 | @echo "build : Build the docker images." |
| 64 | @echo " - If this is the first time you are building, choose 'make build' option." |
| 65 | @echo "rw_core : Build the rw_core docker image" |
| 66 | @echo "ro_core : Build the ro_core docker image" |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 67 | @echo "ofagent : Build the openflow agent docker image" |
| 68 | @echo "cli : Build the voltha CLI docker image" |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 69 | @echo "venv : Build local Python virtualenv" |
| 70 | @echo "clean : Remove files created by the build and tests" |
| 71 | @echo "distclean : Remove venv directory" |
| 72 | @echo "docker-push : Push the docker images to an external repository" |
David Bainbridge | 5f3619c | 2019-07-10 22:51:09 +0000 | [diff] [blame] | 73 | @echo "lint-dockerfile : Perform static analysis on Dockerfiles" |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 74 | @echo "lint-style : Verify code is properly gofmt-ed" |
| 75 | @echo "lint-sanity : Verify that 'go vet' doesn't report any issues" |
| 76 | @echo "lint-dep : Verify the integrity of the 'dep' files" |
| 77 | @echo "lint : Shorthand for lint-style & lint-sanity" |
| 78 | @echo "test : Generate reports for all go tests" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 79 | @echo |
| 80 | |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 81 | ## Local Development Helpers |
| 82 | local-protos: |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 83 | @mkdir -p python/local_imports |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 84 | ifdef LOCAL_PROTOS |
| 85 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
| 86 | cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go |
William Kurkian | d4eccbc | 2019-07-30 10:17:21 -0400 | [diff] [blame] | 87 | rm -rf python/local_imports/voltha-protos |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 88 | mkdir -p python/local_imports/voltha-protos/dist |
| 89 | cp ../voltha-protos/dist/*.tar.gz python/local_imports/voltha-protos/dist/ |
| 90 | endif |
| 91 | |
| 92 | local-pyvoltha: |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 93 | @mkdir -p python/local_imports |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 94 | ifdef LOCAL_PYVOLTHA |
William Kurkian | d4eccbc | 2019-07-30 10:17:21 -0400 | [diff] [blame] | 95 | rm -rf python/local_imports/pyvoltha |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 96 | mkdir -p python/local_imports/pyvoltha/dist |
| 97 | cp ../pyvoltha/dist/*.tar.gz python/local_imports/pyvoltha/dist/ |
| 98 | endif |
| 99 | |
| 100 | ## Python venv dev environment |
| 101 | |
| 102 | VENVDIR := python/venv-volthago |
| 103 | |
| 104 | venv: distclean local-protos local-pyvoltha |
| 105 | virtualenv ${VENVDIR};\ |
| 106 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 107 | rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\ |
| 108 | pip install -r python/requirements.txt |
| 109 | ifdef LOCAL_PYVOLTHA |
| 110 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 111 | pip install python/local_imports/pyvoltha/dist/*.tar.gz |
| 112 | endif |
| 113 | ifdef LOCAL_PROTOS |
| 114 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 115 | pip install python/local_imports/voltha-protos/dist/*.tar.gz |
| 116 | endif |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 117 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 118 | ## Docker targets |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 119 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 120 | build: docker-build |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 121 | |
Scott Baker | 676f0dd | 2019-10-14 17:07:48 -0700 | [diff] [blame^] | 122 | docker-build: rw_core ro_core ofagent cli |
sslobodr | a3ea7d4 | 2019-01-16 15:03:16 -0500 | [diff] [blame] | 123 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 124 | rw_core: local-protos |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 125 | docker build $(DOCKER_BUILD_ARGS) -t ${RWCORE_IMAGENAME}:${DOCKER_TAG} -t ${RWCORE_IMAGENAME}:latest -f docker/Dockerfile.rw_core . |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 126 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 127 | ro_core: local-protos |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 128 | docker build $(DOCKER_BUILD_ARGS) -t ${ROCORE_IMAGENAME}:${DOCKER_TAG} -t ${ROCORE_IMAGENAME}:latest -f docker/Dockerfile.ro_core . |
Stephane Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 129 | |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 130 | ofagent: local-protos local-pyvoltha |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 131 | docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${OFAGENT_IMAGENAME}:${DOCKER_TAG} -t ${OFAGENT_IMAGENAME}:latest -f python/docker/Dockerfile.ofagent python |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 132 | |
| 133 | cli: local-protos local-pyvoltha |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 134 | docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${CLI_IMAGENAME}:${DOCKER_TAG} -t ${CLI_IMAGENAME}:latest -f python/docker/Dockerfile.cli python |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 135 | |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 136 | docker-push: |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 137 | docker push ${RWCORE_IMAGENAME}:${DOCKER_TAG} |
| 138 | docker push ${ROCORE_IMAGENAME}:${DOCKER_TAG} |
Kent Hagerman | f4a3aab | 2019-05-22 14:42:34 -0400 | [diff] [blame] | 139 | docker push ${OFAGENT_IMAGENAME}:${DOCKER_TAG} |
| 140 | docker push ${CLI_IMAGENAME}:${DOCKER_TAG} |
Matt Jeanneret | 2e3051a | 2019-05-11 15:01:46 -0400 | [diff] [blame] | 141 | |
| 142 | ## lint and unit tests |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 143 | |
David Bainbridge | 5f3619c | 2019-07-10 22:51:09 +0000 | [diff] [blame] | 144 | PATH:=$(GOPATH)/bin:$(PATH) |
| 145 | HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint) |
| 146 | lint-dockerfile: |
| 147 | ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint)) |
| 148 | mkdir -p $(GOPATH)/bin |
| 149 | curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m) |
| 150 | chmod 755 $(GOPATH)/bin/hadolint |
| 151 | endif |
| 152 | @echo "Running Dockerfile lint check ..." |
| 153 | @hadolint $$(find . -name "Dockerfile.*") |
| 154 | @echo "Dockerfile lint check OK" |
| 155 | |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 156 | lint-style: |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 157 | ifeq (,$(shell which gofmt)) |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 158 | go get -u github.com/golang/go/src/cmd/gofmt |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 159 | endif |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 160 | @echo "Running style check..." |
| 161 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 162 | if [ ! -z "$$gofmt_out" ]; then \ |
| 163 | echo "$$gofmt_out" ;\ |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 164 | 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] | 165 | exit 1 ;\ |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 166 | fi |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 167 | @echo "Style check OK" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 168 | |
| 169 | lint-sanity: |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 170 | @echo "Running sanity check..." |
| 171 | @go vet ./... |
| 172 | @echo "Sanity check OK" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 173 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 174 | lint-dep: |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 175 | @echo "Running dependency check..." |
| 176 | @dep check |
| 177 | @echo "Dependency check OK" |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 178 | |
David Bainbridge | 5f3619c | 2019-07-10 22:51:09 +0000 | [diff] [blame] | 179 | lint: lint-style lint-sanity lint-dep lint-dockerfile |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 180 | |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 181 | GO_JUNIT_REPORT:=$(shell which go-junit-report) |
| 182 | GOCOVER_COBERTURA:=$(shell which gocover-cobertura) |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 183 | |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 184 | test: |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 185 | ifeq (,$(GO_JUNIT_REPORT)) |
| 186 | go get -u github.com/jstemmer/go-junit-report |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 187 | @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 188 | endif |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 189 | ifeq (,$(GOCOVER_COBERTURA)) |
| 190 | go get -u github.com/t-yuki/gocover-cobertura |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 191 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 192 | endif |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 193 | @mkdir -p ./tests/results |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 194 | @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] | 195 | RETURN=$$? ;\ |
| 196 | $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 197 | $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 198 | exit $$RETURN |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 199 | |
David K. Bainbridge | 1678e19 | 2019-05-17 11:48:29 -0700 | [diff] [blame] | 200 | clean: |
| 201 | rm -rf python/local_imports |
| 202 | find python -name '*.pyc' | xargs rm -f |
| 203 | |
| 204 | distclean: clean |
| 205 | rm -rf ${VENVDIR} |
| 206 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 207 | # end file |