gpt4 book ai didi

docker - 如何使用serverspec测试Jenkins是否在jenkins docker容器中运行?

转载 作者:行者123 更新时间:2023-12-02 18:24:53 25 4
gpt4 key购买 nike

我试图证明Jenkins在由官方docker hub jenkins镜像构建的容器中运行。

require "serverspec"
require "docker"

describe "Dockerfile" do
before(:all) do
image = Docker::Image.build_from_dir('./images/jenkins')

set :os, family: :debian
set :backend, :docker
set :docker_image, image.id
end

describe process("java") do
it { should be_running }
end
end

我得到以下结果:
Failures:

1) Dockerfile Process "java" should be running
Failure/Error: it { should be_running }
expected Process "java" to be running

# ./spec_jenkins.rb:24:in `block (3 levels) in <top (required)>'

我是否误解是针对从生成的镜像实例化的容器运行测试?

最佳答案

Jenkins (Jenkins)官方图像定义了一个ENTRYPOINT而不是CMD

但是,specinfra查找CMD,如果找不到,则使用/bin/sh

IOW,specinfra不运行Jenkins。我的测试失败的原因。

通过指定正确的docker_container_create_optionsspecinfra也可以启动Jenkins并通过测试。

工作代码:

require "serverspec"
require "docker"

describe "Dockerfile" do
before(:all) do
image = Docker::Image.build_from_dir('./images/jenkins')

set :os, family: :debian
set :backend, :docker
set :docker_image, image.id
set :docker_container_create_options, {'Cmd' => ['/usr/local/bin/jenkins.sh']}
end

describe process("java") do
it { should be_running }
end
end

关于docker - 如何使用serverspec测试Jenkins是否在jenkins docker容器中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30698786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com