GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.23k stars 1.4k forks source link

arm64 - fork/exec /bin/sh: exec format error #3183

Open ricardorqr opened 1 month ago

ricardorqr commented 1 month ago

Hi team

I have a Jenkins pipeline which creates a multi-architecture image using Kaniko. I'm following this tutorial: https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-multi-architecture-image.html

This is my pipeline

pipeline {
  agent {
    kubernetes {
      inheritFrom 'jenkins-kaniko-tomcat'
      yaml """
        apiVersion: v1
        kind: Pod
        metadata:
          name: kaniko-tomcat
          namespace: jenkins
        spec:
          containers:
            - name: awscli
              image: amazon/aws-cli:latest
              command:
              - sleep
              args:
              - 99d
              volumeMounts:
                - name: docker-config
                  mountPath: /kaniko/.docker
                - name: jenkins-root
                  mountPath: /tmp/workspace

            - name: kaniko
              image: gcr.io/kaniko-project/executor:debug
              #image: 495633144232.dkr.ecr.us-west-2.amazonaws.com/jenkins-agent-rico:kaniko
              imagePullPolicy: Always
              command:
              - sleep
              args:
              - 99d
              volumeMounts:
                - name: docker-config
                  mountPath: /kaniko/.docker
                - name: jenkins-root
                  mountPath: /tmp/workspace       
          restartPolicy: Never
          volumes:
            - name: docker-config
              configMap:
                name: docker-config
            - name: jenkins-root
              emptyDir: {}
      """
    }
  }

  stages {
    // Other stages...

    stage('Build image - arm64') {
      steps {
        container(name: 'kaniko') {
          sh '''
            /kaniko/executor --context `pwd` --verbosity trace \
            --destination 123456789.dkr.ecr.us-east-2.amazonaws.com/my-repo:$my-image-arm64 \
            --custom-platform linux/arm64
          '''
        }
      }
    }

    stage('Build image - amd64') {
      steps {
        container(name: 'kaniko') {
          sh '''
            cd uber-cloud-tools
            modified_string=$(echo "$VERSION" | tr '/' '-')

            /kaniko/executor --context `pwd` --verbosity debug \
            --destination 123456789.dkr.ecr.us-east-2.amazonaws.com/my-repo:$my-image-amd64 \
            --custom-platform linux/amd64
          '''
        }
      }
    }

    stage('Build image - multi-architecture') {
      steps {
        container(name: 'awscli') {
          sh '''
            aws ecr get-login-password --region us-east-2 | docker login --username AWS \
            --password-stdin 123456789.dkr.ecr.us-east-2.amazonaws.com

            docker manifest create 123456789.dkr.ecr.us-east-2.amazonaws.com/my-repo:$my-image \
            123456789.dkr.ecr.us-east-2.amazonaws.com/my-repo:$my-image-arm64 \
            123456789.dkr.ecr.us-east-2.amazonaws.com/my-repo:$my-image-amd64

            docker manifest push 123456789.dkr.ecr.us-east-2.amazonaws.com/my-repo:$my-image
          '''
        }
      }
    }

  }
}

This is my Dockerfile. As you can see it is a very simple one.

FROM amazoncorretto:8u342

RUN yum install -y procps && yum clean all

And this is the error.

 ...
 [36mINFO [0m[0032] Cmd: /bin/sh                                 
 [36mINFO [0m[0032] Args: [-c yum install -y procps && yum clean all] 
 [36mINFO [0m[0032] Running: [/bin/sh -c yum install -y procps && yum clean all] 
error building image: error building stage: failed to execute command: starting command: fork/exec /bin/sh: exec format error

It fails when it executes the line RUN yum install -y procps && yum clean all. I have other pipelines that don't have any command (RUN) to perform, so they are working. If I remove the stage Build image - arm64, the stage Build image - amd64 works. I'm also using --custom-platform. It seems this error is related to arm64. I'm not sure.

Any idea how can I silver this?

ricardorqr commented 1 month ago

I tested removing the line RUN yum install -y procps && yum clean all and the stage Build image - arm64 worked. It seems for arm64, commands are not working.

ricardorqr commented 3 weeks ago

Any idea how I can solve this problem?