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

时间:2015-06-07 21:49:16

标签: docker serverspec

我正在努力证明Jenkins正在使用官方码头工作室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)>'

我是否误解了测试是针对从构建的映像实例化的容器运行的?

1 个答案:

答案 0 :(得分:2)

官方Jenkins图像定义了ENTRYPOINT而不是CMD

但是,specinfra会查找CMD并使用/bin/sh,如果找不到。{/ p>

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