Jenkins Kubernetes 插件不执行 Docker 图像的入口点
Jenkins Kubernetes Plugin doesn't executre entrypoint of Docker image
一般来说,我对 Jenkins Kubernetes 插件和 Kubernetes 还很陌生 - https://github.com/jenkinsci/kubernetes-plugin
我想在我的 CI 中使用 E2E 测试设置插件。
在我的 Jenkinsfile
中,我有一个 podTemplate
,其外观和使用如下:
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"
}
}
}
}
}
在构建图像的 Dockerfile
中,我添加了一个 ENTRYPOINT
ENTRYPOINT ["bash", "./docker-entrypoint.sh"]
不过好像不是kubernetes插件执行的
我是不是漏掉了什么?
根据 Define a Command and Arguments for a Container 文档:
The command and arguments that you define in the configuration file
override the default command and arguments provided by the container
image.
This table总结了Docker和Kubernetes使用的字段名:
| Docker field name | K8s field name |
|------------------:|:--------------:|
| ENTRYPOINT | command |
| CMD | args |
定义 command
意味着忽略您的 Docker 文件 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.
因此,您需要将广告连播模板中的 command
替换为 args
,这将保留您的 Docker 文件 ENTRYPOINT
(相当于 Docker文件 CMD
).
一般来说,我对 Jenkins Kubernetes 插件和 Kubernetes 还很陌生 - https://github.com/jenkinsci/kubernetes-plugin
我想在我的 CI 中使用 E2E 测试设置插件。
在我的 Jenkinsfile
中,我有一个 podTemplate
,其外观和使用如下:
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"
}
}
}
}
}
在构建图像的 Dockerfile
中,我添加了一个 ENTRYPOINT
ENTRYPOINT ["bash", "./docker-entrypoint.sh"]
不过好像不是kubernetes插件执行的
我是不是漏掉了什么?
根据 Define a Command and Arguments for a Container 文档:
The command and arguments that you define in the configuration file override the default command and arguments provided by the container image.
This table总结了Docker和Kubernetes使用的字段名:
| Docker field name | K8s field name |
|------------------:|:--------------:|
| ENTRYPOINT | command |
| CMD | args |
定义 command
意味着忽略您的 Docker 文件 ENTRYPOINT
:
When you override the default
ENTRYPOINT
andCMD
, these rules apply:
- If you supply a
command
but noargs
for a Container, only the suppliedcommand
is used. The defaultENTRYPOINT
and the defaultCMD
defined in the Docker image are ignored.- If you supply only
args
for a Container, the defaultENTRYPOINT
defined in the Docker image is run with theargs
that you supplied.
因此,您需要将广告连播模板中的 command
替换为 args
,这将保留您的 Docker 文件 ENTRYPOINT
(相当于 Docker文件 CMD
).