使用RSpectesting多个Docker镜像
免责声明:对ruby和rspec来说,这是非常新的
我一直在试图build立一个Docker镜像作为我们不同项目的基础镜像的私人回购。 我们也试图将testing多个docker图像作为testing套件的一部分。
我们虽然有rspec
奇怪的问题,它似乎像testing运行在错误的docker机器上。
目前,我们有两个docker图像,每个在一个单独的文件夹
. ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── Jenkinsfile ├── README.md ├── Rakefile ├── nodejs │ ├── 7.0 │ │ ├── Dockerfile │ │ ├── README.md │ │ └── spec │ │ └── image_spec.rb │ └── README.md ├── python │ ├── 2.7 │ │ ├── Dockerfile │ │ ├── README.md │ │ ├── docker-entrypoint.sh │ │ ├── requirements.txt │ │ └── spec │ │ └── image_spec.rb │ └── README.md └── spec └── spec_helper.rb
这基本上是我们目前使用的结构,我们的spec/spec_helper.rb
使用默认/简单
require 'serverspec' require 'docker' RSpec.configure do |config| # Use color in STDOUT config.color = true # Use color not only in STDOUT but also in pagers and files config.tty = true # Use the specified formatter config.formatter = :documentation # :progress, :html, :textmate end
这是我们正在使用的Rakefile
内容
require 'rake' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:rspec) do |t| t.pattern = Dir.glob('*/*/spec/*_spec.rb') t.rspec_opts = '--format documentation --require spec_helper --color' end task :default => :spec
我们面临的问题是,当我们运行bundle exec rake rspec
, python/2.7/spec_image.rb
testing失败,因为我们确信它们在nodejs/7.0
上运行。 而当我们运行bundle exec rspec python/2.7/spec/image_spec.rb
它会成功运行。
这里也是python/2.7
image_spec.rb
样子
require 'serverspec' require 'docker' DOCKER_FOLDER = "python/2.7" describe "Python/2.7 Specs" do before :all do add_simplejson_to_requirements image = Docker::Image.build_from_dir(DOCKER_FOLDER, ARG: 'requirements.txt') set :path, '/usr/local/bin:$PATH' set :os, family: :alpine set :backend, :docker set :docker_image, image.id end #test for python version 2.7 it 'has python 2.7 installed' do expect(command('python -c "import sys; print(sys.version_info[:])"').stdout).to include\ '2, 7' end it 'installs requirements.txt given as --build-arg' do expect(command('pip install simplejson==3.6.3').stdout).to include\ 'Requirement already satisfied' end end
有人可以指出我们正确的方向吗?
谢谢