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