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 | |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 17 | SHELL=/bin/bash -e -o pipefail |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 18 | |
Zack Williams | 27f59a4 | 2019-05-10 09:12:07 -0700 | [diff] [blame] | 19 | # Variables |
| 20 | VERSION ?= $(shell cat ./VERSION) |
| 21 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 22 | ifeq ($(TAG),) |
| 23 | TAG := latest |
| 24 | endif |
| 25 | |
| 26 | ifeq ($(TARGET_TAG),) |
| 27 | TARGET_TAG := latest |
| 28 | endif |
| 29 | |
| 30 | # If no DOCKER_HOST_IP is specified grab a v4 IP address associated with |
| 31 | # the default gateway |
| 32 | ifeq ($(DOCKER_HOST_IP),) |
| 33 | DOCKER_HOST_IP := $(shell ifconfig $$(netstat -rn | grep -E '^(default|0.0.0.0)' | head -1 | awk '{print $$NF}') | grep inet | awk '{print $$2}' | sed -e 's/addr://g') |
| 34 | endif |
| 35 | |
| 36 | |
| 37 | ifneq ($(http_proxy)$(https_proxy),) |
| 38 | # Include proxies from the environment |
| 39 | DOCKER_PROXY_ARGS = \ |
| 40 | --build-arg http_proxy=$(http_proxy) \ |
| 41 | --build-arg https_proxy=$(https_proxy) \ |
| 42 | --build-arg ftp_proxy=$(ftp_proxy) \ |
| 43 | --build-arg no_proxy=$(no_proxy) \ |
| 44 | --build-arg HTTP_PROXY=$(HTTP_PROXY) \ |
| 45 | --build-arg HTTPS_PROXY=$(HTTPS_PROXY) \ |
| 46 | --build-arg FTP_PROXY=$(FTP_PROXY) \ |
| 47 | --build-arg NO_PROXY=$(NO_PROXY) |
| 48 | endif |
| 49 | |
| 50 | DOCKER_BUILD_ARGS = \ |
| 51 | --build-arg TAG=$(TAG) \ |
| 52 | --build-arg REGISTRY=$(REGISTRY) \ |
| 53 | --build-arg REPOSITORY=$(REPOSITORY) \ |
| 54 | $(DOCKER_PROXY_ARGS) $(DOCKER_CACHE_ARG) \ |
| 55 | --rm --force-rm \ |
| 56 | $(DOCKER_BUILD_EXTRA_ARGS) |
| 57 | |
| 58 | DOCKER_IMAGE_LIST = \ |
| 59 | rw_core |
| 60 | |
| 61 | |
Stephane Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 62 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) rw_core ro_core protos kafka db tests python simulators k8s afrouter arouterd base |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 63 | |
| 64 | # This should to be the first and default target in this Makefile |
| 65 | help: |
| 66 | @echo "Usage: make [<target>]" |
| 67 | @echo "where available targets are:" |
| 68 | @echo |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 69 | @echo "build : Build the docker images." |
| 70 | @echo " - If this is the first time you are building, choose 'make build' option." |
| 71 | @echo "rw_core : Build the rw_core docker container" |
| 72 | @echo "ro_core : Build the ro_core docker container" |
| 73 | @echo "afrouter : Build the afrouter docker container" |
| 74 | @echo "afrouterTest : Build the afrouterTest docker container" |
| 75 | @echo "afrouterd : Build the afrouterd docker container" |
| 76 | @echo "simulated_olt : Build the simulated_olt docker container" |
| 77 | @echo "simulated_onu : Build the simulated_onu docker container" |
| 78 | @echo "lint-style : Verify code is properly gofmt-ed" |
| 79 | @echo "lint-sanity : Verify that 'go vet' doesn't report any issues" |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 80 | @echo "lint-dep : Verify the integrity of the `dep` files" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 81 | @echo "lint : Shorthand for lint-style & lint-sanity" |
| 82 | @echo "test : Generate reports for all go tests" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 83 | @echo |
| 84 | |
| 85 | |
| 86 | # Parallel Build |
| 87 | $(DIRS): |
| 88 | @echo " MK $@" |
| 89 | $(Q)$(MAKE) -C $@ |
| 90 | |
| 91 | # Parallel Clean |
| 92 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 93 | $(DIRS_CLEAN): |
| 94 | @echo " CLEAN $(basename $@)" |
| 95 | $(Q)$(MAKE) -C $(basename $@) clean |
| 96 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 97 | build: containers |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 98 | |
Stephane Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 99 | containers: base rw_core ro_core simulated_olt simulated_onu afrouter arouterd |
sslobodr | 2fb98b8 | 2019-01-21 09:29:51 -0500 | [diff] [blame] | 100 | |
| 101 | base: |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 102 | ifdef LOCAL_PROTOS |
| 103 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
William Kurkian | 86e1837 | 2019-04-18 15:09:06 -0400 | [diff] [blame] | 104 | 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] | 105 | endif |
sslobodr | 2fb98b8 | 2019-01-21 09:29:51 -0500 | [diff] [blame] | 106 | docker build $(DOCKER_BUILD_ARGS) -t base:latest -f docker/Dockerfile.base . |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 107 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 108 | afrouter: base |
sslobodr | 38afd0d | 2019-01-21 12:31:46 -0500 | [diff] [blame] | 109 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouter:${TAG} -f docker/Dockerfile.arouter . |
sslobodr | a3ea7d4 | 2019-01-16 15:03:16 -0500 | [diff] [blame] | 110 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 111 | afrouterTest: base |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 112 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afroutertest:${TAG} -f docker/Dockerfile.arouterTest . |
| 113 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 114 | arouterd: base |
sslobodr | 38afd0d | 2019-01-21 12:31:46 -0500 | [diff] [blame] | 115 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouterd:${TAG} -f docker/Dockerfile.arouterd . |
sslobodr | a3ea7d4 | 2019-01-16 15:03:16 -0500 | [diff] [blame] | 116 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 117 | rw_core: base |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 118 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-rw-core:${TAG} -f docker/Dockerfile.rw_core . |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 119 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 120 | ro_core: base |
Stephane Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 121 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ro-core:${TAG} -f docker/Dockerfile.ro_core . |
| 122 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 123 | simulated_olt: base |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 124 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-olt:${TAG} -f docker/Dockerfile.simulated_olt . |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 125 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 126 | simulated_onu: base |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 127 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-onu:${TAG} -f docker/Dockerfile.simulated_onu . |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 128 | |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 129 | lint-style: |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 130 | ifeq (,$(shell which gofmt)) |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 131 | go get -u github.com/golang/go/src/cmd/gofmt |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 132 | endif |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 133 | @echo "Running style check..." |
| 134 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 135 | if [ ! -z "$$gofmt_out" ]; then \ |
| 136 | echo "$$gofmt_out" ;\ |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 137 | 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] | 138 | exit 1 ;\ |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 139 | fi |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 140 | @echo "Style check OK" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 141 | |
| 142 | lint-sanity: |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 143 | @echo "Running sanity check..." |
| 144 | @go vet ./... |
| 145 | @echo "Sanity check OK" |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 146 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 147 | lint-dep: |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 148 | @echo "Running dependency check..." |
| 149 | @dep check |
| 150 | @echo "Dependency check OK" |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 151 | |
| 152 | lint: lint-style lint-sanity lint-dep |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 153 | |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 154 | GO_JUNIT_REPORT:=$(shell which go-junit-report) |
| 155 | GOCOVER_COBERTURA:=$(shell which gocover-cobertura) |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 156 | test: |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 157 | ifeq (,$(GO_JUNIT_REPORT)) |
| 158 | go get -u github.com/jstemmer/go-junit-report |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 159 | @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 160 | endif |
| 161 | |
| 162 | ifeq (,$(GOCOVER_COBERTURA)) |
| 163 | go get -u github.com/t-yuki/gocover-cobertura |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 164 | @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 165 | endif |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 166 | |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 167 | @mkdir -p ./tests/results |
Zack Williams | 7cf7800 | 2019-04-30 21:45:35 -0700 | [diff] [blame] | 168 | |
Kent Hagerman | ca4c51e | 2019-05-02 12:28:55 -0400 | [diff] [blame] | 169 | @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] | 170 | RETURN=$$? ;\ |
| 171 | $(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 172 | $(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 173 | exit $$RETURN |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 174 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 175 | # end file |