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