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 | |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 17 | SHELL=/bin/bash -o pipefail |
| 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" |
| 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 | |
| 81 | |
| 82 | # Parallel Build |
| 83 | $(DIRS): |
| 84 | @echo " MK $@" |
| 85 | $(Q)$(MAKE) -C $@ |
| 86 | |
| 87 | # Parallel Clean |
| 88 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 89 | $(DIRS_CLEAN): |
| 90 | @echo " CLEAN $(basename $@)" |
| 91 | $(Q)$(MAKE) -C $(basename $@) clean |
| 92 | |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 93 | build: containers |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 94 | |
Stephane Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 95 | containers: base rw_core ro_core simulated_olt simulated_onu afrouter arouterd |
sslobodr | 2fb98b8 | 2019-01-21 09:29:51 -0500 | [diff] [blame] | 96 | |
| 97 | base: |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 98 | ifdef LOCAL_PROTOS |
| 99 | mkdir -p vendor/github.com/opencord/voltha-protos/go |
William Kurkian | 86e1837 | 2019-04-18 15:09:06 -0400 | [diff] [blame] | 100 | 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] | 101 | endif |
sslobodr | 2fb98b8 | 2019-01-21 09:29:51 -0500 | [diff] [blame] | 102 | docker build $(DOCKER_BUILD_ARGS) -t base:latest -f docker/Dockerfile.base . |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 103 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 104 | afrouter: base |
sslobodr | 38afd0d | 2019-01-21 12:31:46 -0500 | [diff] [blame] | 105 | 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] | 106 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 107 | afrouterTest: base |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 108 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afroutertest:${TAG} -f docker/Dockerfile.arouterTest . |
| 109 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 110 | arouterd: base |
sslobodr | 38afd0d | 2019-01-21 12:31:46 -0500 | [diff] [blame] | 111 | 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] | 112 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 113 | rw_core: base |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 114 | 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] | 115 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 116 | ro_core: base |
Stephane Barbarie | a75791c | 2019-01-24 10:58:06 -0500 | [diff] [blame] | 117 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ro-core:${TAG} -f docker/Dockerfile.ro_core . |
| 118 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 119 | simulated_olt: base |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 120 | 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] | 121 | |
Matt Jeanneret | 85ab508 | 2019-04-01 11:29:20 -0400 | [diff] [blame] | 122 | simulated_onu: base |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 123 | 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] | 124 | |
Kent Hagerman | 074d0e0 | 2019-04-24 17:58:16 -0400 | [diff] [blame] | 125 | lint-style: |
| 126 | hash gofmt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ |
| 127 | go get -u github.com/golang/go/src/cmd/gofmt; \ |
| 128 | fi |
| 129 | |
| 130 | if [[ "$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*') | tee /dev/tty)" ]]; then \ |
| 131 | echo "Lint failed on one or more files ^; run 'go fmt' to fix."; \ |
| 132 | exit 1; \ |
| 133 | fi |
| 134 | |
| 135 | lint-sanity: |
| 136 | go vet ./... |
| 137 | |
| 138 | lint: lint-style lint-sanity |
| 139 | |
| 140 | test: |
| 141 | hash go-junit-report > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ |
| 142 | go get -u github.com/jstemmer/go-junit-report; \ |
| 143 | fi |
| 144 | hash gocover-cobertura > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ |
| 145 | go get -u github.com/t-yuki/gocover-cobertura; \ |
| 146 | fi |
| 147 | |
| 148 | mkdir -p ./tests/results |
| 149 | go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee /dev/tty | go-junit-report > ./tests/results/go-test-results.xml; \ |
| 150 | RETURN=$$?; \ |
| 151 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml && exit $$RETURN |
| 152 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 153 | # end file |