Skip to content

Commit

Permalink
Add GitHub Actions workflow to scan Docker images (#317)
Browse files Browse the repository at this point in the history
Signed-off-by: Khalid <[email protected]>
  • Loading branch information
Hawazyn authored Nov 20, 2024
1 parent 333de4b commit b04c59e
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/docker-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build and Scan Docker Images

on:
workflow_dispatch:
push:
branches:
- main

jobs:
build-and-scan:
name: ${{ matrix.folder }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
folder: ["curl", "httpd", "locust", "nginx", "wireshark"]

steps:
- name: Checkout Repository
uses: actions/[email protected]

- name: Log in to Docker Hub
# Required for Docker Scout
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker Image
run: |
FILES=$(find ./${{ matrix.folder }} -type f -iname 'dockerfile*')
if [ -z "$FILES" ]; then
echo "No Dockerfiles found in folder: ${{ matrix.folder }}. Skipping build."
exit 1
fi
for FILE in $FILES; do
IMAGE_NAME="${{ matrix.folder }}-$(basename $FILE | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]-')"
echo "Building Docker image: $IMAGE_NAME using $FILE"
docker build -t $IMAGE_NAME -f $FILE ./${{ matrix.folder }}
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
done
- name: Scan Docker Image
uses: docker/[email protected]
with:
image: ${{ env.IMAGE_NAME }}
command: cves,recommendations
sarif-file: sarif.output.json

- name: Export the Results
uses: actions/[email protected]
with:
name: docker-scout-sarif-${{ matrix.folder }}
path: sarif.output.json

0 comments on commit b04c59e

Please sign in to comment.