【问题标题】:sh step in dockerfile agent running using rootless podman hangs使用无根 podman 运行的 dockerfile 代理中的 sh 步骤挂起
【发布时间】:2022-07-04 22:25:32
【问题描述】:

我正在尝试将 dockefile 代理与(无根)Podman(yum install podman-docker)一起使用,但是应该在容器中运行命令的 sh 步骤挂起。

FROM registry.access.redhat.com/ubi8/python-36:1-164
COPY requirements.txt .
RUN pip install -r requirements.txt
pipeline {
    agent {
        dockerfile true
    }
    stages {
        stage "stage", {
            steps {
                sh "echo hello"
            }
        }
    }
}

Jenkins 然后告诉(在“sh”和“进程显然从未启动”之间挂了更长的时间之后)

[Pipeline] { (Generate CryptoStore dist zip)
[Pipeline] sh
process apparently never started in /var/lib/jenkins/workspace/--%<--@tmp/durable-5572a21e
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }

设置LAUNCH_DIAGNOSTICS,它告诉

sh: /var/lib/jenkins/workspace/--%<--@2@tmp/durable-baac9648/jenkins-log.txt: Permission denied
sh: /var/lib/jenkins/workspace/--%<--@2@tmp/durable-baac9648/jenkins-result.txt.tmp: Permission denied
touch: cannot touch '/var/lib/jenkins/workspace/--%<--@2@tmp/durable-baac9648/jenkins-log.txt': Permission denied
mv: cannot stat '/var/lib/jenkins/workspace/--%<--@2@tmp/durable-baac9648/jenkins-result.txt.tmp': No such file or directory
touch: cannot touch '/var/lib/jenkins/workspace/--%<--@2@tmp/durable-baac9648/jenkins-log.txt': Permission denied
[...]

我看到 Jenkins 使用 -u 选项启动容器,该选项对应于启动容器的代理正在运行的用户,但 podman 以 root 身份安装卷。

如何解决或解决这个问题?该插件似乎没有覆盖用户的选项,向args 添加自定义-u 选项似乎没有帮助,docker run jenkins 显示然后只包含两个-u 选项,但第一个( jenkins one) 似乎被使用了...

【问题讨论】:

    标签: jenkins podman


    【解决方案1】:

    研究如何更改卷挂载的用户我发现了以下故障排除信息:Passed-in devices or files can't be accessed in rootless container (UID/GID mapping problem)

    其中描述了一些解决方法,但也包含以下提示:

    附注:使用--userns=keep-id 有时可以替代 解决方案,但它强制将常规用户的主机 UID 映射到 容器内的 UID 相同,因此它提供的灵活性低于 使用--uidmap--gidmap

    无论如何,由于 Jenkins 在这里偷走了我们的灵活性,我将 args "--userns=keep-id" 添加到我的 dockerfile 选项中,现在它工作正常。 :)

    pipeline {
        agent {
            dockerfile {
                filename 'Containerfile'
                
                // Jenkins sets the user in the container to the same one running it
                // Using (rootless) podman as docker this breaks the -v volume mounts because the user in the container is mapped to a different one on the host.
                // this options disables that mapping, so the uid inside and outside match again.
                args "--userns=keep-id"
            }
        }
        stages {
            stage "Generate CryptoStore dist zip", {
                steps {
                    sh "echo hello"
                }
            }
        }
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 2022-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多