Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 1 | # Copyrigh/ 2019-present Open Networking Foundation |
Dinesh Belwalkar | 0121796 | 2019-05-23 21:51:16 +0000 | [diff] [blame] | 2 | # |
| 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 |
| 16 | SHELL = bash -eu -o pipefail |
| 17 | |
| 18 | # Variables |
| 19 | VERSION ?= $(shell cat ./VERSION) |
| 20 | CONTAINER_NAME ?= $(notdir $(abspath .)) |
| 21 | |
| 22 | ## Docker related |
| 23 | DOCKER_REGISTRY ?= |
| 24 | DOCKER_REPOSITORY ?= |
| 25 | DOCKER_BUILD_ARGS ?= |
| 26 | DOCKER_TAG ?= ${VERSION} |
| 27 | DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG} |
| 28 | |
| 29 | ## Docker labels. Only set ref and commit date if committed |
| 30 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 31 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 32 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 33 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 34 | |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 35 | help: |
| 36 | @echo "Usage: make [<target>]" |
| 37 | @echo "where available targets are:" |
| 38 | @echo |
Dinesh Belwalkar | e63f7f9 | 2019-11-22 23:11:16 +0000 | [diff] [blame] | 39 | @echo "proto/importer.pb.go : Build importer.pb.go for go build ./.." |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 40 | @echo "build : Build the docker images." |
| 41 | @echo " - If this is the first time you are building, choose 'make build' option." |
| 42 | @echo "clean : Remove files created by the build and tests" |
| 43 | @echo "docker-push : Push the docker images to an external repository" |
| 44 | @echo "lint-dockerfile : Perform static analysis on Dockerfiles" |
| 45 | @echo "lint-style : Verify code is properly gofmt-ed" |
Dinesh Belwalkar | e63f7f9 | 2019-11-22 23:11:16 +0000 | [diff] [blame] | 46 | @echo "lint-sanity : Verify that 'go vet' doesn't report any issues" |
| 47 | @echo "lint-mod : Verify the integrity of the 'mod' files" |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 48 | @echo "lint : Shorthand for lint-style & lint-sanity" |
| 49 | @echo "test : Generate reports for all go tests" |
| 50 | @echo |
| 51 | |
Dinesh Belwalkar | 0121796 | 2019-05-23 21:51:16 +0000 | [diff] [blame] | 52 | all: test |
Dinesh Belwalkar | e63f7f9 | 2019-11-22 23:11:16 +0000 | [diff] [blame] | 53 | proto/importer.pb.go: proto/importer.proto |
| 54 | mkdir -p proto |
| 55 | protoc --proto_path=proto \ |
| 56 | -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ |
| 57 | --go_out=plugins=grpc:proto/ \ |
| 58 | proto/importer.proto |
| 59 | |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 60 | build: docker-build |
| 61 | |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame^] | 62 | docker-build: docker-build-importer |
| 63 | make -C demo_test docker-build |
| 64 | make -C mock-redfish-server docker-build |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 65 | |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame^] | 66 | docker-push: docker-push-importer |
| 67 | make -C demo_test docker-push |
| 68 | make -C mock-redfish-server docker-push |
| 69 | |
| 70 | docker-build-importer: |
Dinesh Belwalkar | 0121796 | 2019-05-23 21:51:16 +0000 | [diff] [blame] | 71 | docker build $(DOCKER_BUILD_ARGS) \ |
| 72 | -t ${DOCKER_IMAGENAME} \ |
| 73 | --build-arg org_label_schema_version="${VERSION}" \ |
| 74 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 75 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 76 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 77 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 78 | -f Dockerfile . |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame^] | 79 | |
| 80 | docker-push-importer: |
Dinesh Belwalkar | 0121796 | 2019-05-23 21:51:16 +0000 | [diff] [blame] | 81 | docker push ${DOCKER_IMAGENAME} |
| 82 | |
Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame^] | 83 | |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 84 | PATH:=$(GOPATH)/bin:$(PATH) |
| 85 | HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint) |
| 86 | |
| 87 | lint-dockerfile: |
| 88 | ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint)) |
| 89 | mkdir -p $(GOPATH)/bin |
| 90 | curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m) |
| 91 | chmod 755 $(GOPATH)/bin/hadolint |
| 92 | endif |
| 93 | @echo "Running Dockerfile lint check ..." |
Dinesh Belwalkar | 72ecafb | 2019-12-12 00:08:56 +0000 | [diff] [blame] | 94 | @hadolint $$(find . -type f -not -path "./vendor/*" -name "Dockerfile") |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 95 | @echo "Dockerfile lint check OK" |
| 96 | |
| 97 | lint-style: |
| 98 | ifeq (,$(shell which gofmt)) |
| 99 | go get -u github.com/golang/go/src/cmd/gofmt |
| 100 | endif |
| 101 | @echo "Running style check..." |
| 102 | @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 103 | if [ ! -z "$$gofmt_out" ]; then \ |
| 104 | echo "$$gofmt_out" ;\ |
| 105 | echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\ |
| 106 | exit 1 ;\ |
| 107 | fi |
| 108 | @echo "Style check OK" |
| 109 | |
Dinesh Belwalkar | a6ba07d | 2020-01-10 23:22:34 +0000 | [diff] [blame] | 110 | lint-sanity:proto/importer.pb.go |
Dinesh Belwalkar | e63f7f9 | 2019-11-22 23:11:16 +0000 | [diff] [blame] | 111 | @echo "Running sanity check..." |
| 112 | @go vet -mod=vendor ./... |
| 113 | @echo "Sanity check OK" |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 114 | |
Dinesh Belwalkar | e63f7f9 | 2019-11-22 23:11:16 +0000 | [diff] [blame] | 115 | lint-mod: |
| 116 | @echo "Running dependency check..." |
| 117 | @go mod verify |
| 118 | @echo "Dependency check OK" |
| 119 | lint: lint-style lint-dockerfile lint-sanity lint-mod |
Dinesh Belwalkar | 0bc4ace | 2019-11-14 21:41:50 +0000 | [diff] [blame] | 120 | |
| 121 | # Rules to automatically install golangci-lint |
| 122 | GOLANGCI_LINT_TOOL?=$(shell which golangci-lint) |
| 123 | ifeq (,$(GOLANGCI_LINT_TOOL)) |
| 124 | GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint |
| 125 | golangci_lint_tool_install: |
| 126 | # Same version as installed by Jenkins ci-management |
| 127 | # Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint |
| 128 | curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0 |
| 129 | else |
| 130 | golangci_lint_tool_install: |
| 131 | endif |
| 132 | |
| 133 | sca: golangci_lint_tool_install |
| 134 | rm -rf ./sca-report |
| 135 | @mkdir -p ./sca-report |
| 136 | $(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml |
| 137 | |
Dinesh Belwalkar | 0121796 | 2019-05-23 21:51:16 +0000 | [diff] [blame] | 138 | test: docker-build |
| 139 | |
| 140 | clean: |
| 141 | @echo "No cleanup available" |