feat(setup-trivy)!: automatically determine arch (#14)
CD / Release (push) Successful in 12s
CD / Release (push) Successful in 12s
Mapping x86_64 to "64bit" and aarch64 to "ARM64" as this is how Trivy names their releases. Adjusted CICD to test-run both amd64 and arm64 versions. Reviewed-on: t.behrendt/trivy-actions#14 Reviewed-by: branch-buddy <branch-buddy@t00n.de> Co-authored-by: Timo Behrendt <t.behrendt@t00n.de> Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
This commit was merged in pull request #14.
This commit is contained in:
@@ -5,17 +5,19 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-setup-trivy:
|
test-setup-trivy:
|
||||||
name: Test Setup Trivy
|
strategy:
|
||||||
|
matrix:
|
||||||
|
arch: [amd64, arm64]
|
||||||
|
name: Test Setup Trivy ${{ matrix.arch }}
|
||||||
runs-on:
|
runs-on:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- linux_amd64
|
- linux_${{ matrix.arch }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
- name: Setup Trivy
|
- name: Setup Trivy
|
||||||
uses: ./setup-trivy
|
uses: ./setup-trivy
|
||||||
with:
|
with:
|
||||||
version: v0.66.0
|
version: v0.66.0
|
||||||
architecture: amd64
|
|
||||||
- name: Run Trivy
|
- name: Run Trivy
|
||||||
run: trivy --version
|
run: trivy --version
|
||||||
|
|
||||||
@@ -23,13 +25,11 @@ jobs:
|
|||||||
name: Test Setup DB
|
name: Test Setup DB
|
||||||
runs-on:
|
runs-on:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- linux_amd64
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
- uses: ./setup-trivy
|
- uses: ./setup-trivy
|
||||||
with:
|
with:
|
||||||
version: v0.66.0
|
version: v0.66.0
|
||||||
architecture: amd64
|
|
||||||
- name: Setup DB
|
- name: Setup DB
|
||||||
uses: ./setup-db
|
uses: ./setup-db
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ jobs:
|
|||||||
uses: https://gitea.t000-n.de/t.behrendt/trivy-actions/setup-trivy@0.0.1
|
uses: https://gitea.t000-n.de/t.behrendt/trivy-actions/setup-trivy@0.0.1
|
||||||
with:
|
with:
|
||||||
version: "v0.66.0"
|
version: "v0.66.0"
|
||||||
architecture: "amd64"
|
|
||||||
- name: Setup DB
|
- name: Setup DB
|
||||||
uses: https://gitea.t000-n.de/t.behrendt/trivy-actions/setup-db@0.0.1
|
uses: https://gitea.t000-n.de/t.behrendt/trivy-actions/setup-db@0.0.1
|
||||||
- name: Scan for vulnerabilities
|
- name: Scan for vulnerabilities
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ A reusable Gitea Action that downloads and sets up the Trivy binary for vulnerab
|
|||||||
uses: your-username/trivy-actions@main/setup-trivy
|
uses: your-username/trivy-actions@main/setup-trivy
|
||||||
with:
|
with:
|
||||||
version: "v0.66.0" # Optional: Trivy version (default: v0.66.0)
|
version: "v0.66.0" # Optional: Trivy version (default: v0.66.0)
|
||||||
architecture: "amd64" # Optional: amd64 or arm64 (default: amd64)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Complete Example
|
### Complete Example
|
||||||
@@ -31,14 +30,12 @@ jobs:
|
|||||||
uses: your-username/trivy-actions@main/setup-trivy
|
uses: your-username/trivy-actions@main/setup-trivy
|
||||||
with:
|
with:
|
||||||
version: "v0.66.0"
|
version: "v0.66.0"
|
||||||
architecture: "amd64"
|
|
||||||
- name: Scan for vulnerabilities
|
- name: Scan for vulnerabilities
|
||||||
run: trivy fs .
|
run: trivy fs .
|
||||||
```
|
```
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
| Input | Description | Required | Default |
|
| Input | Description | Required | Default |
|
||||||
| -------------- | ----------------------------------------- | -------- | --------- |
|
| --------- | ----------------------------------------- | -------- | --------- |
|
||||||
| `version` | Trivy version to download (e.g., v0.66.0) | No | `v0.66.0` |
|
| `version` | Trivy version to download (e.g., v0.66.0) | No | `v0.66.0` |
|
||||||
| `architecture` | System architecture (amd64, arm64) | No | `amd64` |
|
|
||||||
|
|||||||
+17
-38
@@ -7,45 +7,34 @@ branding:
|
|||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: "Trivy version to download (e.g., v0.66.0)"
|
description: "Trivy version to download (e.g., latest)"
|
||||||
required: false
|
required: false
|
||||||
default: "v0.66.0"
|
default: "v0.66.0"
|
||||||
architecture:
|
|
||||||
description: "System architecture (amd64, arm64)"
|
|
||||||
required: false
|
|
||||||
default: "amd64"
|
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
|
- shell: bash
|
||||||
|
id: arch
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
case "$(uname -m)" in
|
||||||
|
x86_64)
|
||||||
|
ARCH="64bit"
|
||||||
|
;;
|
||||||
|
aarch64)
|
||||||
|
ARCH="ARM64"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo "ARCH=$ARCH" >> $GITHUB_OUTPUT
|
||||||
- name: Cache Trivy binary
|
- name: Cache Trivy binary
|
||||||
id: cache-trivy
|
id: cache-trivy
|
||||||
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
|
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
|
||||||
with:
|
with:
|
||||||
path: /usr/local/bin/trivy
|
path: /usr/local/bin/trivy
|
||||||
key: trivy-${{ inputs.version }}-${{ inputs.architecture }}
|
key: trivy-${{ inputs.version }}-${{ steps.arch.outputs.arch }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
trivy-${{ inputs.version }}-${{ inputs.architecture }}-
|
trivy-${{ inputs.version }}-${{ steps.arch.outputs.arch }}
|
||||||
trivy-${{ inputs.version }}-
|
|
||||||
|
|
||||||
- name: Validate inputs
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
|
|
||||||
VERSION="${{ inputs.version }}"
|
|
||||||
ARCH="${{ inputs.architecture }}"
|
|
||||||
|
|
||||||
# Validate architecture
|
|
||||||
case "$ARCH" in
|
|
||||||
amd64|arm64)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Error: Unsupported architecture '$ARCH'. Supported: amd64, arm64"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
- name: Download and install Trivy
|
- name: Download and install Trivy
|
||||||
if: steps.cache-trivy.outputs.cache-hit != 'true'
|
if: steps.cache-trivy.outputs.cache-hit != 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -53,20 +42,10 @@ runs:
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
VERSION="${{ inputs.version }}"
|
VERSION="${{ inputs.version }}"
|
||||||
ARCH="${{ inputs.architecture }}"
|
|
||||||
|
|
||||||
case "$ARCH" in
|
|
||||||
amd64)
|
|
||||||
ARCH="64bit"
|
|
||||||
;;
|
|
||||||
arm64)
|
|
||||||
ARCH="ARM64"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
mkdir -p /usr/local/bin
|
mkdir -p /usr/local/bin
|
||||||
|
|
||||||
curl -sL "https://github.com/aquasecurity/trivy/releases/download/${VERSION}/trivy_${VERSION#v}_Linux-${ARCH}.tar.gz" -o trivy.tar.gz
|
curl -sL "https://github.com/aquasecurity/trivy/releases/download/${VERSION}/trivy_${VERSION#v}_Linux-${{ steps.arch.outputs.arch }}.tar.gz" -o trivy.tar.gz
|
||||||
tar -xzf trivy.tar.gz
|
tar -xzf trivy.tar.gz
|
||||||
chmod +x trivy
|
chmod +x trivy
|
||||||
mv trivy /usr/local/bin/
|
mv trivy /usr/local/bin/
|
||||||
|
|||||||
Reference in New Issue
Block a user