2024-08-24 09:49:51 +02:00
|
|
|
name: Docker Image Build and Analysis
|
|
|
|
|
2024-08-24 08:01:56 +02:00
|
|
|
on:
|
|
|
|
schedule:
|
|
|
|
- cron: "0 0 * * *" # Schedule the workflow to run daily at midnight (UTC time). Adjust the time if needed.
|
|
|
|
workflow_dispatch: # Manual run trigger
|
|
|
|
inputs:
|
|
|
|
trigger-build:
|
|
|
|
description: 'Trigger a manual build and push'
|
|
|
|
default: 'true'
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-and-analyze:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
2024-08-24 08:22:37 +02:00
|
|
|
- name: Log in to Docker Hub
|
2024-08-24 08:18:49 +02:00
|
|
|
uses: docker/login-action@v3
|
2024-08-24 08:01:56 +02:00
|
|
|
with:
|
2024-08-24 08:22:37 +02:00
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
2024-08-24 08:01:56 +02:00
|
|
|
|
2024-08-24 09:49:51 +02:00
|
|
|
- name: Build Docker image
|
|
|
|
id: build-image
|
|
|
|
run: |
|
2024-08-24 09:53:30 +02:00
|
|
|
echo "Building Docker image..."
|
2024-08-24 09:49:51 +02:00
|
|
|
docker build -t my-app-image:latest .
|
2024-08-24 09:53:30 +02:00
|
|
|
echo "Docker image built successfully."
|
2024-08-24 09:49:51 +02:00
|
|
|
|
|
|
|
- name: Install Docker Scout
|
|
|
|
run: |
|
2024-08-24 09:53:30 +02:00
|
|
|
echo "Installing Docker Scout..."
|
2024-08-24 09:49:51 +02:00
|
|
|
curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s --
|
2024-08-24 09:53:30 +02:00
|
|
|
echo "Docker Scout installed successfully."
|
2024-08-24 09:49:51 +02:00
|
|
|
|
|
|
|
- name: Analyze Docker image with Docker Scout
|
|
|
|
id: analyze-image
|
|
|
|
run: |
|
2024-08-24 09:53:30 +02:00
|
|
|
echo "Analyzing Docker image with Docker Scout..."
|
|
|
|
docker scout cves my-app-image:latest > scout-results.txt
|
|
|
|
cat scout-results.txt # Print the report to the workflow logs for easy viewing
|
|
|
|
echo "Docker Scout analysis completed."
|
|
|
|
|
|
|
|
- name: Create GitHub issue comment
|
|
|
|
uses: peter-evans/create-issue-comment@v3
|
|
|
|
with:
|
|
|
|
issue-number: 1 # Replace with the issue number or use an appropriate method to identify the issue or PR
|
|
|
|
body: |
|
|
|
|
**Docker Image Build and Analysis Report**
|
|
|
|
|
|
|
|
The Docker image was built and analyzed successfully.
|
|
|
|
|
|
|
|
**Build Summary:**
|
|
|
|
- Image Tag: my-app-image:latest
|
|
|
|
|
|
|
|
**Analysis Report:**
|
|
|
|
```
|
|
|
|
$(cat scout-results.txt)
|
|
|
|
```
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|