Skip to content
Snippets Groups Projects
Commit be49ccfe authored by Robert Speicher's avatar Robert Speicher
Browse files

Merge branch 'omnibus-release-openshift-template' into 'master'

Omnibus-repo release openshift template

See merge request !120
parents f39e3b07 971c6972
No related branches found
No related tags found
1 merge request!120Omnibus-repo release openshift template
Pipeline #
Loading
Loading
@@ -5,6 +5,8 @@ require 'time'
module Release
class OmnibusGitLabRelease < BaseRelease
class VersionFileDoesNotExistError < StandardError; end
class TemplateFileDoesNotExistError < StandardError; end
class VersionStringNotFoundError < StandardError; end
class SecurityReleaseInProgressError < StandardError; end
 
# Number of minutes we will be able to reuse the same security repository.
Loading
Loading
@@ -59,6 +61,15 @@ module Release
super
end
 
def after_release
bump_container_versions(stable_branch)
bump_container_versions('master')
push_ref('branch', stable_branch)
push_ref('branch', 'master')
super
end
def repo_variable
return @repo_variable if defined?(@repo_variable)
 
Loading
Loading
@@ -137,5 +148,38 @@ module Release
 
File.read(gitlab_file_path).strip
end
def bump_container_versions(branch)
repository.ensure_branch_exists(branch)
bump_version_in_openshift_template
end
def version_from_container_template(file_path)
unless File.exist?(file_path)
raise TemplateFileDoesNotExistError.new(file_path)
end
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
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 than what is already in the template
return unless version > openshift_version
content = File.read(file_path)
content.sub!(%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}")
repository.write_file(file_path, content)
repository.commit(file_path, "Update #{file_path} to #{version.to_docker}")
end
end
end
Loading
Loading
@@ -138,6 +138,10 @@ class Version < String
str << '.0'
end
 
def to_docker(ee: false)
to_omnibus(ee: ee).tr('+', '-')
end
def to_patch
"#{major}.#{minor}.#{patch}"
end
Loading
Loading
Loading
Loading
@@ -48,14 +48,16 @@ describe Release::GitlabCeRelease do
def execute(version, branch)
described_class.new(version).execute
repository.checkout(branch)
ob_repository.checkout(branch)
end
 
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
@@ -80,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
@@ -113,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
@@ -156,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
@@ -163,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
@@ -186,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,34 @@ 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_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
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
Loading
Loading
@@ -148,6 +148,12 @@ class OmnibusReleaseFixture
'VERSION' => "1.9.24\n"
)
 
commit_blob(
path: 'docker/openshift-template.json',
content: '"name": "gitlab-1.9.24","name": "gitlab/gitlab-ce:1.9.24-ce.0","name": "${APPLICATION_NAME}:gitlab-1.9.24"',
message: 'Add openshift-template.json'
)
repository.branches.create('1-9-stable', 'HEAD')
repository.branches.create('1-9-stable-ee', 'HEAD')
 
Loading
Loading
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