blob: ae04c2f313ada492474837e86ddef7eac35c76c6 [file] [log] [blame]
khenaidoocfee5f42018-07-19 22:47:38 -04001#
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 Williams7cf78002019-04-30 21:45:35 -070017SHELL=/bin/bash -e -o pipefail
Kent Hagerman074d0e02019-04-24 17:58:16 -040018
khenaidoocfee5f42018-07-19 22:47:38 -040019ifeq ($(TAG),)
20TAG := latest
21endif
22
23ifeq ($(TARGET_TAG),)
24TARGET_TAG := latest
25endif
26
27# If no DOCKER_HOST_IP is specified grab a v4 IP address associated with
28# the default gateway
29ifeq ($(DOCKER_HOST_IP),)
30DOCKER_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')
31endif
32
33
34ifneq ($(http_proxy)$(https_proxy),)
35# Include proxies from the environment
36DOCKER_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)
45endif
46
47DOCKER_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
55DOCKER_IMAGE_LIST = \
56 rw_core
57
58
Stephane Barbariea75791c2019-01-24 10:58:06 -050059.PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) rw_core ro_core protos kafka db tests python simulators k8s afrouter arouterd base
khenaidoocfee5f42018-07-19 22:47:38 -040060
61# This should to be the first and default target in this Makefile
62help:
63 @echo "Usage: make [<target>]"
64 @echo "where available targets are:"
65 @echo
Kent Hagerman074d0e02019-04-24 17:58:16 -040066 @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 Hagerman0ab4cb22019-04-24 13:13:35 -040077 @echo "lint-dep : Verify the integrity of the `dep` files"
Kent Hagerman074d0e02019-04-24 17:58:16 -040078 @echo "lint : Shorthand for lint-style & lint-sanity"
79 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040080 @echo
81
82
83# Parallel Build
84$(DIRS):
85 @echo " MK $@"
86 $(Q)$(MAKE) -C $@
87
88# Parallel Clean
89DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
90$(DIRS_CLEAN):
91 @echo " CLEAN $(basename $@)"
92 $(Q)$(MAKE) -C $(basename $@) clean
93
khenaidoo9a468962018-09-19 15:33:13 -040094build: containers
khenaidoocfee5f42018-07-19 22:47:38 -040095
Stephane Barbariea75791c2019-01-24 10:58:06 -050096containers: base rw_core ro_core simulated_olt simulated_onu afrouter arouterd
sslobodr2fb98b82019-01-21 09:29:51 -050097
98base:
William Kurkiandaa6bb22019-03-07 12:26:28 -050099ifdef LOCAL_PROTOS
100 mkdir -p vendor/github.com/opencord/voltha-protos/go
William Kurkian86e18372019-04-18 15:09:06 -0400101 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
William Kurkiandaa6bb22019-03-07 12:26:28 -0500102endif
sslobodr2fb98b82019-01-21 09:29:51 -0500103 docker build $(DOCKER_BUILD_ARGS) -t base:latest -f docker/Dockerfile.base .
khenaidoocfee5f42018-07-19 22:47:38 -0400104
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400105afrouter: base
sslobodr38afd0d2019-01-21 12:31:46 -0500106 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouter:${TAG} -f docker/Dockerfile.arouter .
sslobodra3ea7d42019-01-16 15:03:16 -0500107
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400108afrouterTest: base
sslobodrd6e07e72019-01-31 16:07:20 -0500109 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afroutertest:${TAG} -f docker/Dockerfile.arouterTest .
110
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400111arouterd: base
sslobodr38afd0d2019-01-21 12:31:46 -0500112 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouterd:${TAG} -f docker/Dockerfile.arouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500113
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400114rw_core: base
khenaidoocfee5f42018-07-19 22:47:38 -0400115 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-rw-core:${TAG} -f docker/Dockerfile.rw_core .
khenaidoocfee5f42018-07-19 22:47:38 -0400116
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400117ro_core: base
Stephane Barbariea75791c2019-01-24 10:58:06 -0500118 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ro-core:${TAG} -f docker/Dockerfile.ro_core .
119
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400120simulated_olt: base
khenaidood2b6df92018-12-13 16:37:20 -0500121 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-olt:${TAG} -f docker/Dockerfile.simulated_olt .
khenaidood2b6df92018-12-13 16:37:20 -0500122
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400123simulated_onu: base
khenaidood2b6df92018-12-13 16:37:20 -0500124 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-onu:${TAG} -f docker/Dockerfile.simulated_onu .
khenaidood2b6df92018-12-13 16:37:20 -0500125
Kent Hagerman074d0e02019-04-24 17:58:16 -0400126lint-style:
Zack Williams7cf78002019-04-30 21:45:35 -0700127ifeq (,$(shell which gofmt))
128 go get -u github.com/golang/go/src/cmd/gofmt;
129endif
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 Hagerman074d0e02019-04-24 17:58:16 -0400135 fi
136
137lint-sanity:
138 go vet ./...
139
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400140lint-dep:
141 dep check
142
143lint: lint-style lint-sanity lint-dep
Kent Hagerman074d0e02019-04-24 17:58:16 -0400144
Zack Williams7cf78002019-04-30 21:45:35 -0700145GO_JUNIT_REPORT:=$(shell which go-junit-report)
146GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
Kent Hagerman074d0e02019-04-24 17:58:16 -0400147test:
Zack Williams7cf78002019-04-30 21:45:35 -0700148ifeq (,$(GO_JUNIT_REPORT))
149 go get -u github.com/jstemmer/go-junit-report
150 GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
151endif
152
153ifeq (,$(GOCOVER_COBERTURA))
154 go get -u github.com/t-yuki/gocover-cobertura
155 GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
156endif
Kent Hagerman074d0e02019-04-24 17:58:16 -0400157
158 mkdir -p ./tests/results
Zack Williams7cf78002019-04-30 21:45:35 -0700159
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 Hagerman074d0e02019-04-24 17:58:16 -0400165
khenaidoocfee5f42018-07-19 22:47:38 -0400166# end file