简体   繁体   中英

Jenkins Kubernetes Plugin doesn't executre entrypoint of Docker image

I'm fairly new into Jenkins Kubernetes Plugin and Kubernetes in general - https://github.com/jenkinsci/kubernetes-plugin

I want to use the plugin for E2E tests setup inside my CI.

Inside my Jenkinsfile I have a podTemplate which looks and used as follows:

def podTemplate = """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: website
    image: ${WEBSITE_INTEGRATION_IMAGE_PATH}
    command:
      - cat
    tty: true
    ports:
     - containerPort: 3000
  - name: cypress
    resources:
      requests:
        memory: 2Gi
      limit:
        memory: 4Gi
    image: ${CYPRESS_IMAGE_PATH}
    command:
      - cat
    tty: true
"""

pipeline {
  agent {
    label 'docker'
  }
  stages {
    stage('Prepare') {
      steps {
        timeout(time: 15) {
          script {
            ci_machine = docker.build("${WEBSITE_IMAGE_PATH}")
          }
        }
      }
    }

    stage('Build') {
      steps {
        timeout(time: 15) {
          script {
            ci_machine.inside("-u root") {
              sh "yarn build"
            }
          }
        }
      }

      post {
        success {
          timeout(time: 15) {
            script {
              docker.withRegistry("https://${REGISTRY}", REGISTRY_CREDENTIALS) {
                integrationImage = docker.build("${WEBSITE_INTEGRATION_IMAGE_PATH}")
                integrationImage.push()
              }
            }
          }
        }
      }
    }

    stage('Browser Tests') {
      agent {
        kubernetes {
          label "${KUBERNETES_LABEL}"
          yaml podTemplate
        }
      }
      steps {
        timeout(time: 5, unit: 'MINUTES') {
          container("website") {
            sh "yarn start"
          }

          container("cypress") {
            sh "yarn test:e2e"
          }
        }
      }
  }
}


In Dockerfile that builds an image I added an ENTRYPOINT

ENTRYPOINT ["bash", "./docker-entrypoint.sh"]

However it seems that it's not executed by the kubernetes plugin.

Am I missing something?

As per Define a Command and Arguments for a Container docs:

The command and arguments that you define in the configuration file override the default command and arguments provided by the container image.

This table summarizes the field names used by Docker and Kubernetes:

| Docker field name | K8s field name |
|------------------:|:--------------:|
|    ENTRYPOINT     |     command    |
|       CMD         |      args      |

Defining a command implies ignoring your Dockerfile ENTRYPOINT :

When you override the default ENTRYPOINT and CMD , these rules apply:

  • If you supply a command but no args for a Container, only the supplied command is used. The default ENTRYPOINT and the default CMD defined in the Docker image are ignored.
  • If you supply only args for a Container, the default ENTRYPOINT defined in the Docker image is run with the args that you supplied.

So you need to replace the command in your pod template by args , which will preserve your Dockerfile ENTRYPOINT (acting equivalent to a Dockerfile CMD ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM