Skip to content
Snippets Groups Projects
Commit ebcb5eff authored by DJ Mountney's avatar DJ Mountney
Browse files

Clean up and add tests for omnibus container template release

parent a43f2bf1
No related branches found
No related tags found
1 merge request!120Omnibus-repo release openshift template
Pipeline #
Loading
Loading
@@ -62,13 +62,10 @@ module Release
end
 
def after_release
# Bump container template versiosn for stable ce releases
unless version.ee? || version.rc?
bump_container_template_versions(stable_branch)
bump_container_template_versions('master')
push_ref('branch', stable_branch)
push_ref('branch', 'master')
end
bump_container_versions(stable_branch)
bump_container_versions('master')
push_ref('branch', stable_branch)
push_ref('branch', 'master')
 
super
end
Loading
Loading
@@ -152,36 +149,32 @@ module Release
File.read(gitlab_file_path).strip
end
 
def bump_container_template_versions(branch)
return if version.ee? || version.rc?
def bump_container_versions(branch)
repository.ensure_branch_exists(branch)
openshift_filename = 'docker/openshift-template.json'
openshift_version = version_class.new(version_from_container_template(openshift_filename).tr('-', '+'))
unless openshift_version.valid?
raise VersionStringNotFoundError.new("#{openshift_version} in #{openshift_filename}")
end
# Only bump the version if newer that what is already in the template
if version.to_i > openshift_version.to_i
bump_version_in_openshift_template(openshift_filename)
end
bump_version_in_openshift_template
end
 
def version_from_container_template(file_name)
file_path = File.join(repository.path, file_name)
def version_from_container_template(file_path)
unless File.exist?(file_path)
raise TemplateFileDoesNotExistError.new(file_path)
end
 
File.open(file_path) { |f| f.read.match(%r{gitlab/gitlab-ce:(\d+\.\d+\.\d+-ce\.\d+)})[1] }
file_version = File.open(file_path) { |f| f.read.match(%r{gitlab/gitlab-ce:(\d+\.\d+\.\d+-ce\.\d+)})[1] }
version_class.new(file_version.tr('-', '+'))
end
 
def bump_version_in_openshift_template(file_name)
file_path = File.join(repository.path, file_name)
unless File.exist?(file_path)
raise TemplateFileDoesNotExistError.new(file_path)
def bump_version_in_openshift_template
return if version.ee? || version.rc?
file_path = File.join(repository.path, 'docker/openshift-template.json')
openshift_version = version_from_container_template(file_path)
unless openshift_version.valid?
raise VersionStringNotFoundError.new("#{openshift_version} in #{file_path}")
end
# Only bump the version if newer that what is already in the template
return unless version > openshift_version
content = File.read(file_path)
content.gsub!(%r{gitlab/gitlab-ce:\d+\.\d+\.\d+-ce\.\d+}, "gitlab/gitlab-ce:#{version.to_docker}")
content.gsub!(/gitlab-\d+\.\d+\.\d+/, "gitlab-#{version.to_patch}")
Loading
Loading
Loading
Loading
@@ -138,10 +138,6 @@ class Version < String
str << '.0'
end
 
def from_omnibus
self.class.new(to_s.gsub(/-ce$/, ''))
end
def to_docker(ee: false)
to_omnibus(ee: ee).tr('+', '-')
end
Loading
Loading
@@ -154,11 +150,6 @@ class Version < String
"#{to_patch}-rc#{number}"
end
 
def to_i
raise ArgumentError unless valid?
Integer(to_patch.gsub(/\D/, ''))
end
def valid?
self =~ self.class::VERSION_REGEX
end
Loading
Loading
Loading
Loading
@@ -54,9 +54,10 @@ describe Release::GitlabCeRelease do
describe '#execute' do
{ ce: '', ee: '-ee' }.each do |edition, suffix|
context "with an existing 9-1-stable#{suffix} stable branch, releasing a patch" do
let(:version) { "9.1.24#{suffix}" }
let(:ob_version) { "9.1.24+#{edition}.0" }
let(:branch) { "9-1-stable#{suffix}" }
let(:version) { "9.1.24#{suffix}" }
let(:ob_version) { "9.1.24+#{edition}.0" }
let(:docker_version) { "gitlab/gitlab-ce:#{ob_version.tr('+', '-')}" }
let(:branch) { "9-1-stable#{suffix}" }
 
describe "release GitLab#{suffix.upcase}" do
it 'performs changelog compilation' do
Loading
Loading
@@ -81,15 +82,24 @@ describe Release::GitlabCeRelease do
expect(ob_repository).to have_version('workhorse').at('3.3.3')
expect(ob_repository).to have_version('pages').at('4.4.4')
expect(ob_repository).to have_version('gitaly').at('5.5.5')
if edition == :ce
expect(ob_repository).to have_container_template('docker/openshift-template.json')
.match(docker_version)
else
expect(ob_repository).not_to have_container_template('docker/openshift-template.json')
.match(docker_version)
end
end
end
end
end
 
