Skip to content

Commit 429bdb1

Browse files
Robert Marshallbalasankarc
andcommitted
Merge branch 'split-info-docker' into 'master'
Split Docker related information to own class See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7011 Merged-by: Robert Marshall <[email protected]> Approved-by: Andrew Patterson <[email protected]> Approved-by: Robert Marshall <[email protected]> Co-authored-by: Balasankar "Balu" C <[email protected]>
2 parents c5b4ebe + 0237300 commit 429bdb1

File tree

12 files changed

+75
-61
lines changed

12 files changed

+75
-61
lines changed

lib/gitlab/build/facts.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require_relative 'info/docker'
12
require_relative 'info/git'
23
require_relative 'info/package'
34

@@ -73,7 +74,7 @@ def common_vars
7374

7475
def qa_trigger_vars
7576
%W[
76-
QA_RELEASE=#{Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info.docker_tag)}
77+
QA_RELEASE=#{Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info::Docker.tag)}
7778
QA_IMAGE=#{Build::Info.qa_image}
7879
QA_TESTS=#{Gitlab::Util.get_env('QA_TESTS')}
7980
ALLURE_JOB_NAME=#{allure_job_name}-#{Build::Info::Package.edition}

lib/gitlab/build/image.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module Build
66
module Image
77
def pull
88
Docker::Image.create(
9-
'fromImage' => "#{gitlab_registry_image_address}:#{Build::Info.docker_tag}"
9+
'fromImage' => "#{gitlab_registry_image_address}:#{Build::Info::Docker.tag}"
1010
)
11-
puts "Pulled tag: #{Build::Info.docker_tag}"
11+
puts "Pulled tag: #{Build::Info::Docker.tag}"
1212
end
1313

1414
def gitlab_registry_image_address(tag: nil)
@@ -29,7 +29,7 @@ def tag_and_push_to_gitlab_registry(final_tag)
2929
puts "Pushed #{gitlab_registry_image_address}:#{final_tag}"
3030
end
3131

32-
def tag_and_push_to_dockerhub(final_tag, initial_tag: Build::Info.docker_tag)
32+
def tag_and_push_to_dockerhub(final_tag, initial_tag: Build::Info::Docker.tag)
3333
DockerOperations.authenticate(Gitlab::Util.get_env('DOCKERHUB_USERNAME'), Gitlab::Util.get_env('DOCKERHUB_PASSWORD'))
3434
DockerOperations.tag_and_push(
3535
gitlab_registry_image_address,
@@ -41,7 +41,7 @@ def tag_and_push_to_dockerhub(final_tag, initial_tag: Build::Info.docker_tag)
4141
end
4242

4343
def write_release_file
44-
contents = Build::Info.release_file_contents
44+
contents = Build::Info::Docker.release_file_contents
4545
File.write('docker/RELEASE', contents)
4646
contents
4747
end

lib/gitlab/build/info.rb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class Info
1515
}.freeze
1616

1717
class << self
18-
def docker_tag
19-
Gitlab::Util.get_env('IMAGE_TAG') || Build::Info::Package.release_version.tr('+', '-')
20-
end
21-
2218
def qa_image
2319
Gitlab::Util.get_env('QA_IMAGE') || "#{Gitlab::Util.get_env('CI_REGISTRY')}/#{Build::Info::Components::GitLabRails.project_path}/#{Build::Info::Package.name}-qa:#{Build::Info::Components::GitLabRails.ref(prepend_version: false)}"
2420
end
@@ -43,30 +39,6 @@ def log_level
4339
end
4440
end
4541

46-
def release_file_contents
47-
repo = Gitlab::Util.get_env('PACKAGECLOUD_REPO') # Target repository
48-
49-
download_url = if /dev.gitlab.org/.match?(Build::Info::CI.api_v4_url)
50-
Build::Info::CI.package_download_url
51-
else
52-
Build::Info::CI.triggered_package_download_url
53-
end
54-
55-
raise "Unable to identify package download URL." unless download_url
56-
57-
contents = []
58-
contents << "PACKAGECLOUD_REPO=#{repo.chomp}\n" if repo && !repo.empty?
59-
contents << "RELEASE_PACKAGE=#{Build::Info::Package.name}\n"
60-
contents << "RELEASE_VERSION=#{Build::Info::Package.release_version}\n"
61-
contents << "DOWNLOAD_URL=#{download_url}\n"
62-
contents << "CI_JOB_TOKEN=#{Build::Info::CI.job_token}\n"
63-
contents.join
64-
end
65-
66-
def image_reference
67-
"#{Build::GitlabImage.gitlab_registry_image_address}:#{Info.docker_tag}"
68-
end
69-
7042
def deploy_env_key
7143
if Build::Check.is_auto_deploy_tag?
7244
'AUTO_DEPLOY_ENVIRONMENT'

lib/gitlab/build/info/docker.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Build
2+
class Info
3+
class Docker
4+
class << self
5+
def tag
6+
Gitlab::Util.get_env('IMAGE_TAG') || Build::Info::Package.release_version.tr('+', '-')
7+
end
8+
9+
def release_file_contents
10+
repo = Gitlab::Util.get_env('PACKAGECLOUD_REPO') # Target repository
11+
12+
download_url = if /dev.gitlab.org/.match?(Build::Info::CI.api_v4_url)
13+
Build::Info::CI.package_download_url
14+
else
15+
Build::Info::CI.triggered_package_download_url
16+
end
17+
18+
raise "Unable to identify package download URL." unless download_url
19+
20+
contents = []
21+
contents << "PACKAGECLOUD_REPO=#{repo.chomp}\n" if repo && !repo.empty?
22+
contents << "RELEASE_PACKAGE=#{Build::Info::Package.name}\n"
23+
contents << "RELEASE_VERSION=#{Build::Info::Package.release_version}\n"
24+
contents << "DOWNLOAD_URL=#{download_url}\n"
25+
contents << "CI_JOB_TOKEN=#{Build::Info::CI.job_token}\n"
26+
contents.join
27+
end
28+
end
29+
end
30+
end
31+
end

lib/gitlab/deployer_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def trigger_project
5050
end
5151

5252
def release
53-
@release ||= Build::Info.docker_tag
53+
@release ||= Build::Info::Docker.tag
5454
end
5555

5656
def form_data_for_trigger

lib/gitlab/tasks/docker_tasks.rake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ namespace :docker do
2626
# Only runs on dev.gitlab.org
2727
task :staging do
2828
Gitlab::Util.section('docker:push:staging') do
29-
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info.docker_tag)
29+
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info::Docker.tag)
3030
end
3131
end
3232

