copacetic icon indicating copy to clipboard operation
copacetic copied to clipboard

[QUESTION] Error apt upgradable

Open rodrigoaraujo-rfxtech opened this issue 1 year ago • 10 comments

What is your question?

I'm using copa to check an image for vulnerabilities with the following command:

copa patch -i $trivyImage

But it always stops at the error below:

#10 sh -c apt list --upgradable 2>/dev/null | grep -q upgradable || exit 1 #10 ERROR: process "sh -c apt list --upgradable 2>/dev/null | grep -q upgradable || exit 1" did not complete successfully: exit code: 1 Error: process "sh -c apt list --upgradable 2>/dev/null | grep -q upgradable || exit 1" did not complete successfully: exit code: 1

rodrigoaraujo-rfxtech avatar Oct 08 '24 14:10 rodrigoaraujo-rfxtech

Hi @rodrigoasf9 it looks like your image does not have any outdated packages. Would you be able to share the image you used in order to confirm?

ashnamehrotra avatar Oct 08 '24 15:10 ashnamehrotra

I expected that to be the case, but I would like to know if there is any way to avoid this type of error in a pipeline?

rodrigoaraujo-rfxtech avatar Oct 08 '24 17:10 rodrigoaraujo-rfxtech

@rodrigoasf9 to ignore errors you can run copa with the "--ignore-errors" flag

ashnamehrotra avatar Oct 08 '24 17:10 ashnamehrotra

@ashnamehrotra hello,

I have the same problem in my pipeline, some work, others don't work and all that don't work have the same error message and I'm already using the --igonre-errors parameter, I'll share the pipeline yml:

jobs:      
  - job: Run_Trivy_ACR_and_Git
    displayName: Run Trivy ACR and Git
    pool:
      vmImage: 'ubuntu-latest'
    
    steps:
     - task: Docker@2
       inputs:
	 command: 'build'
	 containerRegistry: <my registry>
	 repository: <my repos>
	 Dockerfile: <my dockerfile>
	 buildContext: **
	 tags: $(Build.BuildId)
       displayName: 'Docker build'

     - task: Docker@2
       inputs:
	 command: 'push'
	 containerRegistry: <my registry>
	 repository: <my repos>
	 tags: $(Build.BuildId)
        displayName: 'Docker push'

      - task: Docker@2
        displayName: Login docker
        inputs:
          containerRegistry: <my registry>
          command: 'login'
          addBaseImageData: true
          addPipelineData: true
      
      - task: trivy@1
        displayName: Run Trivy on the Repos
        inputs:
          version: 'v0.54.1'
          docker: false
          path: '$(System.DefaultWorkingDirectory)'
          severities: 'CRITICAL,HIGH'
          exitCode: '0'
          ignoreUnfixed: true
          
      - task: trivy@1
        displayName: Run Trivy in ACR
        inputs:
          version: 'v0.54.1'
          docker: false
          loginDockerConfig: true
          image: <my image>
          severities: 'CRITICAL,HIGH'
          ignoreUnfixed: true
          exitCode: '0'
      
      - script: |
          sudo apt-get update
          sudo apt-get install -y wget
          wget https://github.com/project-copacetic/copacetic/releases/download/v0.8.0/copa_0.8.0_linux_amd64.tar.gz
          tar -xvzf copa_0.8.0_linux_amd64.tar.gz
          mv copa /usr/local/bin/copa
          sudo chmod +x /usr/local/bin/copa
        displayName: 'Download and Install COPA Cetic Binary'
      
      - script: |
          export DOCKER_BUILDKIT=1
          mkdir -p ~/.docker/cli-plugins
          curl -SL https://github.com/docker/buildx/releases/download/v0.17.1/buildx-v0.17.1.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx
          chmod +x ~/.docker/cli-plugins/docker-buildx
          docker buildx create --use
          docker buildx inspect --bootstrap
        displayName: 'Setup BuildKit and Buildx v0.17.1'


      - task: Bash@3
        displayName: 'Run COPA Cetic for vulnerability correction'
        env: 
          trivyImage: <my image>
        inputs:
          targetType: 'inline'
          script: |
            echo "Starting Update/Upgrade packages"
            sudo apt-get update && sudo apt-get upgrade -y || true
            echo "Starting COPA Cetic..."
            copa patch -i $trivyImage --ignore-errors

      - task: Docker@2
        displayName: 'Push Patched Docker Image to ACR'
        inputs:
          command: 'push'
          repository: <my repos>
          tags: |
            $(imageTag)-patched
          containerRegistry: <my registry>
  

When you reach the Run COPA Cetic for vulnerability correction step, the error occurs. Is there anything else that needs to be done?

evertonlsouza avatar Oct 09 '24 19:10 evertonlsouza

@evertonlsouza is there a reason you are running sudo apt-get update && sudo apt-get upgrade -y || true before the copa patch? would you also be able to share the image you are using to see if we can reproduce?

ashnamehrotra avatar Oct 10 '24 19:10 ashnamehrotra

Hi @ashnamehrotra

I am using sudo apt-get update && sudo apt-get upgrade -y || true to do some tests to see if it worked but the error persisted, there is no specific reason.

Regarding the images, I tested with these:

FROM node:18-bookworm-slim AS packages

FROM node:18-bookworm-slim AS build

FROM node:18-bookworm-slim

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

evertonlsouza avatar Oct 10 '24 19:10 evertonlsouza

@rodrigoasf9 @evertonlsouza you are correct, we error out when there are no upgradable packages since we do not want to create a patched image tag with no changes. Currently, --ignore-errors does not ignore this specific case, but we will add support for that!

ashnamehrotra avatar Oct 11 '24 20:10 ashnamehrotra

@ashnamehrotra thank you!

evertonlsouza avatar Oct 14 '24 13:10 evertonlsouza

@ashnamehrotra We’re eagerly awaiting that feature, but I’d also like to ask if you suggest any workarounds for these cases. In our experience, some images successfully go through the Copa patching process, while others don’t, returning the type of error we previously shared.

rodrigoaraujo-rfxtech avatar Oct 15 '24 17:10 rodrigoaraujo-rfxtech

@rodrigoasf9 there currently aren't any workaround within copa, however, you can check for vulnerabilities before choosing to patch the image similar to how we do in this example for the copa action: https://github.com/project-copacetic/copa-action/blob/00f0ef529529d7a7d49a1f3b9f5f5cf54ba2235e/.github/workflows/patch.yaml#L1-L81. This way, we will not patch an image if it is already up to date and will not encounter that error. You can also check for/catch the specific error you are seeing in this case.

ashnamehrotra avatar Oct 15 '24 18:10 ashnamehrotra

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 03 '25 20:07 github-actions[bot]

Could we perhaps get a different exit code than 1 if there are no packages to upgrade?

In GitLab CI, I either have to:

  • Fail the pipeline unnecessarily when images are already patched, or
  • Ignore all exit code 1 errors and potentially miss real failures

Would it be possible to use a different exit code for "no updates available"? That way CI systems could handle it properly:

allow_failure:
  exit_codes: [42]  # Allow "no updates available"

fazdamoa avatar Jul 09 '25 10:07 fazdamoa

@fazdamoa Would having exit code [0] for success instead of having a failure remove your issue? Or would you rather have a whole new exit code.

leodewang avatar Jul 23 '25 22:07 leodewang

Yes, that would remove the issue, and be preferable.

On Wed, 23 Jul 2025, 23:49 Leo Wang, @.***> wrote:

leodewang left a comment (project-copacetic/copacetic#802) https://github.com/project-copacetic/copacetic/issues/802#issuecomment-3110836019

@fazdamoa https://github.com/fazdamoa Would having exit code [0] for success instead of having a failure remove your issue? Or would you rather have a whole new exit code.

— Reply to this email directly, view it on GitHub https://github.com/project-copacetic/copacetic/issues/802#issuecomment-3110836019, or unsubscribe https://github.com/notifications/unsubscribe-auth/AITGEFLOYY4LBFSP6CI6RML3KAGPJAVCNFSM6AAAAABPSKMCXKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCMJQHAZTMMBRHE . You are receiving this because you were mentioned.Message ID: @.***>

fazdamoa avatar Jul 24 '25 05:07 fazdamoa

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 23 '25 03:09 github-actions[bot]