blob: d9c5e70dababa73cf1e9d0f3149ee917ccecf85a [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
18# Variables
19VERSION ?= $(shell cat ./VERSION)
20CONTAINER_NAME ?= $(notdir $(abspath .))
21
22## Docker related
23DOCKER_REGISTRY ?=
24DOCKER_REPOSITORY ?=
25DOCKER_BUILD_ARGS ?=
26DOCKER_TAG ?= ${VERSION}
27DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
28
29## Docker labels. Only set ref and commit date if committed
30DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
31DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
32DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
33DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
34
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000035help:
36 @echo "Usage: make [<target>]"
37 @echo "where available targets are:"
38 @echo
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000039 @echo "proto/importer.pb.go : Build importer.pb.go for go build ./.."
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000040 @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 Belwalkare63f7f92019-11-22 23:11:16 +000046 @echo "lint-sanity : Verify that 'go vet' doesn't report any issues"
47 @echo "lint-mod : Verify the integrity of the 'mod' files"
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000048 @echo "lint : Shorthand for lint-style & lint-sanity"
49 @echo "test : Generate reports for all go tests"
50 @echo
51
Dinesh Belwalkar01217962019-05-23 21:51:16 +000052all: test
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +000053proto/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 Belwalkar0bc4ace2019-11-14 21:41:50 +000060build: docker-build
61
Scott Bakerbdb962b2020-04-03 10:53:36 -070062docker-build: docker-build-importer
63 make -C demo_test docker-build
64 make -C mock-redfish-server docker-build
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000065
Scott Bakerbdb962b2020-04-03 10:53:36 -070066docker-push: docker-push-importer
67 make -C demo_test docker-push
68 make -C mock-redfish-server docker-push
69
70docker-build-importer:
Dinesh Belwalkar01217962019-05-23 21:51:16 +000071 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 Bakerbdb962b2020-04-03 10:53:36 -070079
80docker-push-importer:
Dinesh Belwalkar01217962019-05-23 21:51:16 +000081 docker push ${DOCKER_IMAGENAME}
82
Scott Bakerbdb962b2020-04-03 10:53:36 -070083
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000084PATH:=$(GOPATH)/bin:$(PATH)
85HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
86
87lint-dockerfile:
88ifeq (,$(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
92endif
93 @echo "Running Dockerfile lint check ..."
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +000094 @hadolint $$(find . -type f -not -path "./vendor/*" -name "Dockerfile")
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +000095 @echo "Dockerfile lint check OK"
96
97lint-style:
98ifeq (,$(shell which gofmt))
99 go get -u github.com/golang/go/src/cmd/gofmt
100endif
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 Belwalkara6ba07d2020-01-10 23:22:34 +0000110lint-sanity:proto/importer.pb.go
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +0000111 @echo "Running sanity check..."
112 @go vet -mod=vendor ./...
113 @echo "Sanity check OK"
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000114
Dinesh Belwalkare63f7f92019-11-22 23:11:16 +0000115lint-mod:
116 @echo "Running dependency check..."
117 @go mod verify
118 @echo "Dependency check OK"
119lint: lint-style lint-dockerfile lint-sanity lint-mod
Dinesh Belwalkar0bc4ace2019-11-14 21:41:50 +0000120
121# Rules to automatically install golangci-lint
122GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
123ifeq (,$(GOLANGCI_LINT_TOOL))
124GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
125golangci_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
129else
130golangci_lint_tool_install:
131endif
132
133sca: 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 Belwalkar01217962019-05-23 21:51:16 +0000138test: docker-build
139
140clean:
141 @echo "No cleanup available"