Skip to content
Snippets Groups Projects
Commit 05678c90 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch '2598-add-docker-tests' into 'master'

Add specs against docker related tasks

Closes #2598

See merge request !1758
parents 7b37327c 473cc453
No related branches found
No related tags found
1 merge request!1758Add specs against docker related tasks
Loading
Loading
@@ -138,7 +138,8 @@ class Build
def tag_triggered_qa
# For triggered builds, we need the QA image's tag to match the docker
# tag. So, we are retagging the image.
DockerOperations.tag("gitlab/gitlab-qa", "#{edition}-latest", "#{edition}-#{ENV['IMAGE_TAG']}") if ENV['IMAGE_TAG'] && !ENV['IMAGE_TAG'].empty?
edition = package.gsub("gitlab-", "").strip # 'ee' or 'ce'
DockerOperations.tag("gitlab/gitlab-qa", "gitlab/gitlab-qa", "#{edition}-latest", "#{edition}-#{ENV['IMAGE_TAG']}") if ENV['IMAGE_TAG'] && !ENV['IMAGE_TAG'].empty?
end
 
private
Loading
Loading
# There is nothing currently available that we can test. Need to figure out how
# to imitate calls to docker using Chefspec and then test if docker-api gem is
# working correctly.
require 'chef_helper'
describe 'docker', type: :rake do
before :all do
Rake.application.rake_require 'gitlab/tasks/docker_tasks'
end
describe 'docker:build:image' do
before do
Rake::Task['docker:build:image'].reenable
allow(ENV).to receive(:[]).and_call_original
end
it 'calls build command with correct parameters' do
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('dev.gitlab.org:5005/gitlab/omnibus-gitlab')
allow(Build).to receive(:package).and_return('gitlab-ce')
allow(Build).to receive(:write_release_file).and_return(true)
allow(File).to receive(:expand_path).and_return('/tmp/omnibus-gitlab/lib/gitlab/tasks/docker_tasks.rake')
allow(DockerOperations).to receive(:build).and_call_original
expect(DockerOperations).to receive(:build).with("/tmp/omnibus-gitlab/docker", "dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ce", "latest")
expect(Docker::Image).to receive(:build_from_dir).with("/tmp/omnibus-gitlab/docker", { t: "dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ce:latest", pull: true })
Rake::Task['docker:build:image'].invoke
end
end
describe 'docker:pull:staging' do
before do
Rake::Task['docker:pull:staging'].reenable
allow(ENV).to receive(:[]).and_call_original
end
it 'pulls in correct image' do
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('dev.gitlab.org:5005/gitlab/omnibus-gitlab')
allow(Build).to receive(:package).and_return('gitlab-ce')
allow(Build).to receive(:docker_tag).and_return('9.0.0')
allow(DockerOperations).to receive(:authenticate).and_return(true)
expect(Docker::Image).to receive(:create).with('fromImage' => 'dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ce:9.0.0')
Rake::Task['docker:pull:staging'].invoke
end
end
describe 'docker:push' do
let(:dummy_image) { Docker::Image.new(Docker::Connection.new("test", {}), "id" => "test") }
let(:dummy_creds) { { username: "test", password: "test" } }
before do
Rake::Task['docker:push:staging'].reenable
Rake::Task['docker:push:stable'].reenable
Rake::Task['docker:push:nightly'].reenable
Rake::Task['docker:push:rc'].reenable
Rake::Task['docker:push:latest'].reenable
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('dev.gitlab.org:5005/gitlab/omnibus-gitlab')
allow(Build).to receive(:package).and_return('gitlab-ce')
allow(Build).to receive(:docker_tag).and_return('9.0.0')
allow(DockerOperations).to receive(:authenticate).and_return(true)
allow(Docker::Image).to receive(:get).and_return(dummy_image)
allow(Docker).to receive(:creds).and_return(dummy_creds)
allow(dummy_image).to receive(:tag).and_return(true)
end
it 'pushes to staging correctly' do
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ce:9.0.0')
Rake::Task['docker:push:staging'].invoke
end
it 'pushes nightly images correctly' do
allow(Build).to receive(:add_nightly_tag?).and_return(true)
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'gitlab/gitlab-ce:nightly')
Rake::Task['docker:push:nightly'].invoke
end
it 'pushes latest images correctly' do
allow(Build).to receive(:add_latest_tag?).and_return(true)
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'gitlab/gitlab-ce:latest')
Rake::Task['docker:push:latest'].invoke
end
it 'pushes rc images correctly' do
allow(Build).to receive(:add_rc_tag?).and_return(true)
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'gitlab/gitlab-ce:rc')
Rake::Task['docker:push:rc'].invoke
end
it 'pushes triggered images correctly' do
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('registry.gitlab.com/gitlab-org/omnibus-gitlab')
allow(ENV).to receive(:[]).with("DOCKER_TAG").and_return("omnibus-12345")
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'registry.gitlab.com/gitlab-org/omnibus-gitlab/gitlab-ce:omnibus-12345')
Rake::Task['docker:push:triggered'].invoke
end
end
describe 'docker:build:qa' do
let(:dummy_image) { Docker::Image.new(Docker::Connection.new("test", {}), "id" => "test") }
let(:dummy_creds) { { username: "test", password: "test" } }
before do
Rake::Task['docker:build:qa'].reenable
allow(ENV).to receive(:[]).and_call_original
allow(Build).to receive(:get_gitlab_repo).and_return("/tmp/gitlab.1234/qa")
allow(Build).to receive(:package).and_return('gitlab-ce')
allow(DockerOperations).to receive(:build).and_call_original
end
it 'calls build method with correct parameters' do
allow(ENV).to receive(:[]).with('IMAGE_TAG').and_return(nil)
expect(DockerOperations).to receive(:build).with("/tmp/gitlab.1234/qa", "gitlab/gitlab-qa", "ce-latest")
expect(Docker::Image).to receive(:build_from_dir).with("/tmp/gitlab.1234/qa", { t: "gitlab/gitlab-qa:ce-latest", pull: true })
Rake::Task['docker:build:qa'].invoke
end
it 'tags triggered QA correctly' do
allow(ENV).to receive(:[]).with('IMAGE_TAG').and_return("omnibus-12345")
allow(DockerOperations).to receive(:build).and_return(true)
allow(Docker::Image).to receive(:build_from_dir).and_return(true)
allow(Docker::Image).to receive(:get).and_return(dummy_image)
allow(Build).to receive(:tag_triggered_qa).and_call_original
allow(DockerOperations).to receive(:tag).and_call_original
expect(Build).to receive(:tag_triggered_qa)
expect(DockerOperations).to receive(:tag).with("gitlab/gitlab-qa", "gitlab/gitlab-qa", "ce-latest", "ce-omnibus-12345")
expect(dummy_image).to receive(:tag).with(repo: "gitlab/gitlab-qa", tag: "ce-omnibus-12345", force: true)
Rake::Task['docker:build:qa'].invoke
end
end
describe 'docker:push:qa' do
let(:dummy_image) { Docker::Image.new(Docker::Connection.new("test", {}), "id" => "test") }
let(:dummy_creds) { { username: "test", password: "test" } }
before do
Rake::Task['docker:push:qa:stable'].reenable
Rake::Task['docker:push:qa:nightly'].reenable
Rake::Task['docker:push:qa:rc'].reenable
Rake::Task['docker:push:qa:latest'].reenable
allow(ENV).to receive(:[]).and_call_original
allow(Build).to receive(:package).and_return('gitlab-ce')
allow(Build).to receive(:docker_tag).and_return('9.0.0')
allow(DockerOperations).to receive(:authenticate).and_return(true)
allow(Docker::Image).to receive(:get).and_return(dummy_image)
allow(Docker).to receive(:creds).and_return(dummy_creds)
allow(dummy_image).to receive(:tag).and_return(true)
end
it 'pushes nightly images correctly' do
allow(Build).to receive(:add_nightly_tag?).and_return(true)
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'gitlab/gitlab-qa:ce-nightly')
Rake::Task['docker:push:qa:nightly'].invoke
end
it 'pushes latest images correctly' do
allow(Build).to receive(:add_latest_tag?).and_return(true)
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'gitlab/gitlab-qa:ce-latest')
Rake::Task['docker:push:qa:latest'].invoke
end
it 'pushes rc images correctly' do
allow(Build).to receive(:add_rc_tag?).and_return(true)
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'gitlab/gitlab-qa:ce-rc')
Rake::Task['docker:push:qa:rc'].invoke
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment