Skip to content

Added copa to the images build#247

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

Added copa to the images build#247
bluvulture wants to merge 14 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 thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
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 thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
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 thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
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 thread .github/workflows/release.yml Outdated
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
Comment thread .github/workflows/release.yml Outdated
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 thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml
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 thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
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 thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
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.

Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml
Copilot AI review requested due to automatic review settings May 27, 2026 08:31
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 3 out of 3 changed files in this pull request and generated 7 comments.

Comment thread testimage.sh Outdated
Comment on lines +1 to +128
#!/bin/bash

set -euo pipefail

REF="origin/1.x"
IMAGE_NAME="pimcore/pimcore"
LOCAL_TAG="php8.1-v1-dev"
WORKFLOW_TAG="php8.1-v1-dev-amd64"
PATCHED_TAG="${LOCAL_TAG}-copa"
PHP_VERSION="8.1"
DEBIAN_VERSION="bullseye"
TARGET="pimcore_php_fpm"
ARCH="amd64"
BUILDKIT_CONTAINER="buildkitd-copa-local"
WORKDIR="$(mktemp -d)"

for bin in git tar docker trivy jq copa diff sort mktemp; do
command -v "$bin" >/dev/null 2>&1 || {
echo "Missing required command: $bin" >&2
exit 1
}
done

cleanup() {
docker rm -f "$BUILDKIT_CONTAINER" >/dev/null 2>&1 || true
rm -rf "$WORKDIR"
}
trap cleanup EXIT

echo "== Fetch 2.x and export build context =="
git fetch origin 2.x
git archive "$REF" | tar -x -C "$WORKDIR"

echo
echo "== Build original image from 2.x =="
docker build --load \
--provenance=false \
--platform "linux/${ARCH}" \
--target "${TARGET}" \
--build-arg PHP_VERSION="${PHP_VERSION}" \
--build-arg DEBIAN_VERSION="${DEBIAN_VERSION}" \
--tag "${IMAGE_NAME}:${WORKFLOW_TAG}" \
--tag "${IMAGE_NAME}:${LOCAL_TAG}" \
"$WORKDIR"

echo
echo "== Trivy scan without Copa =="
trivy image --pkg-types os --ignore-unfixed \
--format table \
-o /tmp/trivy-before.txt \
"${IMAGE_NAME}:${LOCAL_TAG}" || true
cat /tmp/trivy-before.txt

echo
echo "== Save package inventory before patch =="
docker run --rm "${IMAGE_NAME}:${LOCAL_TAG}" \
dpkg-query -W -f='${Package} ${Version}\n' | sort > /tmp/pkg-before.txt

echo
echo "== Export Trivy JSON report =="
trivy image --pkg-types os --ignore-unfixed \
--format json \
-o /tmp/trivy-report.json \
"${IMAGE_NAME}:${LOCAL_TAG}"

if jq -e '.Results[]? | select(.Vulnerabilities != null and (.Vulnerabilities | length > 0))' /tmp/trivy-report.json >/dev/null 2>&1; then
echo
echo "== Start BuildKit for Copa =="
docker rm -f "$BUILDKIT_CONTAINER" >/dev/null 2>&1 || true
docker run --detach --rm --privileged \
-p 127.0.0.1:8889:8888/tcp \
--name "$BUILDKIT_CONTAINER" \
--entrypoint buildkitd \
moby/buildkit:v0.30.0 \
--addr tcp://0.0.0.0:8888 >/dev/null

# for i in $(seq 1 60); do
# if docker exec "$BUILDKIT_CONTAINER" buildctl --addr tcp://127.0.0.1:8889 debug workers >/dev/null 2>&1; then
# break
# fi
# if [ "$i" -eq 60 ]; then
# echo "BuildKit failed to start within 60 seconds" >&2
# exit 1
# fi
# sleep 1
# done

echo
echo "== Patch image with Copa =="
copa patch \
-i "${IMAGE_NAME}:${LOCAL_TAG}" \
-r /tmp/trivy-report.json \
-t "${PATCHED_TAG}" \
-a tcp://127.0.0.1:8889

echo
echo "== Trivy scan with Copa =="
trivy image --pkg-types os --ignore-unfixed \
--format table \
-o /tmp/trivy-after.txt \
"${IMAGE_NAME}:${PATCHED_TAG}" || true
cat /tmp/trivy-after.txt

echo
echo "== Save package inventory after patch =="
docker run --rm "${IMAGE_NAME}:${PATCHED_TAG}" \
dpkg-query -W -f='${Package} ${Version}\n' | sort > /tmp/pkg-after.txt

echo
echo "== Package diff: original vs patched =="
diff -u /tmp/pkg-before.txt /tmp/pkg-after.txt || true

echo
echo "== Image IDs =="
docker image inspect "${IMAGE_NAME}:${LOCAL_TAG}" --format 'original {{.RepoTags}} {{.Id}}'
docker image inspect "${IMAGE_NAME}:${PATCHED_TAG}" --format 'patched {{.RepoTags}} {{.Id}}'
else
echo
echo "No OS vulnerabilities reported by Trivy. Copa patch step skipped."
fi

echo
echo "Artifacts written to:"
echo " /tmp/trivy-before.txt"
echo " /tmp/trivy-report.json"
echo " /tmp/pkg-before.txt"
echo " /tmp/trivy-after.txt"
echo " /tmp/pkg-after.txt" No newline at end of file
Comment thread testimage.sh Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
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 thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
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 +239 to +253
trivy image --pkg-types os --ignore-unfixed \
--exit-code 1 \
--severity "$FAIL_SEVERITY" \
"${IMAGE_NAME}:${TAG}"

# Attach scan results to GitHub Actions job summary
{
echo "## Trivy Scan: ${IMAGE_NAME}:${TAG}"
echo ""
echo "### OS Vulnerabilities (${FAIL_SEVERITY}+)"
echo '```'
cat /tmp/trivy-os-${TAG}.txt 2>/dev/null || echo "No results"
echo '```'
echo ""
} >> "$GITHUB_STEP_SUMMARY"
Comment on lines +94 to +99
docker run --detach --rm --privileged \
-p 127.0.0.1:8888:8888/tcp \
--name buildkitd \
--entrypoint buildkitd \
moby/buildkit:v${{ env.BUILDKIT_VERSION }} \
--addr tcp://0.0.0.0:8888
Comment on lines +218 to +242
FAIL_SEVERITY="$FAIL_ON_SEVERITY"
if [ "$FAIL_SEVERITY" != "NONE" ]; then
echo "Running post-patch scan (fail on ${FAIL_SEVERITY}+)"

# Get the image hash for report naming
IMAGE_HASH=$(docker image inspect "${IMAGE_NAME}:${TAG}" --format '{{.Id}}' | sed 's/sha256://' | head -c 12)

trivy image --pkg-types os --ignore-unfixed \
--severity "$FAIL_SEVERITY" \
--format table \
-o /tmp/trivy-os-${TAG}.txt \
"${IMAGE_NAME}:${TAG}" || true

# Save report with image hash for artifact upload
trivy image --pkg-types os --ignore-unfixed \
--severity "$FAIL_SEVERITY" \
--format json \
-o "trivy-reports/${TAG}_${IMAGE_HASH}.json" \
"${IMAGE_NAME}:${TAG}" || true
cp /tmp/trivy-os-${TAG}.txt "trivy-reports/${TAG}_${IMAGE_HASH}.txt" 2>/dev/null || true

trivy image --pkg-types os --ignore-unfixed \
--exit-code 1 \
--severity "$FAIL_SEVERITY" \
"${IMAGE_NAME}:${TAG}"
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
@bluvulture bluvulture requested a review from brusch May 27, 2026 14:25
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.

3 participants