context "with a new 10-1-stable#{suffix} stable branch, releasing an RC" do
let(:version) { "10.1.0-rc13#{suffix}" }
let(:ob_version) { "10.1.0+rc13.#{edition}.0" }
let(:branch) { "10-1-stable#{suffix}" }
let(:version) { "10.1.0-rc13#{suffix}" }
let(:ob_version) { "10.1.0+rc13.#{edition}.0" }
let(:docker_version) { "gitlab/gitlab-ce:#{ob_version.tr('+', '-')}" }
let(:branch) { "10-1-stable#{suffix}" }
 
describe "release GitLab#{suffix.upcase}" do
it 'does not perform changelog compilation' do
Loading
Loading
@@ -114,15 +124,18 @@ describe Release::GitlabCeRelease do
expect(ob_repository).to have_version('workhorse').at('3.4.0')
expect(ob_repository).to have_version('pages').at('4.5.0')
expect(ob_repository).to have_version('gitaly').at('5.6.0')
expect(ob_repository).not_to have_container_template('docker/openshift-template.json')
.match(docker_version)
end
end
end
end
 
context "with a new 10-1-stable#{suffix} stable branch, releasing a stable .0" do
let(:version) { "10.1.0#{suffix}" }
let(:ob_version) { "10.1.0+#{edition}.0" }
let(:branch) { "10-1-stable#{suffix}" }
let(:version) { "10.1.0#{suffix}" }
let(:ob_version) { "10.1.0+#{edition}.0" }
let(:docker_version) { "gitlab/gitlab-ce:#{ob_version.tr('+', '-')}" }
let(:branch) { "10-1-stable#{suffix}" }
 
describe "release GitLab#{suffix.upcase}" do
it 'performs changelog compilation' do
Loading
Loading
@@ -157,6 +170,14 @@ describe Release::GitlabCeRelease do
expect(ob_repository).to have_version('workhorse').at('3.4.0')
expect(ob_repository).to have_version('pages').at('4.5.0')
expect(ob_repository).to have_version('gitaly').at('5.6.0')
if edition == :ce
expect(ob_repository).to have_container_template('docker/openshift-template.json')
.match(docker_version)
else
expect(ob_repository).not_to have_container_template('docker/openshift-template.json')
.match(docker_version)
end
end
end
end
Loading
Loading
@@ -164,9 +185,10 @@ describe Release::GitlabCeRelease do
end
 
context "with a version < 8.5.0" do
let(:version) { "1.9.24-ee" }
let(:ob_version) { "1.9.24+ee.0" }
let(:branch) { "1-9-stable-ee" }
let(:version) { "1.9.24-ee" }
let(:ob_version) { "1.9.24+ee.0" }
let(:docker_version) { "gitlab/gitlab-ce:#{ob_version.tr('+', '-')}" }
let(:branch) { "1-9-stable-ee" }
 
describe "release GitLab-EE" do
before do
Loading
Loading
@@ -187,6 +209,8 @@ describe Release::GitlabCeRelease do
expect(ob_repository).to have_version('workhorse').at('3.3.3')
expect(ob_repository).not_to have_version('pages')
expect(ob_repository).to have_version('gitaly').at('5.5.5')
expect(ob_repository).not_to have_container_template('docker/openshift-template.json')
.match(docker_version)
end
end
end
Loading
Loading
Loading
Loading
@@ -278,6 +278,30 @@ describe Version do
end
end
 
describe '#to_docker' do
it 'converts pre-releases' do
aggregate_failures do
expect(version('1.23.4-rc1').to_docker).to eq '1.23.4-rc1.ce.0'
expect(version('1.23.4-rc1').to_docker(ee: true)).to eq '1.23.4-rc1.ee.0'
end
end
it 'converts minor releases' do
aggregate_failures do
expect(version('1.23.0').to_docker).to eq '1.23.0-ce.0'
expect(version('1.23.0').to_docker(ee: true)).to eq '1.23.0-ee.0'
end
end
it 'converts patch releases' do
aggregate_failures do
expect(version('1.23.2').to_docker).to eq '1.23.2-ce.0'
expect(version('1.23.2').to_docker(ee: true)).to eq '1.23.2-ee.0'
end
end
end
describe '#to_patch' do
it 'returns the patch version' do
expect(version('1.23.4-rc1').to_patch).to eq '1.23.4'
Loading
Loading
Loading
Loading
@@ -129,4 +129,44 @@ module RuggedMatchers
"expected #{repository.workdir} not to contain #{@actual}"
end
end
# Verify that `repository` has a template file with container at a specific version
#
# Examples:
#
# expect(repository).to have_have_container_template('docer/openshift-template.json').match('gitlab/gitlab-ce:1.2.3-ce.0')
# expect(repository).not_to have_container_template('docer/openshift-template.json')
matcher :have_container_template do |file_path|
match do |repository|
@actual = file_path
begin
!read_head_blob(repository, @actual)[@match_data].nil?
rescue NoMethodError
false
end
end
match_when_negated do |repository|
@actual = file_path
begin
read_head_blob(repository, @actual)[@match_data].nil?
rescue NoMethodError
true
end
end
chain :match do |match|
@match_data = match
end
failure_message do
"expected #{File.join(repository.workdir, @actual)} to match #{@match_data}"
end
failure_message_when_negated do
"expected #{repository.workdir} not to contain #{@actual}"
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