Skip to content

Commit 0ba1b9c

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/7013 Merged-by: Robert Marshall <[email protected]> Approved-by: Robert Marshall <[email protected]> Approved-by: Andrew Patterson <[email protected]> Reviewed-by: Robert Marshall <[email protected]> Co-authored-by: Balasankar "Balu" C <[email protected]>
2 parents 477a4b2 + a17fa38 commit 0ba1b9c

File tree

5 files changed

+99
-81
lines changed

5 files changed

+99
-81
lines changed

lib/gitlab/build/info.rb

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

99
module Build
1010
class Info
11-
DEPLOYER_OS_MAPPING = {
12-
'AUTO_DEPLOY_ENVIRONMENT' => 'ubuntu-xenial',
13-
'PATCH_DEPLOY_ENVIRONMENT' => 'ubuntu-bionic',
14-
'RELEASE_DEPLOY_ENVIRONMENT' => 'ubuntu-focal',
15-
}.freeze
16-
1711
class << self
1812
def gcp_release_bucket
1913
# All tagged builds are pushed to the release bucket
@@ -34,30 +28,6 @@ def log_level
3428
'info'
3529
end
3630
end
37-
38-
def deploy_env_key
39-
if Build::Check.is_auto_deploy_tag?
40-
'AUTO_DEPLOY_ENVIRONMENT'
41-
elsif Build::Check.is_rc_tag?
42-
'PATCH_DEPLOY_ENVIRONMENT'
43-
elsif Build::Check.is_latest_stable_tag?
44-
'RELEASE_DEPLOY_ENVIRONMENT'
45-
end
46-
end
47-
48-
def deploy_env
49-
key = deploy_env_key
50-
51-
return nil if key.nil?
52-
53-
env = Gitlab::Util.get_env(key)
54-
55-
abort "Unable to determine which environment to deploy too, #{key} is empty" unless env
56-
57-
puts "Ready to send trigger for environment(s): #{env}"
58-
59-
env
60-
end
6131
end
6232
end
6333
end

lib/gitlab/build/info/deploy.rb

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

lib/gitlab/tasks/gitlab_com.rake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require_relative '../build/info/deploy'
12
require_relative '../deployer_helper.rb'
23
require_relative "../util.rb"
34

@@ -11,10 +12,10 @@ namespace :gitlab_com do
1112
exit
1213
end
1314

14-
deploy_env = Build::Info.deploy_env
15+
deploy_env = Build::Info::Deploy.environment
1516
operating_systems = Build::Info::Package.file_list.map { |path| path.split("/")[1] }.uniq
1617

17-
unless operating_systems.include?(Build::Info::DEPLOYER_OS_MAPPING[Build::Info.deploy_env_key])
18+
unless operating_systems.include?(Build::Info::Deploy::OS_MAPPING[Build::Info::Deploy.environment_key])
1819
puts "Deployment to #{deploy_env} not to be triggered from this build (#{operating_systems.join(',')})."
1920
exit
2021
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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('AUTO_DEPLOY_ENVIRONMENT').and_return('ad')
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 auto-deploy tag' do
19+
before do
20+
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(true)
21+
end
22+
it 'returns the auto-deploy environment' do
23+
expect(described_class.environment).to eq('ad')
24+
end
25+
end
26+
27+
context 'on RC 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(true)
31+
end
32+
it 'returns the patch-deploy environment' do
33+
expect(described_class.environment).to eq('patch')
34+
end
35+
end
36+
37+
context 'on latest tag' do
38+
before do
39+
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
40+
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
41+
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(true)
42+
end
43+
it 'returns the release-deploy environment' do
44+
expect(described_class.environment).to eq('r')
45+
end
46+
end
47+
48+
context 'when unable to determine the desired env' do
49+
before do
50+
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
51+
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
52+
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(false)
53+
end
54+
it 'it returns nil' do
55+
expect(described_class.environment).to eq(nil)
56+
end
57+
end
58+
end
59+
end

spec/lib/gitlab/build/info_spec.rb

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +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('AUTO_DEPLOY_ENVIRONMENT').and_return('ad')
15-
allow(ENV).to receive(:[]).with('PATCH_DEPLOY_ENVIRONMENT').and_return('patch')
16-
allow(ENV).to receive(:[]).with('RELEASE_DEPLOY_ENVIRONMENT').and_return('r')
17-
end
18-
19-
context 'on auto-deploy tag' do
20-
before do
21-
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(true)
22-
end
23-
it 'returns the auto-deploy environment' do
24-
expect(described_class.deploy_env).to eq('ad')
25-
end
26-
end
27-
28-
context 'on RC 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(true)
32-
end
33-
it 'returns the auto-deploy environment' do
34-
expect(described_class.deploy_env).to eq('patch')
35-
end
36-
end
37-
38-
context 'on latest tag' 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(true)
43-
end
44-
it 'returns the auto-deploy environment' do
45-
expect(described_class.deploy_env).to eq('r')
46-
end
47-
end
48-
49-
context 'when unable to determine the desired env' do
50-
before do
51-
allow(Build::Check).to receive(:is_auto_deploy_tag?).and_return(false)
52-
allow(Build::Check).to receive(:is_rc_tag?).and_return(false)
53-
allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(false)
54-
end
55-
it 'it returns nil' do
56-
expect(described_class.deploy_env).to eq(nil)
57-
end
58-
end
59-
end
60-
6112
describe '.gcp_release_bucket' do
6213
it 'returns the release bucket when on a tag' do
6314
allow(Build::Check).to receive(:on_tag?).and_return(true)

0 commit comments

Comments
 (0)