Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ‹ Output trivy results, and neater summary

Alicia Sykesbf8628a4cc5f
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 925e6e20..0d4535f3 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -122,6 +122,7 @@ jobs:
CREATED=${{ steps.timestamp.outputs.iso }}
- name: πŸ›‘οΈ Trivy vulnerability scan
+ id: scan
uses: aquasecurity/[email protected]
env:
TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db:2
@@ -137,6 +138,23 @@ jobs:
output: 'trivy-${{ matrix.arch }}.sarif'
timeout: '10m'
+ # SARIF isn't human-readable, so on a gating failure re-print the CVEs as a table
+ - name: πŸ“‹ List blocking CVEs (on scan failure)
+ if: steps.scan.outcome == 'failure'
+ uses: aquasecurity/[email protected]
+ env:
+ TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db:2
+ TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db:1
+ with:
+ version: v0.70.0
+ image-ref: dashy-scan:${{ matrix.arch }}
+ severity: CRITICAL
+ ignore-unfixed: true
+ exit-code: '0'
+ vuln-type: 'os,library'
+ format: 'table'
+ timeout: '10m'
+
- name: πŸ“€ Upload Trivy SARIF
if: always() && hashFiles(format('trivy-{0}.sarif', matrix.arch)) != ''
uses: github/codeql-action/upload-sarif@v4
@@ -144,15 +162,6 @@ jobs:
sarif_file: trivy-${{ matrix.arch }}.sarif
category: trivy-${{ matrix.arch }}
- - name: πŸ“€ Upload Trivy artifact
- if: always() && hashFiles(format('trivy-{0}.sarif', matrix.arch)) != ''
- uses: actions/upload-artifact@v7
- with:
- name: trivy-${{ matrix.arch }}
- path: trivy-${{ matrix.arch }}.sarif
- if-no-files-found: ignore
- retention-days: 1
-
- name: πŸš€ Push by digest
id: push
uses: docker/build-push-action@v7
@@ -196,7 +205,7 @@ jobs:
id-token: write
attestations: write
env:
- HAS_DH: ${{ secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' }}
+ HAS_DH: ${{ vars.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' }}
SEMVER_VALUE: ${{ inputs.tag || github.ref_name }}
SEMVER_ENABLE: ${{ github.event_name == 'push' || inputs.tag != '' }}
LATEST_ENABLE: ${{ inputs.tag == '' }}
@@ -208,14 +217,6 @@ jobs:
pattern: digest-*
merge-multiple: true
- - name: πŸ“₯ Download Trivy SARIFs
- uses: actions/download-artifact@v8
- continue-on-error: true
- with:
- path: ${{ runner.temp }}/trivy
- pattern: trivy-*
- merge-multiple: true
-
- name: πŸ”§ Set up Buildx
uses: docker/setup-buildx-action@v4
@@ -230,7 +231,7 @@ jobs:
if: env.HAS_DH == 'true'
uses: docker/login-action@v4
with:
- username: ${{ secrets.DOCKER_USERNAME }}
+ username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: πŸ—‚οΈ Generate tags
@@ -293,7 +294,7 @@ jobs:
subject-digest: ${{ steps.manifest.outputs.digest }}
push-to-registry: true
- - name: πŸ“‹ Summary
+ - name: πŸ“‹ Job summary
if: always()
continue-on-error: true
env:
@@ -301,100 +302,56 @@ jobs:
SBOM_URL: ${{ steps.attest_sbom.outputs.attestation-url }}
PROV_OUTCOME: ${{ steps.attest_provenance.outcome }}
PROV_URL: ${{ steps.attest_provenance.outputs.attestation-url }}
- DIGEST: ${{ steps.manifest.outputs.digest }}
+ MANIFEST: ${{ steps.manifest.outputs.digest }}
PRIMARY: ${{ steps.manifest.outputs.primary_tag }}
TAGS_JSON: ${{ steps.meta.outputs.json }}
DIGESTS_DIR: ${{ runner.temp }}/digests
- TRIVY_DIR: ${{ runner.temp }}/trivy
- # Behold, some ugly bash, to produce a pretty output (don't read it, just trust)
run: |
set -euo pipefail
+ repo="${PRIMARY%%:*}"
- attest_line() {
- local label="$1" outcome="$2" url="$3"
- case "$outcome" in
- success)
- if [ -n "$url" ]; then
- echo "- βœ… $label attested ([view]($url))"
- else
- echo "- βœ… $label attested"
- fi ;;
- failure) echo "- ⚠️ $label attestation failed (image pushed without attest)" ;;
- *) echo "- ⏭️ $label attestation \`$outcome\`" ;;
+ attest() {
+ case "$2" in
+ success) [ -n "$3" ] && echo "- βœ… $1 attested ([view]($3))" || echo "- βœ… $1 attested" ;;
+ failure) echo "- ⚠️ $1 attestation failed" ;;
+ *) echo "- ⏭️ $1 attestation skipped" ;;
esac
}
- trivy_section() {
- local dir="$1"
- [ -d "$dir" ] || return 0
- local found=0
- local lines=""
- local arch f n
- for arch in amd64 arm64 armv7; do
- f="$dir/trivy-$arch.sarif"
- [ -f "$f" ] || continue
- found=1
- n=$(jq '[.runs[]?.results[]?] | length' "$f" 2>/dev/null || echo 0)
- [[ "$n" =~ ^[0-9]+$ ]] || n=0
- if [ "$n" = "0" ]; then
- lines+="- βœ… \`$arch\` β€” no fixable CRITICAL CVEs"$'\n'
- else
- lines+="- ⚠️ \`$arch\` β€” $n fixable CRITICAL CVE(s)"$'\n'
- fi
- done
- [ "$found" = "1" ] || return 0
- echo "## Security Scan"
- echo ""
- echo "Trivy (CRITICAL severity, fixable only):"
- echo ""
- printf '%s\n' "$lines"
- echo "---"
- echo ""
- }
-
- arch_section() {
- local arch="$1"
- local file="$DIGESTS_DIR/$arch"
- [ -f "$file" ] || return 0
- local digest manifest size count
- digest=$(cat "$file")
- manifest=$(docker buildx imagetools inspect "${PRIMARY%%:*}@$digest" --raw 2>/dev/null || echo '{}')
- size=$(jq '[.layers[]?.size // 0] | add // 0' <<< "$manifest")
- count=$(jq '.layers // [] | length' <<< "$manifest")
- echo "#### Dashy \`$arch\`"
- echo ""
- echo "- **Digest:** \`$digest\`"
- [ "$size" != "0" ] && echo "- **Size:** $(numfmt --to=iec --suffix=B "$size" 2>/dev/null || echo "$size B")"
- [ "$count" != "0" ] && echo "- **Layers:** $count"
- echo ""
- }
-
- # Clear auto-generated "Attestation Created" blocks from attest actions.
+ # Replace the attest actions' auto-added blocks with our own summary
: > "$GITHUB_STEP_SUMMARY"
{
- if [ -n "$DIGEST" ]; then
- echo "## Docker Image"
- echo ""
- echo "**Manifest:** \`$DIGEST\`"
- echo ""
- echo '```bash'
- jq -r '.tags[] | "docker pull \(.)"' <<< "$TAGS_JSON"
- echo '```'
- echo ""
- echo "---"
- echo ""
- fi
echo "## Attestations"
- echo ""
- attest_line "SBOM" "$SBOM_OUTCOME" "$SBOM_URL"
- attest_line "Build provenance" "$PROV_OUTCOME" "$PROV_URL"
- echo ""
+ echo
+ attest "SBOM" "$SBOM_OUTCOME" "$SBOM_URL"
+ attest "Build provenance" "$PROV_OUTCOME" "$PROV_URL"
+ echo
echo "---"
- echo ""
- trivy_section "$TRIVY_DIR"
+ echo
echo "## Build Info"
- echo ""
+ echo
+ echo "| Arch | Size | Layers | Digest |"
+ echo "|---|---|---|---|"
for arch in amd64 arm64 armv7; do
- arch_section "$arch"
+ f="$DIGESTS_DIR/$arch"
+ [ -f "$f" ] || continue
+ digest=$(cat "$f")
+ raw=$(docker buildx imagetools inspect "$repo@$digest" --raw 2>/dev/null || echo '{}')
+ bytes=$(jq '[.layers[]?.size // 0] | add // 0' <<< "$raw")
+ size=$(numfmt --to=iec --suffix=B "$bytes" 2>/dev/null || echo "${bytes}B")
+ layers=$(jq '.layers // [] | length' <<< "$raw")
+ echo "| \`$arch\` | $size | $layers | \`$digest\` |"
done
+ echo
+ echo "---"
+ echo
+ echo "## Docker Image"
+ echo
+ echo "**Manifest:** \`$MANIFEST\`"
+ echo
+ echo "The following tags have been updated and published:"
+ echo
+ echo '```'
+ if [ -n "${TAGS_JSON:-}" ]; then jq -r '.tags[]?' <<< "$TAGS_JSON"; fi
+ echo '```'
} >> "$GITHUB_STEP_SUMMARY"