blob: a89e3e01bd505c3144b7669a771eb30918c372c8 [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
Kent Hagerman074d0e02019-04-24 17:58:16 -040017SHELL=/bin/bash -o pipefail
18
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"
77 @echo "lint : Shorthand for lint-style & lint-sanity"
78 @echo "test : Generate reports for all go tests"
khenaidoocfee5f42018-07-19 22:47:38 -040079 @echo
80
81
82# Parallel Build
83$(DIRS):
84 @echo " MK $@"
85 $(Q)$(MAKE) -C $@
86
87# Parallel Clean
88DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
89$(DIRS_CLEAN):
90 @echo " CLEAN $(basename $@)"
91 $(Q)$(MAKE) -C $(basename $@) clean
92
khenaidoo9a468962018-09-19 15:33:13 -040093build: containers
khenaidoocfee5f42018-07-19 22:47:38 -040094
Stephane Barbariea75791c2019-01-24 10:58:06 -050095containers: base rw_core ro_core simulated_olt simulated_onu afrouter arouterd
sslobodr2fb98b82019-01-21 09:29:51 -050096
97base:
William Kurkiandaa6bb22019-03-07 12:26:28 -050098ifdef LOCAL_PROTOS
99 mkdir -p vendor/github.com/opencord/voltha-protos/go
William Kurkian86e18372019-04-18 15:09:06 -0400100 cp -r ${GOPATH}/src/github.com/opencord/voltha-protos/go/* vendor/github.com/opencord/voltha-protos/go
William Kurkiandaa6bb22019-03-07 12:26:28 -0500101endif
sslobodr2fb98b82019-01-21 09:29:51 -0500102 docker build $(DOCKER_BUILD_ARGS) -t base:latest -f docker/Dockerfile.base .
khenaidoocfee5f42018-07-19 22:47:38 -0400103
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400104afrouter: base
sslobodr38afd0d2019-01-21 12:31:46 -0500105 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouter:${TAG} -f docker/Dockerfile.arouter .
sslobodra3ea7d42019-01-16 15:03:16 -0500106
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400107afrouterTest: base
sslobodrd6e07e72019-01-31 16:07:20 -0500108 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afroutertest:${TAG} -f docker/Dockerfile.arouterTest .
109
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400110arouterd: base
sslobodr38afd0d2019-01-21 12:31:46 -0500111 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouterd:${TAG} -f docker/Dockerfile.arouterd .
sslobodra3ea7d42019-01-16 15:03:16 -0500112
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400113rw_core: base
khenaidoocfee5f42018-07-19 22:47:38 -0400114 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-rw-core:${TAG} -f docker/Dockerfile.rw_core .
khenaidoocfee5f42018-07-19 22:47:38 -0400115
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400116ro_core: base
Stephane Barbariea75791c2019-01-24 10:58:06 -0500117 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-ro-core:${TAG} -f docker/Dockerfile.ro_core .
118
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400119simulated_olt: base
khenaidood2b6df92018-12-13 16:37:20 -0500120 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-olt:${TAG} -f docker/Dockerfile.simulated_olt .
khenaidood2b6df92018-12-13 16:37:20 -0500121
Matt Jeanneret85ab5082019-04-01 11:29:20 -0400122simulated_onu: base
khenaidood2b6df92018-12-13 16:37:20 -0500123 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-onu:${TAG} -f docker/Dockerfile.simulated_onu .
khenaidood2b6df92018-12-13 16:37:20 -0500124
Kent Hagerman074d0e02019-04-24 17:58:16 -0400125lint-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
135lint-sanity:
136 go vet ./...
137
138lint: lint-style lint-sanity
139
140test:
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
khenaidoocfee5f42018-07-19 22:47:38 -0400153# end file