-
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 6 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,90 @@ | ||
| name: Docker Compose Image Metadata and CVE Scan | ||
| name: Docker Scout PR Analysis | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**/docker-compose*.yml' | ||
| - '**/docker-compose*.yaml' | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| # Set permissions to ensure we can create/update comments. | ||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| scan: | ||
| scout: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout Code | ||
| # 1. Check out the PR code. | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Detect Changed docker-compose Files | ||
| id: files | ||
| # 2. Ensure Docker (and Docker Scout) is available. | ||
| # (Docker Scout is integrated into the Docker CLI in recent versions.) | ||
| - name: Set up Docker Scout | ||
| 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 | ||
| echo "Docker version:" | ||
| docker --version | ||
| echo "Docker Scout version:" | ||
| docker scout version | ||
| - name: Prepare Empty Report File | ||
| # 3. Find any changed docker-compose files. | ||
| - name: Find changed docker-compose files | ||
| id: find-files | ||
| run: | | ||
| echo "Docker Compose Image Metadata and CVE Report" > report.txt | ||
| echo "=============================================" >> report.txt | ||
| - name: Scan docker-compose Files for Images and CVEs | ||
| if: steps.files.outputs.files != '' | ||
| # List changed files between the PR base and current HEAD | ||
| CHANGED_FILES=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" HEAD | grep -Ei 'docker-compose\.(ya?ml)' || true) | ||
| echo "Found changed docker-compose files:" | ||
| echo "$CHANGED_FILES" | ||
| # Export as an output (if multiple files, they’ll be whitespace separated) | ||
| echo "::set-output name=files::${CHANGED_FILES}" | ||
| # 4. Analyze Docker images and CVEs from the changed files. | ||
| - name: Analyze Docker images in docker-compose files | ||
| id: analyze | ||
| 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 | ||
| # Initialize the Markdown output | ||
| OUTPUT_FILE="docker-scout-results.md" | ||
| echo "### Docker Scout Analysis" > $OUTPUT_FILE | ||
| echo "" >> $OUTPUT_FILE | ||
| echo "| Docker Image | Metadata | Open CVEs |" >> $OUTPUT_FILE | ||
| echo "|--------------|----------|-----------|" >> $OUTPUT_FILE | ||
| if [ -z "${{ steps.find-files.outputs.files }}" ]; then | ||
| echo "No docker-compose files changed." >> $OUTPUT_FILE | ||
| else | ||
| for file in ${{ steps.find-files.outputs.files }}; do | ||
| echo "Processing file: $file" | ||
| # Extract lines that define an image (adjust the regex as needed) | ||
| IMAGES=$(grep -E '^\s*image:' "$file" | awk '{print $2}') | ||
| for image in $IMAGES; do | ||
| echo "Scanning image: $image" | ||
| # Use Docker Scout to inspect the image metadata. | ||
| # (Assumes that “docker scout inspect” outputs JSON; adjust formatting as needed.) | ||
| METADATA=$(docker scout inspect "$image" --format '{{json .}}' 2>/dev/null || echo '{}') | ||
| # For demonstration, extract repository and tag (requires jq). | ||
| SHORT_META=$(echo "$METADATA" | jq -r 'if .Repository and .Tag then "\(.Repository)@\(.Tag)" else "N/A" end' 2>/dev/null) | ||
| # Get open CVEs (again, adjust the command/format as needed). | ||
| CVES=$(docker scout cves "$image" 2>/dev/null || echo "None") | ||
| # Remove newlines from CVES so the Markdown table stays intact. | ||
| CVES=$(echo "$CVES" | tr '\n' ' ') | ||
| 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 | ||
| # Append a row to the Markdown table. | ||
| echo "| \`$image\` | $SHORT_META | $CVES |" >> $OUTPUT_FILE | ||
| done | ||
| done | ||
| echo "---------------------------------------------" >> report.txt | ||
| done | ||
| # Display the final report. | ||
| cat report.txt | ||
| fi | ||
| echo "Docker Scout Analysis:" | ||
| cat $OUTPUT_FILE | ||
| # Set the output so it can be used in the next step. | ||
| echo "::set-output name=result::$(cat $OUTPUT_FILE)" | ||
| - name: Post PR Comment with the Report | ||
| if: steps.files.outputs.files != '' | ||
| uses: actions/github-script@v6 | ||
| # 5. Post the Markdown table as a comment on the PR. | ||
| - name: Comment on PR with Docker Scout results | ||
| uses: peter-evans/create-or-update-comment@v2 | ||
| 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```" | ||
| }); | ||
| issue-number: ${{ github.event.pull_request.number }} | ||
| body: | | ||
| ${{ steps.analyze.outputs.result }} | ||
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.