Skip to content

Commit d2e8d40

Browse files
authored
feat: add install_trivy command (#43)
The command to install Trivy open source security scanner. By default, the latest version is installed. Useful for cases when an image with preinstalled Trviy is not suitable, e.g. when the machine executor is needed.
1 parent 5464d0e commit d2e8d40

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

.circleci/test-deploy.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ jobs:
4747
- checkout
4848
- security/scan_dockerfile:
4949
dockerfile_dir: ./sample
50+
install_trivy:
51+
executor: core/node
52+
steps:
53+
- security/install_trivy:
54+
version: v0.59.1
55+
- run:
56+
name: Validate installation
57+
command: |
58+
if ! trivy --version | grep -q "0.59.1"; then
59+
echo "Failed to install chosen trivy version"
60+
exit 1
61+
fi
5062
5163
workflows:
5264
test-deploy:
@@ -87,6 +99,8 @@ workflows:
8799
name: analyze_code_full
88100
rules: p/cwe-top-25
89101
filters: *filters
102+
- install_trivy:
103+
filters: *filters
90104
- orb-tools/pack:
91105
filters: *release-filters
92106
- orb-tools/publish:
@@ -103,5 +117,6 @@ workflows:
103117
- detect_secrets_git_base_revision
104118
- analyze_code_diff
105119
- analyze_code_full
120+
- install_trivy
106121
context: orb-publishing
107122
filters: *release-filters

src/commands/install_trivy.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
description: >
2+
Install Trivy (https://github.com/aquasecurity/trivy) all-in-one open source
3+
security scanner, optionally selecting the specific version.
4+
5+
parameters:
6+
version:
7+
type: string
8+
default: ""
9+
description: >
10+
Choose the specific version of Trivy from https://github.com/aquasecurity/trivy/releases.
11+
By default, the latest version is picked.
12+
13+
steps:
14+
- run:
15+
name: Install Trivy
16+
environment:
17+
PARAM_STR_VERSION: <<parameters.version>>
18+
command: <<include(scripts/install-trivy.sh)>>

src/scripts/install-trivy.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
BASE_URL="https://raw.githubusercontent.com/aquasecurity/trivy"
4+
INSTALL_SCRIPT_URL="${BASE_URL}/main/contrib/install.sh"
5+
TRIVY_DEST_DIR="${TRIVY_DEST_DIR:-/usr/local/bin}"
6+
7+
function install_trivy () {
8+
local script_args=(-b "${TRIVY_DEST_DIR}")
9+
10+
if [[ -n "${PARAM_STR_VERSION}" ]]; then
11+
script_args+=("${PARAM_STR_VERSION}")
12+
fi
13+
14+
set -x
15+
curl -sfL --retry 1 "${INSTALL_SCRIPT_URL}" | sudo sh -s -- "${script_args[@]}"
16+
set +x
17+
18+
echo "Installed trivy ${PARAM_STR_VERSION:-latest} at ${TRIVY_DEST_DIR}"
19+
}
20+
21+
if ! command -v trivy >/dev/null 2>&1; then
22+
echo "Failed to detect trivy, installing..."
23+
24+
install_trivy
25+
fi

0 commit comments

Comments
 (0)