Skip to content

Added copa to the images build#247

Draft
bluvulture wants to merge 11 commits into
5.xfrom
image_copa
Draft

Added copa to the images build#247
bluvulture wants to merge 11 commits into
5.xfrom
image_copa

Conversation

@bluvulture
Copy link
Copy Markdown
Contributor

@bluvulture bluvulture commented May 26, 2026

This pull request updates the release.yml workflow to add automated vulnerability scanning and patching to the Docker image build process, and refines how images are published and cleaned up. The main improvements are the integration of Trivy for vulnerability scanning, Copa for patching OS-level vulnerabilities, and enhanced image management during the build and publish steps.

Security automation and image build improvements:

  • Vulnerability scanning and patching:

    • Trivy is now installed and used to scan built Docker images for OS-level vulnerabilities, and Copa is used to automatically patch any fixable vulnerabilities before publishing. [1] [2]
    • If vulnerabilities are patched, the original image is replaced with the patched version and all tags are applied to the updated image.
  • Build environment enhancements:

    • The workflow now installs Trivy and Copa as part of the setup, and starts a BuildKit daemon in a container to support image patching.
    • The BuildKit daemon is reliably stopped at the end of the workflow to ensure cleanup.

Publishing and workflow behavior:

  • Publishing control:

    • The default for the publish input is changed from true to false, making image publishing opt-in for manual workflow dispatches.
  • Image management and cleanup:

    • After building and optionally patching images, all tags are applied, images are pushed if publishing is enabled, and then all images are removed locally to save disk space. [1] [2]

Other workflow refinements:

  • Removed a redundant apt-get update call from the build step, as it is now handled during tool installation.

Changed publishing process to publish only patched images
Copilot AI review requested due to automatic review settings May 26, 2026 09:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Docker image release workflow to introduce an automated “scan + patch” stage (Trivy + Copa) before pushing images to registries, aiming to publish images after OS-level vulnerability remediation.

Changes:

  • Defaults manual (workflow_dispatch) runs to not publish images unless explicitly enabled.
  • Installs Trivy and Copa in the workflow, and starts a BuildKit daemon to support Copa patching.
  • Changes the build/publish flow to build locally, scan + patch the image, then tag and push all tags manually.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +60 to +66
set -eux
# Install Trivy
sudo apt-get update
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
Comment on lines +63 to +71
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy

# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
Comment thread .github/workflows/release.yml Outdated
-p 127.0.0.1:8888:8888/tcp \
--name buildkitd \
--entrypoint buildkitd \
moby/buildkit:latest \
Comment on lines +178 to +186
copa patch -i "${IMAGE_NAME}:${TAG}" \
-r /tmp/trivy-report.json \
-t "${TAG}-patched" \
-a tcp://127.0.0.1:8888

# Verify the patched image exists
if ! docker image inspect "${IMAGE_NAME}:${TAG}-patched" > /dev/null 2>&1; then
echo "::error::Patched image not found for ${IMAGE_NAME}:${TAG}"
exit 1
Comment on lines +69 to +74
# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
tar -xzf copa.tar.gz copa
sudo mv copa /usr/local/bin/copa
rm copa.tar.gz
Copilot AI review requested due to automatic review settings May 26, 2026 13:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment on lines +60 to +65
set -eux
# Install Trivy
sudo apt-get update
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
Comment on lines +62 to +71
sudo apt-get update
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy

# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
Comment thread .github/workflows/release.yml Outdated
sudo apt-get install -y trivy

# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
Copilot AI review requested due to automatic review settings May 26, 2026 14:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Comment on lines +62 to +71
sudo apt-get update
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy

# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
Comment on lines +69 to +72
# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
tar -xzf copa.tar.gz copa
Comment on lines +71 to +74
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
tar -xzf copa.tar.gz copa
sudo mv copa /usr/local/bin/copa
rm copa.tar.gz
Comment on lines +86 to +93
for i in $(seq 1 60); do
if docker exec buildkitd buildctl debug workers >/dev/null 2>&1; then
echo "BuildKit is ready"
break
fi
if [ "$i" -eq 60 ]; then
echo "::error::BuildKit failed to start within 60 seconds"
exit 1
Comment on lines 6 to 10
publish:
description: 'Publish images to registries'
required: false
default: true
default: false
type: boolean
Copilot AI review requested due to automatic review settings May 26, 2026 14:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines +186 to +190
-t "${TAG}-patched" \
-a tcp://127.0.0.1:8888

# Verify the patched image exists
if ! docker image inspect "${IMAGE_NAME}:${TAG}-patched" > /dev/null 2>&1; then
Comment on lines +207 to +210
echo "Running post-patch scan (fail on ${FAIL_SEVERITY}+)"
trivy image --vuln-type os --ignore-unfixed \
--exit-code 1 \
--severity "$FAIL_SEVERITY" \
Comment on lines +74 to +76
# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
Comment on lines +68 to +76
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy

# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
Copilot AI review requested due to automatic review settings May 26, 2026 15:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines +184 to +190
copa patch -i "${IMAGE_NAME}:${TAG}" \
-r /tmp/trivy-report.json \
-t "${TAG}-patched" \
-a tcp://127.0.0.1:8888

# Verify the patched image exists
if ! docker image inspect "${IMAGE_NAME}:${TAG}-patched" > /dev/null 2>&1; then
Comment on lines +67 to +76
sudo apt-get update
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy

# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
fail_on_severity:
description: 'Fail build if post-patch CVEs remain at this severity (CRITICAL, HIGH, MEDIUM, LOW, or NONE to disable)'
required: false
default: 'CRITICAL,HIGH'
Comment on lines +74 to +79
# Install Copa
COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
tar -xzf copa.tar.gz copa
sudo mv copa /usr/local/bin/copa
rm copa.tar.gz
Copilot AI review requested due to automatic review settings May 26, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 6 comments.


docker build --output "type=image,push=$PUSH" \
# Build and load image locally
docker build --load \
VERSION_OVERRIDE: "${{ matrix.build.version-override }}"
ARCH_TAG: ${{ contains(matrix.runner, 'arm') && 'arm64' || 'amd64' }}
PUSH: ${{ github.event_name != 'workflow_dispatch' || inputs.publish }}
FAIL_ON_SEVERITY: ${{ inputs.fail_on_severity || 'CRITICAL' }}
default: false
type: boolean
fail_on_severity:
description: 'Fail build if post-patch CVEs remain at this severity (CRITICAL, HIGH, MEDIUM, LOW, or NONE to disable)'
Comment on lines +74 to +79
# Install Copa
COPA_VERSION="0.14.1"
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz"
tar -xzf copa.tar.gz copa
sudo mv copa /usr/local/bin/copa
rm copa.tar.gz
Comment on lines +67 to +72
sudo apt-get update
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy
Comment on lines +180 to +184
trivy image --pkg-types os --ignore-unfixed --format json \
-o /tmp/trivy-report.json "${IMAGE_NAME}:${TAG}"

if [ -s /tmp/trivy-report.json ] && jq -e '.Results[]? | select(.Vulnerabilities != null and (.Vulnerabilities | length > 0))' /tmp/trivy-report.json > /dev/null 2>&1; then
copa patch -i "${IMAGE_NAME}:${TAG}" \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants