Skip to content

Commit 85aa95e

Browse files
committed
Add boilerplate
1 parent 18c4039 commit 85aa95e

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

actions/scan-image/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## 0.1.0 (2025-10-03)
4+
5+
### 🎉 Features
6+
7+
* **scan-image:** add `snyk` and `trivy` vulnerability scanners with a fail condition configuration
8+
* **scan-image:** add [Dockerhub](https://hub.docker.com/) and [Google Artifact Registry](https://cloud.google.com/artifact-registry/docs) as available private sources

actions/scan-image/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# scan-image
2+
3+
This is a composite GitHub Action used to scan your images in search of vulnerabilities.
4+
5+
The goal is to provide developers a way to check if their PR changes, without having to
6+
wait for periodic scans (Faster feedback loop). This can also be used as part of deployment
7+
CI/CD jobs as a way to verify things before shipping to production environments.
8+
9+
<!-- x-release-please-start-version -->
10+
11+
```yaml
12+
name: Scan image for vulnerabilities
13+
jobs:
14+
scan-image:
15+
name: Scan image for vulnerabilities
16+
steps:
17+
- name: Scan image for vulnerabilities
18+
id: scan-image
19+
uses: grafana/shared-workflows/actions/scan-image@scan-image/v0.1.0
20+
with:
21+
image_name: docker.io/hello-world
22+
fail_on: critical
23+
fail_on_threshold: 1
24+
```
25+
26+
<!-- x-release-please-end-version -->

actions/scan-image/action.yaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Scan Image
2+
description: Composite action to check an image for vulnerabilities
3+
4+
inputs:
5+
image_name:
6+
description: "The name of the image to scan, including the registry e.g. docker.io/hello-world"
7+
required: true
8+
image_source:
9+
description: "The source of the image to scan"
10+
type: choice
11+
options:
12+
- public
13+
- private_dockerhub
14+
- private_gar
15+
default: public
16+
fail_on:
17+
description: "Whether to fail the workflow if vulnerabilities are found"
18+
type: choice
19+
options:
20+
- critical
21+
- high
22+
- medium
23+
- low
24+
default: critical
25+
fail_on_threshold:
26+
description: "The threshold of vulnerabilities to fail the workflow on"
27+
type: integer
28+
default: 1
29+
trivy_version:
30+
description: "The version of Trivy to use (The latest will be used if not provided)"
31+
type: string
32+
33+
outputs:
34+
trivy:
35+
description: "The results of the Trivy scan"
36+
value: ${{ steps.run-trivy.outputs.results }}
37+
38+
runs:
39+
using: composite
40+
steps:
41+
42+
- name: Login to DockerHub
43+
id: login-to-dockerhub
44+
if: inputs.image_source == 'private_dockerhub'
45+
uses: grafana/shared-workflows/actions/[email protected]
46+
47+
- name: Extract GAR registry
48+
id: extract-gar-registry
49+
if: inputs.image_source == 'private_gar'
50+
shell: bash
51+
run: |
52+
IMAGE_NAME="${{ inputs.image_name }}"
53+
REGISTRY="${IMAGE_NAME%%/*}"
54+
echo "registry=${REGISTRY}" >> $GITHUB_OUTPUT
55+
56+
- name: Login to GAR
57+
id: login-to-gar
58+
if: inputs.image_source == 'private_gar'
59+
uses: grafana/shared-workflows/actions/login-to-gar@login-to-gar/v1.0.0
60+
with:
61+
registry: ${{ steps.extract-gar-registry.outputs.registry }}
62+
63+
- name: Setup Trivy (Latest)
64+
id: setup-trivy-latest
65+
if: inputs.trivy_version == ''
66+
uses: aquasecurity/[email protected]
67+
68+
- name: Setup Trivy (Pinned)
69+
id: setup-trivy-pinned
70+
if: inputs.trivy_version != ''
71+
uses: aquasecurity/[email protected]
72+
with:
73+
version: ${{ inputs.trivy_version }}
74+
75+
- name: Run Trivy
76+
id: run-trivy
77+
shell: bash
78+
run: |
79+
trivy image ${{ inputs.image_name }} -f json > trivy.json
80+
cat trivy.json
81+
echo "results=$(cat trivy.json)" >> $GITHUB_OUTPUT
82+
83+

0 commit comments

Comments
 (0)