Added copa to the images build#247
Draft
bluvulture wants to merge 14 commits into
Draft
Conversation
Changed publishing process to publish only patched images
Contributor
There was a problem hiding this comment.
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
+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" |
| -p 127.0.0.1:8888:8888/tcp \ | ||
| --name buildkitd \ | ||
| --entrypoint buildkitd \ | ||
| moby/buildkit:latest \ |
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 |
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" |
| 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//') |
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
+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
+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 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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request updates the
release.ymlworkflow 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:
Build environment enhancements:
Publishing and workflow behavior:
Publishing control:
publishinput is changed fromtruetofalse, making image publishing opt-in for manual workflow dispatches.Image management and cleanup:
Other workflow refinements:
apt-get updatecall from the build step, as it is now handled during tool installation.