Skip to content

Fix trivy scan flow #2310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
TRIVY := $(TOOLS_BIN_DIR)/trivy
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes

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

# Trivy
TRIVY_VER := 0.61.1

# kind
CAPI_KIND_CLUSTER_NAME ?= capi-test

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

.PHONY: verify-container-images
verify-container-images: $(TRIVY) ## Verify container images
TRACE=$(TRACE) ./hack/verify-container-images.sh
verify-container-images: ## Verify container images
TRACE=$(TRACE) ./hack/verify-container-images.sh $(TRIVY_VER)

.PHONY: verify-govulncheck
verify-govulncheck: $(GOVULNCHECK) ## Verify code for vulnerabilities
Expand Down
59 changes: 59 additions & 0 deletions hack/ensure-trivy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Copyright 2025 The Kubernetes Authors.
#
# 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.

set -o errexit
set -o nounset
set -o pipefail

if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi

VERSION=${1}

GO_OS="$(go env GOOS)"
if [[ "${GO_OS}" == "linux" ]]; then
TRIVY_OS="Linux"
elif [[ "${GO_OS}" == "darwin"* ]]; then
TRIVY_OS="macOS"
fi

GO_ARCH="$(go env GOARCH)"
if [[ "${GO_ARCH}" == "amd" ]]; then
TRIVY_ARCH="32bit"
elif [[ "${GO_ARCH}" == "amd64"* ]]; then
TRIVY_ARCH="64bit"
elif [[ "${GO_ARCH}" == "arm" ]]; then
TRIVY_ARCH="ARM"
elif [[ "${GO_ARCH}" == "arm64" ]]; then
TRIVY_ARCH="ARM64"
elif [[ "${GO_ARCH}" == "ppc64le" ]]; then
TRIVY_ARCH="PPC64LE"
fi

TOOL_BIN=hack/tools/bin
mkdir -p ${TOOL_BIN}

TRIVY="${TOOL_BIN}/trivy/${VERSION}/trivy"

# Downloads trivy scanner
if [ ! -f "$TRIVY" ]; then
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"
mkdir -p "$(dirname "$0")/tools/bin/trivy/${VERSION}"
tar -xf "${TOOL_BIN}/trivy.tar.gz" -C "${TOOL_BIN}/trivy/${VERSION}" trivy
chmod +x "${TOOL_BIN}/trivy/${VERSION}/trivy"
rm "${TOOL_BIN}/trivy.tar.gz"
fi
4 changes: 0 additions & 4 deletions hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ GOVULNCHECK := $(BIN_DIR)/govulncheck
$(GOVULNCHECK): $(BIN_DIR) go.mod go.sum ## Build a local copy of govulncheck.
go build -tags=capibmtools -o $@ golang.org/x/vuln/cmd/govulncheck

TRIVY := $(BIN_DIR)/trivy
$(TRIVY): $(BIN_DIR) go.mod go.sum ## Build a local copy of trivy.
go build -tags=capibmtools -o $@ github.com/aquasecurity/trivy/cmd/trivy

RELEASE_NOTES := $(BIN_DIR)/release-notes
$(RELEASE_NOTES): $(BIN_DIR) go.mod go.sum ## Build a local copy of release-notes.
go build -tags=capibmtools -o $@ k8s.io/release/cmd/release-notes
Loading