blob: 3b0e919f6e9579a77438cdcff49d9c9a640ee950 [file] [log] [blame]
Dinesh Belwalkar6c0bc752020-04-24 23:47:53 +00001# Copyright 2019-present Open Networking Foundation
2# Copyright 2019-present Edgecore Networks Corporation
Dinesh Belwalkar01217962019-05-23 21:51:16 +00003#
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# Configure shell
17SHELL = bash -eu -o pipefail
18
Scott Baker5d03e172020-04-10 14:56:20 -070019ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
20
Dinesh Belwalkar01217962019-05-23 21:51:16 +000021# Variables
22VERSION ?= $(shell cat ./VERSION)
23CONTAINER_NAME ?= $(notdir $(abspath .))
24
25## Docker related
26DOCKER_REGISTRY ?=
27DOCKER_REPOSITORY ?=
28DOCKER_BUILD_ARGS ?=
29DOCKER_TAG ?= ${VERSION}
30DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
31
32## Docker labels. Only set ref and commit date if committed
33DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
34DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
35DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
36DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
37
Scott Baker5d03e172020-04-10 14:56:20 -070038ROBOT_MOCK_OLT_FILE ?= $(ROOT_DIR)/demo_test/functional_test/robot-mock-olt.yaml
Scott Baker105df152020-04-13 15:55:14 -070039ROBOT_MOCK_OLT_SINGLE_FILE ?= $(ROOT_DIR)/demo_test/functional_test/robot-mock-olt-single.yaml
Scott Baker5d03e172020-04-10 14:56:20 -070040ROBOT_DEBUG_LOG_OPT ?=
41ROBOT_MISC_ARGS ?=
42
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000043help:
44 @echo "Usage: make [<target>]"
45 @echo "where available targets are:"
46 @echo
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000047 @echo "proto/importer.pb.go : Build importer.pb.go for go build ./.."
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000048 @echo "build : Build the docker images."
49 @echo " - If this is the first time you are building, choose 'make build' option."
50 @echo "clean : Remove files created by the build and tests"
51 @echo "docker-push : Push the docker images to an external repository"
52 @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
53 @echo "lint-style : Verify code is properly gofmt-ed"
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000054 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
55 @echo "lint-mod : Verify the integrity of the 'mod' files"
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000056 @echo "lint : Shorthand for lint-style & lint-sanity"
57 @echo "test : Generate reports for all go tests"
58 @echo
59
Dinesh Belwalkar01217962019-05-23 21:51:16 +000060all: test
Scott Baker5d03e172020-04-10 14:56:20 -070061
Scott Baker105df152020-04-13 15:55:14 -070062# target to invoke mock-olt robot tests, two OLTs
Scott Baker5d03e172020-04-10 14:56:20 -070063functional-mock-test: ROBOT_MISC_ARGS += $(ROBOT_DEBUG_LOG_OPT)
64functional-mock-test: ROBOT_CONFIG_FILE := $(ROBOT_MOCK_OLT_FILE)
65functional-mock-test: ROBOT_FILE := $(ROOT_DIR)/demo_test/functional_test/importer.robot
66functional-mock-test: importer-functional-test
67
Scott Baker105df152020-04-13 15:55:14 -070068# target to invoke mock-olt robot tests, single OLT
69functional-mock-test-single: ROBOT_MISC_ARGS += $(ROBOT_DEBUG_LOG_OPT)
70functional-mock-test-single: ROBOT_CONFIG_FILE := $(ROBOT_MOCK_OLT_FILE)
71functional-mock-test-single: ROBOT_FILE := $(ROOT_DIR)/demo_test/functional_test/importer.robot
72functional-mock-test-single: importer-functional-test
73
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000074proto/importer.pb.go: proto/importer.proto
75 mkdir -p proto
76 protoc --proto_path=proto \
77 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
78 --go_out=plugins=grpc:proto/ \
79 proto/importer.proto
80
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000081build: docker-build
82
Scott Bakerbdb962b2020-04-03 10:53:36 -070083docker-build: docker-build-importer
84 make -C demo_test docker-build
85 make -C mock-redfish-server docker-build
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000086
Scott Bakerbdb962b2020-04-03 10:53:36 -070087docker-push: docker-push-importer
88 make -C demo_test docker-push
89 make -C mock-redfish-server docker-push
90
91docker-build-importer:
Dinesh Belwalkar01217962019-05-23 21:51:16 +000092 docker build $(DOCKER_BUILD_ARGS) \
93 -t ${DOCKER_IMAGENAME} \
94 --build-arg org_label_schema_version="${VERSION}" \
95 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
96 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
97 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
98 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
99 -f Dockerfile .
Scott Bakerbdb962b2020-04-03 10:53:36 -0700100
101docker-push-importer:
Dinesh Belwalkar01217962019-05-23 21:51:16 +0000102 docker push ${DOCKER_IMAGENAME}
103
Scott Bakerbdb962b2020-04-03 10:53:36 -0700104
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000105PATH:=$(GOPATH)/bin:$(PATH)
106HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
107
108lint-dockerfile:
109ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint))
110 mkdir -p $(GOPATH)/bin
111 curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m)
112 chmod 755 $(GOPATH)/bin/hadolint
113endif
114 @echo "Running Dockerfile lint check ..."
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +0000115 @hadolint $$(find . -type f -not -path "./vendor/*" -name "Dockerfile")
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000116 @echo "Dockerfile lint check OK"
117
118lint-style:
119ifeq (,$(shell which gofmt))
120 go get -u github.com/golang/go/src/cmd/gofmt
121endif
122 @echo "Running style check..."
123 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
124 if [ ! -z "$$gofmt_out" ]; then \
125 echo "$$gofmt_out" ;\
126 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
127 exit 1 ;\
128 fi
129 @echo "Style check OK"
130
Dinesh Belwalkara6ba07d2020-01-10 23:22:34 +0000131lint-sanity:proto/importer.pb.go
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +0000132 @echo "Running sanity check..."
133 @go vet -mod=vendor ./...
134 @echo "Sanity check OK"
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000135
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +0000136lint-mod:
137 @echo "Running dependency check..."
138 @go mod verify
139 @echo "Dependency check OK"
140lint: lint-style lint-dockerfile lint-sanity lint-mod
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000141
142# Rules to automatically install golangci-lint
143GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
144ifeq (,$(GOLANGCI_LINT_TOOL))
145GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
146golangci_lint_tool_install:
147 # Same version as installed by Jenkins ci-management
148 # Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
149 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
150else
151golangci_lint_tool_install:
152endif
153
154sca: golangci_lint_tool_install
155 rm -rf ./sca-report
156 @mkdir -p ./sca-report
157 $(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
158
Dinesh Belwalkar01217962019-05-23 21:51:16 +0000159test: docker-build
160
161clean:
162 @echo "No cleanup available"
Scott Baker5d03e172020-04-10 14:56:20 -0700163
164# Check out a copy of voltha-system-tests. We will reuse its robot configuration
165# and its robot libraries
166voltha-system-tests:
167 git clone https://github.com/opencord/voltha-system-tests.git
168
169# virtualenv for the robot tools
170# VOL-2724 Invoke pip via python3 to avoid pathname too long on QA jobs
171vst_venv: voltha-system-tests
172 virtualenv -p python3 $@ && \
173 VIRTUAL_ENV_DISABLE_PROMPT=true source ./$@/bin/activate && \
174 python -m pip install -r voltha-system-tests/requirements.txt
175
176importer-functional-test: vst_venv
177 VIRTUAL_ENV_DISABLE_PROMPT=true source ./$</bin/activate ; set -u ;\
178 cd demo_test/functional_test ;\
179 robot -V $(ROBOT_CONFIG_FILE) $(ROBOT_MISC_ARGS) $(ROBOT_FILE)