-
Notifications
You must be signed in to change notification settings - Fork 0
Update docker-compose.yml #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6920dad
Update docker-compose.yml
FinnPL 544e35e
Update docker-compose-scan.yml
FinnPL ea3e1b2
Update docker-compose-scan.yml
FinnPL 06192f4
Update docker-compose-scan.yml
FinnPL 9cf676f
Update docker-compose-scan.yml
FinnPL ef66154
Update docker-compose-scan.yml
FinnPL 7bf805b
Update docker-compose-scan.yml
FinnPL 799f529
Update docker-compose-scan.yml
FinnPL d3e376d
Update docker-compose-scan.yml
FinnPL d87c2b3
Update docker-compose-scan.yml
FinnPL 8d16fed
Update docker-compose-scan.yml
FinnPL 7ebb1b2
Rename docker-compose-scan.yml to docker-scan.yml
FinnPL 02a5886
Update docker-scan.yml
FinnPL c8fc15c
Update docker-scan.yml
FinnPL 89ea9a7
Update docker-scan.yml
FinnPL b233e0a
Update docker-scan.yml
FinnPL 380880e
Update docker-scan.yml
FinnPL 5ebbe9e
Update docker-compose.yml
FinnPL c333b64
Update docker-scan.yml
FinnPL 8cd0ca7
Update docker-scan.yml
FinnPL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,76 +1,71 @@ | ||
| name: Docker Compose Image Metadata and CVE Scan | ||
| name: Docker Scout Scan | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**/docker-compose*.yml' | ||
| - '**/docker-compose*.yaml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| scan: | ||
| # First job: find images from docker-compose files and output a matrix JSON | ||
| find-images: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| outputs: | ||
| matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
| steps: | ||
| - name: Checkout Code | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Detect Changed docker-compose Files | ||
| id: files | ||
| - name: Install jq and yq | ||
| run: | | ||
| # Get the target branch of the pull request from the event payload. | ||
| BASE_BRANCH=${{ github.event.pull_request.base.ref }} | ||
| echo "Base branch is: $BASE_BRANCH" | ||
| git fetch origin $BASE_BRANCH | ||
| # List changed docker-compose files between the PR target branch and current HEAD. | ||
| CHANGED=$(git diff --name-only origin/$BASE_BRANCH...HEAD | grep -i 'docker-compose.*\.ya\?ml' || true) | ||
| echo "Changed docker-compose files:" | ||
| echo "$CHANGED" | ||
| echo "files=$CHANGED" >> $GITHUB_OUTPUT | ||
| sudo apt-get update && sudo apt-get install -y jq | ||
| # Install yq if not already installed | ||
| if ! command -v yq &>/dev/null; then | ||
| wget https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 -O /usr/local/bin/yq | ||
| chmod +x /usr/local/bin/yq | ||
| fi | ||
| - name: Prepare Empty Report File | ||
| - name: Find images in Docker Compose files | ||
| id: find | ||
| run: | | ||
| echo "Docker Compose Image Metadata and CVE Report" > report.txt | ||
| echo "=============================================" >> report.txt | ||
| echo "Searching for docker-compose*.yml files..." | ||
| files=$(find . -type f -name "docker-compose*.yml") | ||
| echo "Found files:" | ||
| echo "$files" | ||
| images=() | ||
| for file in $files; do | ||
| echo "Processing $file" | ||
| # Use yq to extract all image fields from services | ||
| while IFS= read -r image; do | ||
| if [[ -n "$image" ]]; then | ||
| images+=("$image") | ||
| fi | ||
| done < <(yq e '.services[].image // empty' "$file") | ||
| done | ||
| # Remove duplicates (if any) | ||
| unique_images=($(echo "${images[@]}" | tr ' ' '\n' | sort -u)) | ||
| echo "Unique images found: ${unique_images[@]}" | ||
| # Create a JSON array for the matrix | ||
| matrix=$(printf '%s\n' "${unique_images[@]}" | jq -R . | jq -s .) | ||
| echo "Matrix JSON: $matrix" | ||
| # Set the output for use in the next job | ||
| echo "::set-output name=matrix::$matrix" | ||
| - name: Scan docker-compose Files for Images and CVEs | ||
| if: steps.files.outputs.files != '' | ||
| run: | | ||
| # Loop over each changed docker-compose file. | ||
| for file in $(echo "${{ steps.files.outputs.files }}"); do | ||
| echo "Processing file: $file" >> report.txt | ||
| # Extract image names (assuming docker-compose syntax "image: <imagename>") | ||
| IMAGES=$(grep -oP 'image:\s*\K.+' "$file" | tr -d '"' ) | ||
| if [ -z "$IMAGES" ]; then | ||
| echo " No images found in $file" >> report.txt | ||
| continue | ||
| fi | ||
| - name: Set matrix output | ||
| id: set-matrix | ||
| run: echo "matrix=${{ steps.find.outputs.matrix }}" >> $GITHUB_OUTPUT | ||
|
|
||
| for image in $IMAGES; do | ||
| echo " Found image: $image" >> report.txt | ||
| # Run Docker Scout to check for CVEs. | ||
| echo " Running docker scout cves $image ..." >> report.txt | ||
| SCOUT_OUTPUT=$(docker scout cves "$image" 2>&1 || echo " Error scanning $image") | ||
| echo "$SCOUT_OUTPUT" >> report.txt | ||
| done | ||
| echo "---------------------------------------------" >> report.txt | ||
| done | ||
| # Display the final report. | ||
| cat report.txt | ||
| # Second job: run Docker Scout scan for each image found | ||
| scan-images: | ||
| needs: find-images | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| image: ${{ fromJson(needs.find-images.outputs.matrix) }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Post PR Comment with the Report | ||
| if: steps.files.outputs.files != '' | ||
| uses: actions/github-script@v6 | ||
| - name: Scan image with Docker Scout | ||
| id: scout | ||
| uses: docker/scout-action@v1 | ||
|
||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const report = fs.readFileSync('report.txt', 'utf8'); | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: "## Docker Compose Image Metadata and CVE Scan Report\n```\n" + report + "\n```" | ||
| }); | ||
| command: cves | ||
| image: ${{ matrix.image }} | ||
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.