forked from IBM/ibm-vpc-file-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
136 lines (112 loc) · 4.71 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#
# Copyright 2019 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
EXE_DRIVER_NAME=ibm-vpc-file-csi-driver
DRIVER_NAME=vpcFileDriver
IMAGE = ${EXE_DRIVER_NAME}
GOPACKAGES=$(shell go list ./... | grep -v /vendor/ | grep -v /cmd | grep -v /tests)
VERSION := latest
GIT_COMMIT_SHA="$(shell git rev-parse HEAD 2>/dev/null)"
GIT_REMOTE_URL="$(shell git config --get remote.origin.url 2>/dev/null)"
BUILD_DATE="$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")"
ARCH=$(shell docker version -f {{.Client.Arch}})
OSS_FILES := go.mod Dockerfile
# Jenkins vars. Set to `unknown` if the variable is not yet defined
BUILD_NUMBER?=unknown
GO111MODULE_FLAG?=on
export GO111MODULE=$(GO111MODULE_FLAG)
export LINT_VERSION="1.56.2"
COLOR_YELLOW=\033[0;33m
COLOR_RESET=\033[0m
.PHONY: all
all: deps fmt build test buildimage
.PHONY: driver
driver: deps buildimage
.PHONY: deps
deps:
echo "Installing dependencies ..."
#glide install --strip-vendor
go mod download
go get github.com/pierrre/gotestcover
go install github.com/pierrre/gotestcover
@if ! which golangci-lint >/dev/null || [[ "$$(golangci-lint --version)" != *${LINT_VERSION}* ]]; then \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v${LINT_VERSION}; \
fi
.PHONY: fmt
fmt: lint
$(GOPATH)/bin/golangci-lint run --disable-all --enable=gofmt --timeout 600s
@if [ -n "$$($(GOPATH)/bin/golangci-lint run)" ]; then echo 'Please run ${COLOR_YELLOW}make dofmt${COLOR_RESET} on your code.' && exit 1; fi
.PHONY: dofmt
dofmt:
$(GOPATH)/bin/golangci-lint run --disable-all --enable=gofmt --fix --timeout 600s
.PHONY: lint
lint:
$(GOPATH)/bin/golangci-lint run --timeout 600s
.PHONY: build
build:
CGO_ENABLED=0 GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) go build -mod=vendor -a -ldflags '-X main.vendorVersion='"${DRIVER_NAME}-${GIT_COMMIT_SHA}"' -extldflags "-static"' -o ${GOPATH}/bin/${EXE_DRIVER_NAME} ./cmd/
.PHONY: test
test:
$(GOPATH)/bin/gotestcover -v -race -short -coverprofile=cover.out ${GOPACKAGES}
go tool cover -html=cover.out -o=cover.html # Uncomment this line when UT in place.
.PHONY: ut-coverage
ut-coverage: deps fmt test
.PHONY: coverage
coverage:
go tool cover -html=cover.out -o=cover.html
@./scripts/calculateCoverage.sh
.PHONY: buildimage
buildimage: build-systemutil
docker build \
--build-arg git_commit_id=${GIT_COMMIT_SHA} \
--build-arg git_remote_url=${GIT_REMOTE_URL} \
--build-arg build_date=${BUILD_DATE} \
--build-arg jenkins_build_number=${BUILD_NUMBER} \
--build-arg REPO_SOURCE_URL=${REPO_SOURCE_URL} \
--build-arg BUILD_URL=${BUILD_URL} \
-t $(IMAGE):$(VERSION)-$(ARCH) -f Dockerfile .
ifeq ($(ARCH), amd64)
docker tag $(IMAGE):$(VERSION)-$(ARCH) $(IMAGE):$(VERSION)
endif
.PHONY: build-systemutil
build-systemutil:
docker build --build-arg TAG=$(GIT_COMMIT_SHA) --build-arg OS=linux --build-arg ARCH=$(ARCH) -t csi-driver-builder --pull -f Dockerfile.builder .
docker run --env GHE_TOKEN=${GHE_TOKEN} csi-driver-builder
docker cp `docker ps -q -n=1`:/go/bin/${EXE_DRIVER_NAME} ./${EXE_DRIVER_NAME}
.PHONY: test-sanity
test-sanity: deps fmt
SANITY_PARAMS_FILE=./csi_sanity_params.yaml go test -timeout 60s ./tests/sanity -run ^TestSanity$$ -v
.PHONY: clean
clean:
rm -rf ${EXE_DRIVER_NAME}
rm -rf $(GOPATH)/bin/${EXE_DRIVER_NAME}
.PHONY: runanalyzedeps
runanalyzedeps:
@docker build --rm --build-arg ARTIFACTORY_API_KEY="${ARTIFACTORY_API_KEY}" -t armada/analyze-deps -f Dockerfile.dependencycheck .
docker run -v `pwd`/dependency-check:/results armada/analyze-deps
.PHONY: analyzedeps
analyzedeps:
/tmp/dependency-check/bin/dependency-check.sh --enableExperimental --log /results/logfile --out /results --disableAssembly \
--suppress /src/dependency-check/suppression-file.xml --format JSON --prettyPrint --failOnCVSS 0 --scan /src
.PHONY: showanalyzedeps
showanalyzedeps:
grep "VULNERABILITY FOUND" dependency-check/logfile;
cat dependency-check/dependency-check-report.json |jq '.dependencies[] | select(.vulnerabilities | length>0)';
.PHONY: updatebaseline
updatebaseline:
detect-secrets scan --update .secrets.baseline --all-files --exclude-files go.sum --db2-scan
.PHONY: auditbaseline
auditbaseline:
detect-secrets audit .secrets.baseline