Skip to content

Commit 38fffdc

Browse files
Fix trviy scan flow (#2310)
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent d4ca9c3 commit 38fffdc

File tree

7 files changed

+69
-1281
lines changed

7 files changed

+69
-1281
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
4949
CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier
5050
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
5151
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
52-
TRIVY := $(TOOLS_BIN_DIR)/trivy
5352
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
5453

5554
STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
@@ -88,6 +87,9 @@ OUTPUT_TYPE ?= type=registry
8887
GO_VERSION ?=1.23.8
8988
GO_CONTAINER_IMAGE ?= golang:$(GO_VERSION)
9089

90+
# Trivy
91+
TRIVY_VER := 0.61.1
92+
9193
# kind
9294
CAPI_KIND_CLUSTER_NAME ?= capi-test
9395

@@ -552,8 +554,8 @@ verify-conversions: $(CONVERSION_VERIFIER) ## Verifies expected API conversion a
552554
$(CONVERSION_VERIFIER)
553555

554556
.PHONY: verify-container-images
555-
verify-container-images: $(TRIVY) ## Verify container images
556-
TRACE=$(TRACE) ./hack/verify-container-images.sh
557+
verify-container-images: ## Verify container images
558+
TRACE=$(TRACE) ./hack/verify-container-images.sh $(TRIVY_VER)
557559

558560
.PHONY: verify-govulncheck
559561
verify-govulncheck: $(GOVULNCHECK) ## Verify code for vulnerabilities

hack/ensure-trivy.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
if [[ "${TRACE-0}" == "1" ]]; then
22+
set -o xtrace
23+
fi
24+
25+
VERSION=${1}
26+
27+
GO_OS="$(go env GOOS)"
28+
if [[ "${GO_OS}" == "linux" ]]; then
29+
TRIVY_OS="Linux"
30+
elif [[ "${GO_OS}" == "darwin"* ]]; then
31+
TRIVY_OS="macOS"
32+
fi
33+
34+
GO_ARCH="$(go env GOARCH)"
35+
if [[ "${GO_ARCH}" == "amd" ]]; then
36+
TRIVY_ARCH="32bit"
37+
elif [[ "${GO_ARCH}" == "amd64"* ]]; then
38+
TRIVY_ARCH="64bit"
39+
elif [[ "${GO_ARCH}" == "arm" ]]; then
40+
TRIVY_ARCH="ARM"
41+
elif [[ "${GO_ARCH}" == "arm64" ]]; then
42+
TRIVY_ARCH="ARM64"
43+
elif [[ "${GO_ARCH}" == "ppc64le" ]]; then
44+
TRIVY_ARCH="PPC64LE"
45+
fi
46+
47+
TOOL_BIN=hack/tools/bin
48+
mkdir -p ${TOOL_BIN}
49+
50+
TRIVY="${TOOL_BIN}/trivy/${VERSION}/trivy"
51+
52+
# Downloads trivy scanner
53+
if [ ! -f "$TRIVY" ]; then
54+
curl -L -o ${TOOL_BIN}/trivy.tar.gz "https://github.com/aquasecurity/trivy/releases/download/v${VERSION}/trivy_${VERSION}_${TRIVY_OS}-${TRIVY_ARCH}.tar.gz"
55+
mkdir -p "$(dirname "$0")/tools/bin/trivy/${VERSION}"
56+
tar -xf "${TOOL_BIN}/trivy.tar.gz" -C "${TOOL_BIN}/trivy/${VERSION}" trivy
57+
chmod +x "${TOOL_BIN}/trivy/${VERSION}/trivy"
58+
rm "${TOOL_BIN}/trivy.tar.gz"
59+
fi

hack/tools/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ GOVULNCHECK := $(BIN_DIR)/govulncheck
126126
$(GOVULNCHECK): $(BIN_DIR) go.mod go.sum ## Build a local copy of govulncheck.
127127
go build -tags=capibmtools -o $@ golang.org/x/vuln/cmd/govulncheck
128128

129-
TRIVY := $(BIN_DIR)/trivy
130-
$(TRIVY): $(BIN_DIR) go.mod go.sum ## Build a local copy of trivy.
131-
go build -tags=capibmtools -o $@ github.com/aquasecurity/trivy/cmd/trivy
132-
133129
RELEASE_NOTES := $(BIN_DIR)/release-notes
134130
$(RELEASE_NOTES): $(BIN_DIR) go.mod go.sum ## Build a local copy of release-notes.
135131
go build -tags=capibmtools -o $@ k8s.io/release/cmd/release-notes

0 commit comments

Comments
 (0)