Skip to content

Commit 8cc3d81

Browse files
Robert Marshallbalasankarc
andcommitted
Merge branch 'split-info-deploy' into 'master'
Split Deploy related information to own class See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7238 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 d94eacb + 7677080 commit 8cc3d81

File tree

5 files changed

+90
-71
lines changed

5 files changed

+90
-71
lines changed

lib/gitlab/build/info.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
module Build
1010
class Info
11-
DEPLOYER_OS_MAPPING = {
12-
'PATCH_DEPLOY_ENVIRONMENT' => 'ubuntu-bionic',
13-
'RELEASE_DEPLOY_ENVIRONMENT' => 'ubuntu-focal',
14-
}.freeze
15-
1611
class << self
1712
def gcp_release_bucket
1813
# All tagged builds are pushed to the release bucket
@@ -33,28 +28,6 @@ def log_level
3328
'info'
3429
end
3530
end
36-
37-
def deploy_env_key
38-
if Build::Check.is_rc_tag?
39-
'PATCH_DEPLOY_ENVIRONMENT'
40-
elsif Build::Check.is_latest_stable_tag?
41-
'RELEASE_DEPLOY_ENVIRONMENT'
42-
end
43-
end
44-
45-
def deploy_env
46-
key = deploy_env_key
47-
48-
return nil if key.nil?
49-
50-
env = Gitlab::Util.get_env(key)
51-
52-
abort "Unable to determine which environment to deploy to, #{key} is empty" unless env
53-
54-
puts "Ready to send trigger for environment(s): #{env}"
55-
56-
env
57-
end
5831
end
5932
end
6033
end

lib/gitlab/build/info/deploy.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Build
2+
class Info
3+
class Deploy
4+
OS_MAPPING = {
5+
'PATCH_DEPLOY_ENVIRONMENT' => 'ubuntu-bionic',
6+
'RELEASE_DEPLOY_ENVIRONMENT' => 'ubuntu-focal',
7+
}.freeze
8+
9+
class << self
10+
def environment_key
11+
if Build::Check.is_rc_tag?
12+
'PATCH_DEPLOY_ENVIRONMENT'
13+
elsif Build::Check.is_latest_stable_tag?
14+
'RELEASE_DEPLOY_ENVIRONMENT'
15+
end
16+
end
17+
18+
def environment
19+
key = environment_key
20+
21+
return nil if key.nil?
22+
23+
env = Gitlab::Util.get_env(key)
24+
25+
abort "Unable to determine which environment to deploy too, #{key} is empty" unless env
26+
27+
puts "Ready to send trigger for environment(s): #{env}"
28+
29+
env
30+
end
31+
end
32+
end
33+
end
34+
end

lib/gitlab/tasks/gitlab_com.rake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
require_relative '../build/check'
2+
require_relative '../util'
3+
require_relative '../build/info/deploy'
4+
require_relative '../build/info/package'
5+
require_relative '../deployer_helper'
16
require_relative '../ohai_helper'
2-
require_relative '../deployer_helper.rb'
3-
require_relative "../util.rb"
4-
require_relative "../build/check"
57

68
namespace :gitlab_com do
79
desc 'Tasks related to gitlab.com.'
@@ -18,7 +20,7 @@ namespace :gitlab_com do
1820
next
1921
end
2022

21-
deploy_env = Build::Info.deploy_env
23+
deploy_env = Build::Info::Deploy.environment
2224

2325
if deploy_env.nil?
2426
puts 'Unable to determine which environment to deploy to, exiting...'
@@ -36,7 +38,7 @@ namespace :gitlab_com do
3638
trigger_ref = Gitlab::Util.get_env('DEPLOYER_TRIGGER_REF') || :master
3739

3840
current_os = OhaiHelper.fetch_os_with_codename[0..1].join("-")
39-
os_for_deployment = Build::Info::DEPLOYER_OS_MAPPING[Build::Info.deploy_env_key]
41+
os_for_deployment = Build::Info::Deploy::OS_MAPPING[Build::Info::Deploy.environment_key]
4042
if current_os != os_for_deployment
4143
puts "Deployment to #{deploy_env} not to be triggered from this build (#{current_os})."
4244
next
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'spec_helper'
2+
require 'gitlab/build/info/deploy'
3+
4+
RSpec.describe Build::Info::Deploy 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 '.environment' do
12+
before do
13+
allow(ENV).to receive(:[]).with('PATCH_DEPLOY_ENVIRONMENT').and_return('patch')
14+
allow(ENV).to receive(:[]).with('RELEASE_DEPLOY_ENVIRONMENT').and_return('r')
15+
end
16+
17+
context 'on RC tag' do
18+
before do
19+
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
20+
allow(Build::Check).to receive(:is_rc_tag?).and_return(true)
21+
end
22+
it 'returns the patch-deploy environment' do
23+
expect(described_class.environment).to eq('patch')
24+
end
25+
end
26+
27+
context 'on latest tag' do
28+
before do
29+
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
30+
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
31+
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(true)
32+
end
33+
it 'returns the release-deploy environment' do
34+
expect(described_class.environment).to eq('r')
35+
end
36+
end
37+
38+
context 'when unable to determine the desired env' do
39+
before do
40+
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
41+
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
42+
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(false)
43+
end
44+
it 'it returns nil' do
45+
expect(described_class.environment).to eq(nil)
46+
end
47+
end
48+
end
49+
end

spec/lib/gitlab/build/info_spec.rb

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

12-
describe '.deploy_env' do
13-
before do
14-
allow(ENV).to receive(:[]).with('PATCH_DEPLOY_ENVIRONMENT').and_return('patch')
15-
allow(ENV).to receive(:[]).with('RELEASE_DEPLOY_ENVIRONMENT').and_return('r')
16-
end
17-
18-
context 'on RC tag' do
19-
before do
20-
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
21-
allow(Build::Check).to receive(:is_rc_tag?).and_return(true)
22-
end
23-
it 'returns the auto-deploy environment' do
24-
expect(described_class.deploy_env).to eq('patch')
25-
end
26-
end
27-
28-
context 'on latest tag' do
29-
before do
30-
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
31-
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
32-
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(true)
33-
end
34-
it 'returns the auto-deploy environment' do
35-
expect(described_class.deploy_env).to eq('r')
36-
end
37-
end
38-
39-
context 'when unable to determine the desired env' do
40-
before do
41-
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
42-
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
43-
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(false)
44-
end
45-
it 'it returns nil' do
46-
expect(described_class.deploy_env).to eq(nil)
47-
end
48-
end
49-
end
50-
5112
describe '.gcp_release_bucket' do
5213
it 'returns the release bucket when on a tag' do
5314
allow(Build::Check).to receive(:on_tag?).and_return(true)

0 commit comments

Comments
 (0)