blob: 79f4baaa811bad1f22264609386b235c0597f501 [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
Zack Williams27f59a42019-05-10 09:12:07 -070019# Variables
20VERSION ?= $(shell cat ./VERSION)
21
khenaidoocfee5f42018-07-19 22:47:38 -040022ifeq ($(TAG),)
23TAG := latest
24endif
25
26ifeq ($(TARGET_TAG),)
27TARGET_TAG := latest
28endif
29
30# If no DOCKER_HOST_IP is specified grab a v4 IP address associated with
31# the default gateway
32ifeq ($(DOCKER_HOST_IP),)
33DOCKER_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')
34endif
35
36
37ifneq ($(http_proxy)$(https_proxy),)
38# Include proxies from the environment
39DOCKER_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)
48endif
49
50DOCKER_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
58DOCKER_IMAGE_LIST = \
59 rw_core
60
61
Stephane Barbariea75791c2019-01-24 10:58:06 -050062.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 -040063
64# This should to be the first and default target in this Makefile
65help:
66 @echo "Usage: make [<target>]"
67 @echo "where available targets are:"
68 @echo
Kent Hagerman074d0e02019-04-24 17:58:16 -040069 @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 Hagerman0ab4cb22019-04-24 13:13:35 -040080 @echo "lint-dep : Verify the integrity of the `dep` files"
Kent Hagerman074d0e02019-04-24 17:58:16 -040081 @echo "lint : Shorthand for lint-style & lint-sanity"
82 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040083 @echo
84
85
86# Parallel Build
87$(DIRS):
88 @echo " MK $@"
89 $(Q)$(MAKE) -C $@
90
91# Parallel Clean
92DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
93$(DIRS_CLEAN):
94 @echo " CLEAN $(basename $@)"
95 $(Q)$(MAKE) -C $(basename $@) clean
96
khenaidoo9a468962018-09-19 15:33:13 -040097build: containers
khenaidoocfee5f42018-07-19 22:47:38 -040098
Stephane Barbariea75791c2019-01-24 10:58:06 -050099containers: base rw_core ro_core simulated_olt simulated_onu afrouter arouterd
sslobodr2fb98b82019-01-21 09:29:51 -0500100
101base:
William Kurkiandaa6bb22019-03-07 12:26:28 -0500102ifdef LOCAL_PROTOS
103 mkdir -p vendor/github.com/opencord/voltha-protos/go
William Kurkian86e18372019-04-18 15:09:06 -0400104 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
William Kurkiandaa6bb22019-03-07 12:26:28 -0500105endif
sslobodr2fb98b82019-01-21 09:29:51 -0500106 docker build $(DOCKER_BUILD_ARGS) -t base:latest -f docker/Dockerfile.base .
khenaidoocfee5f42018-07-19 22:47:38 -0400107
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400108afrouter: base
sslobodr38afd0d2019-01-21 12:31:46 -0500109 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouter:${TAG} -f docker/Dockerfile.arouter .
sslobodra3ea7d42019-01-16 15:03:16 -0500110
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400111afrouterTest: base
sslobodrd6e07e72019-01-31 16:07:20 -0500112 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afroutertest:${TAG} -f docker/Dockerfile.arouterTest .
113
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400114arouterd: base
sslobodr38afd0d2019-01-21 12:31:46 -0500115 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouterd:${TAG} -f docker/Dockerfile.arouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500116
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400117rw_core: base
khenaidoocfee5f42018-07-19 22:47:38 -0400118 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-rw-core:${TAG} -f docker/Dockerfile.rw_core .
khenaidoocfee5f42018-07-19 22:47:38 -0400119
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400120ro_core: base
Stephane Barbariea75791c2019-01-24 10:58:06 -0500121 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ro-core:${TAG} -f docker/Dockerfile.ro_core .
122
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400123simulated_olt: base
khenaidood2b6df92018-12-13 16:37:20 -0500124 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-olt:${TAG} -f docker/Dockerfile.simulated_olt .
khenaidood2b6df92018-12-13 16:37:20 -0500125
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400126simulated_onu: base
khenaidood2b6df92018-12-13 16:37:20 -0500127 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-onu:${TAG} -f docker/Dockerfile.simulated_onu .
khenaidood2b6df92018-12-13 16:37:20 -0500128
Kent Hagerman074d0e02019-04-24 17:58:16 -0400129lint-style:
Zack Williams7cf78002019-04-30 21:45:35 -0700130ifeq (,$(shell which gofmt))
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400131 go get -u github.com/golang/go/src/cmd/gofmt
Zack Williams7cf78002019-04-30 21:45:35 -0700132endif
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400133 @echo "Running style check..."
134 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700135 if [ ! -z "$$gofmt_out" ]; then \
136 echo "$$gofmt_out" ;\
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400137 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700138 exit 1 ;\
Kent Hagerman074d0e02019-04-24 17:58:16 -0400139 fi
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400140 @echo "Style check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400141
142lint-sanity:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400143 @echo "Running sanity check..."
144 @go vet ./...
145 @echo "Sanity check OK"
Kent Hagerman074d0e02019-04-24 17:58:16 -0400146
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400147lint-dep:
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400148 @echo "Running dependency check..."
149 @dep check
150 @echo "Dependency check OK"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400151
152lint: lint-style lint-sanity lint-dep
Kent Hagerman074d0e02019-04-24 17:58:16 -0400153
Zack Williams7cf78002019-04-30 21:45:35 -0700154GO_JUNIT_REPORT:=$(shell which go-junit-report)
155GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
Kent Hagerman074d0e02019-04-24 17:58:16 -0400156test:
Zack Williams7cf78002019-04-30 21:45:35 -0700157ifeq (,$(GO_JUNIT_REPORT))
158 go get -u github.com/jstemmer/go-junit-report
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400159 @GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
Zack Williams7cf78002019-04-30 21:45:35 -0700160endif
161
162ifeq (,$(GOCOVER_COBERTURA))
163 go get -u github.com/t-yuki/gocover-cobertura
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400164 @GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
Zack Williams7cf78002019-04-30 21:45:35 -0700165endif
Kent Hagerman074d0e02019-04-24 17:58:16 -0400166
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400167 @mkdir -p ./tests/results
Zack Williams7cf78002019-04-30 21:45:35 -0700168
Kent Hagermanca4c51e2019-05-02 12:28:55 -0400169 @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
Zack Williams7cf78002019-04-30 21:45:35 -0700170 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 Hagerman074d0e02019-04-24 17:58:16 -0400174
khenaidoocfee5f42018-07-19 22:47:38 -0400175# end file