3333
task :stable do
3434
Gitlab::Util.section('docker:push:stable') do
35-
Build::GitlabImage.tag_and_push_to_dockerhub(Build::Info.docker_tag)
35+
Build::GitlabImage.tag_and_push_to_dockerhub(Build::Info::Docker.tag)
3636
end
3737
end
3838

@@ -60,7 +60,7 @@ namespace :docker do
6060
desc "Push triggered Docker Image to GitLab Registry"
6161
task :triggered do
6262
Gitlab::Util.section('docker:push:triggered') do
63-
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info.docker_tag)
63+
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info::Docker.tag)
6464
end
6565
end
6666
end

lib/gitlab/tasks/qa.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace :qa do
105105
task :test_letsencrypt do
106106
Gitlab::Util.section('qa:test_letsencrypt') do
107107
Gitlab::Util.set_env_if_missing('CI_REGISTRY_IMAGE', 'registry.gitlab.com/gitlab-org/build/omnibus-gitlab-mirror')
108-
image_address = Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info.docker_tag)
108+
image_address = Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info::Docker.tag)
109109
Dir.chdir('letsencrypt-test') do
110110
system({ 'IMAGE' => image_address }, './test.sh')
111111
end

spec/lib/gitlab/build/image_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def self.dockerhub_image_name
2222
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('registry.com/group/repo')
2323
allow(ENV).to receive(:[]).with('DOCKERHUB_USERNAME').and_return('john')
2424
allow(ENV).to receive(:[]).with('DOCKERHUB_PASSWORD').and_return('secret')
25-
allow(Build::Info).to receive(:docker_tag).and_return('9.0.0')
25+
allow(Build::Info::Docker).to receive(:tag).and_return('9.0.0')
2626
allow(Gitlab::APIClient).to receive(:new).and_return(double(get_job_id: '999999'))
2727
end
2828

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'spec_helper'
2+
require 'gitlab/build/info/docker'
3+
4+
RSpec.describe Build::Info::Docker do
5+
before do
6+
stub_default_package_version
7+
stub_env_var('GITLAB_ALTERNATIVE_REPO', nil)
8+
stub_env_var('ALTERNATIVE_PRIVATE_TOKEN', nil)
9+
end
10+
11+
describe '.tag' do
12+
before do
13+
allow(Build::Check).to receive(:on_tag?).and_return(true)
14+
allow_any_instance_of(Omnibus::BuildVersion).to receive(:semver).and_return('12.121.12')
15+
allow_any_instance_of(Gitlab::BuildIteration).to receive(:build_iteration).and_return('ce.1')
16+
end
17+
18+
it 'returns package version when regular build' do
19+
expect(described_class.tag).to eq('12.121.12-ce.1')
20+
end
21+
22+
it 'respects IMAGE_TAG if set' do
23+
allow(ENV).to receive(:[]).with('IMAGE_TAG').and_return('foobar')
24+
expect(described_class.tag).to eq('foobar')
25+
end
26+
end
27+
end

spec/lib/gitlab/build/info_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@
99
stub_env_var('ALTERNATIVE_PRIVATE_TOKEN', nil)
1010
end
1111

12-
describe '.docker_tag' do
13-
before do
14-
allow(Build::Check).to receive(:on_tag?).and_return(true)
15-
allow_any_instance_of(Omnibus::BuildVersion).to receive(:semver).and_return('12.121.12')
16-
allow_any_instance_of(Gitlab::BuildIteration).to receive(:build_iteration).and_return('ce.1')
17-
end
18-
19-
it 'returns package version when regular build' do
20-
expect(described_class.docker_tag).to eq('12.121.12-ce.1')
21-
end
22-
23-
it 'respects IMAGE_TAG if set' do
24-
allow(ENV).to receive(:[]).with('IMAGE_TAG').and_return('foobar')
25-
expect(described_class.docker_tag).to eq('foobar')
26-
end
27-
end
28-
2912
describe '.deploy_env' do
3013
before do
3114
allow(ENV).to receive(:[]).with('AUTO_DEPLOY_ENVIRONMENT').and_return('ad')

0 commit comments

Comments
 (0)