File tree Expand file tree Collapse file tree 5 files changed +90
-71
lines changed Expand file tree Collapse file tree 5 files changed +90
-71
lines changed Original file line number Diff line number Diff line change 8
8
9
9
module Build
10
10
class Info
11
- DEPLOYER_OS_MAPPING = {
12
- 'PATCH_DEPLOY_ENVIRONMENT' => 'ubuntu-bionic' ,
13
- 'RELEASE_DEPLOY_ENVIRONMENT' => 'ubuntu-focal' ,
14
- } . freeze
15
-
16
11
class << self
17
12
def gcp_release_bucket
18
13
# All tagged builds are pushed to the release bucket
@@ -33,28 +28,6 @@ def log_level
33
28
'info'
34
29
end
35
30
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
58
31
end
59
32
end
60
33
end
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'
1
6
require_relative '../ohai_helper'
2
- require_relative '../deployer_helper.rb'
3
- require_relative "../util.rb"
4
- require_relative "../build/check"
5
7
6
8
namespace :gitlab_com do
7
9
desc 'Tasks related to gitlab.com.'
@@ -18,7 +20,7 @@ namespace :gitlab_com do
18
20
next
19
21
end
20
22
21
- deploy_env = Build ::Info . deploy_env
23
+ deploy_env = Build ::Info :: Deploy . environment
22
24
23
25
if deploy_env . nil?
24
26
puts 'Unable to determine which environment to deploy to, exiting...'
@@ -36,7 +38,7 @@ namespace :gitlab_com do
36
38
trigger_ref = Gitlab ::Util . get_env ( 'DEPLOYER_TRIGGER_REF' ) || :master
37
39
38
40
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 ]
40
42
if current_os != os_for_deployment
41
43
puts "Deployment to #{ deploy_env } not to be triggered from this build (#{ current_os } )."
42
44
next
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 9
9
stub_env_var ( 'ALTERNATIVE_PRIVATE_TOKEN' , nil )
10
10
end
11
11
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
-
51
12
describe '.gcp_release_bucket' do
52
13
it 'returns the release bucket when on a tag' do
53
14
allow ( Build ::Check ) . to receive ( :on_tag? ) . and_return ( true )
You can’t perform that action at this time.
0 commit comments