Skip to content

Commit 192d5e3

Browse files
authored
feat: add install_grype command (#45)
The command to install Grype a vulnerability scanner. By default, the latest version is installed. Useful for cases when the source of an image being scanned is the Docker daemon, i.e. when using machine executor.
1 parent bd89635 commit 192d5e3

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
@@ -71,6 +71,18 @@ jobs:
7171
echo "Failed to install chosen syft version"
7272
exit 1
7373
fi
74+
install_grype:
75+
executor: core/node
76+
steps:
77+
- security/install_grype:
78+
version: v0.92.1
79+
- run:
80+
name: Validate installation
81+
command: |
82+
if ! grype --version | grep -q "0.92.1"; then
83+
echo "Failed to install chosen grype version"
84+
exit 1
85+
fi
7486
7587
workflows:
7688
test-deploy:
@@ -115,6 +127,8 @@ workflows:
115127
filters: *filters
116128
- install_syft:
117129
filters: *filters
130+
- install_grype:
131+
filters: *filters
118132
- orb-tools/pack:
119133
filters: *release-filters
120134
- orb-tools/publish:
@@ -133,5 +147,6 @@ workflows:
133147
- analyze_code_full
134148
- install_trivy
135149
- install_syft
150+
- install_grype
136151
context: orb-publishing
137152
filters: *release-filters

src/commands/install_grype.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
description: >
2+
Install Grype (https://github.com/anchore/grype) a vulnerability scanner for
3+
container images and filesystems.
4+
5+
parameters:
6+
version:
7+
type: string
8+
default: ""
9+
description: >
10+
Choose the specific version of Grype from https://github.com/anchore/grype/releases.
11+
By default, the latest version is picked.
12+
13+
steps:
14+
- run:
15+
name: Install Grype
16+
environment:
17+
PARAM_STR_VERSION: <<parameters.version>>
18+
command: <<include(scripts/install-grype.sh)>>

src/scripts/install-grype.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/anchore/grype"
4+
INSTALL_SCRIPT_URL="${BASE_URL}/main/install.sh"
5+
GRYPE_DEST_DIR="${GRYPE_DEST_DIR:-/usr/local/bin}"
6+
7+
function install_grype () {
8+
local script_args=(-b "${GRYPE_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 grype ${PARAM_STR_VERSION:-latest} at ${GRYPE_DEST_DIR}"
19+
}
20+
21+
if ! command -v grype >/dev/null 2>&1; then
22+
echo "Failed to detect grype, installing..."
23+
24+
install_grype
25+
fi

0 commit comments

Comments
 (0)