blob: 64b2e736b5257fbb32c3cb1163f1c196c20617f4 [file] [log] [blame]
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +00001# Copyrigh/ 2019-present Open Networking Foundation
Dinesh Belwalkar01217962019-05-23 21:51:16 +00002#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Configure shell
16SHELL = bash -eu -o pipefail
17
Scott Baker5d03e172020-04-10 14:56:20 -070018ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
19
Dinesh Belwalkar01217962019-05-23 21:51:16 +000020# Variables
21VERSION ?= $(shell cat ./VERSION)
22CONTAINER_NAME ?= $(notdir $(abspath .))
23
24## Docker related
25DOCKER_REGISTRY ?=
26DOCKER_REPOSITORY ?=
27DOCKER_BUILD_ARGS ?=
28DOCKER_TAG ?= ${VERSION}
29DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
30
31## Docker labels. Only set ref and commit date if committed
32DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
33DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
34DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
35DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
36
Scott Baker5d03e172020-04-10 14:56:20 -070037ROBOT_MOCK_OLT_FILE ?= $(ROOT_DIR)/demo_test/functional_test/robot-mock-olt.yaml
38ROBOT_DEBUG_LOG_OPT ?=
39ROBOT_MISC_ARGS ?=
40
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000041help:
42 @echo "Usage: make [<target>]"
43 @echo "where available targets are:"
44 @echo
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000045 @echo "proto/importer.pb.go : Build importer.pb.go for go build ./.."
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000046 @echo "build : Build the docker images."
47 @echo " - If this is the first time you are building, choose 'make build' option."
48 @echo "clean : Remove files created by the build and tests"
49 @echo "docker-push : Push the docker images to an external repository"
50 @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
51 @echo "lint-style : Verify code is properly gofmt-ed"
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000052 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
53 @echo "lint-mod : Verify the integrity of the 'mod' files"
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000054 @echo "lint : Shorthand for lint-style & lint-sanity"
55 @echo "test : Generate reports for all go tests"
56 @echo
57
Dinesh Belwalkar01217962019-05-23 21:51:16 +000058all: test
Scott Baker5d03e172020-04-10 14:56:20 -070059
60# target to invoke mock-olt robot tests
61functional-mock-test: ROBOT_MISC_ARGS += $(ROBOT_DEBUG_LOG_OPT)
62functional-mock-test: ROBOT_CONFIG_FILE := $(ROBOT_MOCK_OLT_FILE)
63functional-mock-test: ROBOT_FILE := $(ROOT_DIR)/demo_test/functional_test/importer.robot
64functional-mock-test: importer-functional-test
65
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000066proto/importer.pb.go: proto/importer.proto
67 mkdir -p proto
68 protoc --proto_path=proto \
69 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
70 --go_out=plugins=grpc:proto/ \
71 proto/importer.proto
72
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000073build: docker-build
74
Scott Bakerbdb962b2020-04-03 10:53:36 -070075docker-build: docker-build-importer
76 make -C demo_test docker-build
77 make -C mock-redfish-server docker-build
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000078
Scott Bakerbdb962b2020-04-03 10:53:36 -070079docker-push: docker-push-importer
80 make -C demo_test docker-push
81 make -C mock-redfish-server docker-push
82
83docker-build-importer:
Dinesh Belwalkar01217962019-05-23 21:51:16 +000084 docker build $(DOCKER_BUILD_ARGS) \
85 -t ${DOCKER_IMAGENAME} \
86 --build-arg org_label_schema_version="${VERSION}" \
87 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
88 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
89 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
90 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
91 -f Dockerfile .
Scott Bakerbdb962b2020-04-03 10:53:36 -070092
93docker-push-importer:
Dinesh Belwalkar01217962019-05-23 21:51:16 +000094 docker push ${DOCKER_IMAGENAME}
95
Scott Bakerbdb962b2020-04-03 10:53:36 -070096
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000097PATH:=$(GOPATH)/bin:$(PATH)
98HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
99
100lint-dockerfile:
101ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint))
102 mkdir -p $(GOPATH)/bin
103 curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m)
104 chmod 755 $(GOPATH)/bin/hadolint
105endif
106 @echo "Running Dockerfile lint check ..."
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +0000107 @hadolint $$(find . -type f -not -path "./vendor/*" -name "Dockerfile")
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000108 @echo "Dockerfile lint check OK"
109
110lint-style:
111ifeq (,$(shell which gofmt))
112 go get -u github.com/golang/go/src/cmd/gofmt
113endif
114 @echo "Running style check..."
115 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
116 if [ ! -z "$$gofmt_out" ]; then \
117 echo "$$gofmt_out" ;\
118 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
119 exit 1 ;\
120 fi
121 @echo "Style check OK"
122
Dinesh Belwalkara6ba07d2020-01-10 23:22:34 +0000123lint-sanity:proto/importer.pb.go
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +0000124 @echo "Running sanity check..."
125 @go vet -mod=vendor ./...
126 @echo "Sanity check OK"
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000127
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +0000128lint-mod:
129 @echo "Running dependency check..."
130 @go mod verify
131 @echo "Dependency check OK"
132lint: lint-style lint-dockerfile lint-sanity lint-mod
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000133
134# Rules to automatically install golangci-lint
135GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
136ifeq (,$(GOLANGCI_LINT_TOOL))
137GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
138golangci_lint_tool_install:
139 # Same version as installed by Jenkins ci-management
140 # Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
141 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
142else
143golangci_lint_tool_install:
144endif
145
146sca: golangci_lint_tool_install
147 rm -rf ./sca-report
148 @mkdir -p ./sca-report
149 $(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
150
Dinesh Belwalkar01217962019-05-23 21:51:16 +0000151test: docker-build
152
153clean:
154 @echo "No cleanup available"
Scott Baker5d03e172020-04-10 14:56:20 -0700155
156# Check out a copy of voltha-system-tests. We will reuse its robot configuration
157# and its robot libraries
158voltha-system-tests:
159 git clone https://github.com/opencord/voltha-system-tests.git
160
161# virtualenv for the robot tools
162# VOL-2724 Invoke pip via python3 to avoid pathname too long on QA jobs
163vst_venv: voltha-system-tests
164 virtualenv -p python3 $@ && \
165 VIRTUAL_ENV_DISABLE_PROMPT=true source ./$@/bin/activate && \
166 python -m pip install -r voltha-system-tests/requirements.txt
167
168importer-functional-test: vst_venv
169 VIRTUAL_ENV_DISABLE_PROMPT=true source ./$</bin/activate ; set -u ;\
170 cd demo_test/functional_test ;\
171 robot -V $(ROBOT_CONFIG_FILE) $(ROBOT_MISC_ARGS) $(ROBOT_FILE)