envirobly 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78d045fc1a7ddd776a3f83e20a5e3b8f49882e6477075c6f10ecd7308af9132e
4
- data.tar.gz: dca43cc5b0184b7efdf18c867109f1eea1cb2f70e23b233d2182a99715a95e98
3
+ metadata.gz: 82f46d03c6a985973bd9deac24b145bef0e6fb3b30df464c215a76edb3b2a967
4
+ data.tar.gz: f07509d4681206b3c39279f0e8d6c986400a8ae305eb9c803064526b60b44ec4
5
5
  SHA512:
6
- metadata.gz: 4a9b3835b2002fbdac6aed8f9981c8261d5509cb9bdde6e2398612e58cf432176d486b89311f61eb24e25c4e783925f93349b797f16961e45141c04609f1ae66
7
- data.tar.gz: 15ca73d3b36db3b9d812516d71cbc6af2e8a5afe3a4a6db8fc928a3e18d8148ce88a8d3703f6e84395661b2d5e6a6ed6729c3ca32797f3be1a79dc9dda26c0f0
6
+ metadata.gz: 5ed370c06228f0416559315467dea3e5f4c8a7f2b8bcdc6f7cd73f4250bad0838c88e40ce27770cf857f48dbbc94d8898f0731493c64981b72215f8908432861
7
+ data.tar.gz: ee6c6431ac69593e65da5839bdcaa1f42a80cabee866d5177c4b11f0bc3dddbb7f6489728f85c25b568a6cd5d36906e2eced889c693d3d04fdbb5a976eccd147
@@ -3,13 +3,15 @@
3
3
  class Envirobly::Cli::Main < Envirobly::Base
4
4
  include Envirobly::Colorize
5
5
 
6
+ class_option :unattended, type: :boolean, default: false
7
+
6
8
  desc "version", "Show Envirobly CLI version"
7
9
  method_option :pure, type: :boolean, default: false
8
10
  def version
9
11
  if options.pure
10
- puts Envirobly::VERSION
12
+ say Envirobly::VERSION
11
13
  else
12
- puts "envirobly CLI v#{Envirobly::VERSION}"
14
+ say "envirobly CLI v#{Envirobly::VERSION}"
13
15
  end
14
16
  end
15
17
 
@@ -26,14 +28,28 @@ class Envirobly::Cli::Main < Envirobly::Base
26
28
  say "You can sign in again with `envirobly signin`"
27
29
  end
28
30
 
29
- desc "set_default_account", "Choose default account to deploy the current project to"
30
- def set_default_account
31
- Envirobly::Defaults::Account.new(shell:).require_value
32
- end
31
+ desc "target [NAME]", "Configure deployment (default) target"
32
+ method_option :missing_only, type: :boolean, default: false
33
+ def target(name = nil)
34
+ Envirobly::AccessToken.new(shell:).require!
35
+
36
+ target = Envirobly::Target.new(default_project_name: File.basename(Dir.pwd), shell:)
37
+ target.name = name if name.present?
38
+
39
+ errors = target.errors :name
40
+
41
+ if errors.any?
42
+ errors.each do |message|
43
+ shell.say_error message
44
+ end
45
+
46
+ exit 1
47
+ end
33
48
 
34
- desc "set_default_region", "Set default region for the current project when deploying for the first time"
35
- def set_default_region
36
- Envirobly::Defaults::Region.new(shell:).require_value
49
+ target.configure!(missing_only: options.missing_only)
50
+
51
+ shell.say "#{green_check} "
52
+ shell.say "Target configured.", :green
37
53
  end
38
54
 
39
55
  desc "validate", "Validates config (for given environ)"
@@ -69,18 +85,17 @@ class Envirobly::Cli::Main < Envirobly::Base
69
85
  table_data, borders: true
70
86
  end
71
87
 
72
- desc "deploy [ENVIRON_NAME]", <<~TXT
88
+ desc "deploy [[TARGET/[ENVIRON_NAME]]", <<~TXT
73
89
  Deploy to environ identified by name.
74
90
  Name can contain letters, numbers, dashes or underscores.
75
91
  If environ name is left blank, current git branch name is used.
76
92
  TXT
77
- method_option :account_id, type: :numeric
93
+ method_option :account_url, type: :string
78
94
  method_option :region, type: :string
79
- method_option :project_id, type: :numeric
80
95
  method_option :project_name, type: :string
81
96
  method_option :commit, type: :string, default: "HEAD"
82
97
  method_option :dry_run, type: :boolean, default: false
83
- def deploy(environ_name = nil)
98
+ def deploy(path = nil)
84
99
  commit = Envirobly::Git::Commit.new options.commit
85
100
 
86
101
  unless commit.exists?
@@ -106,15 +121,8 @@ class Envirobly::Cli::Main < Envirobly::Base
106
121
 
107
122
  Envirobly::AccessToken.new(shell:).require!
108
123
 
109
- deployment = Envirobly::Deployment.new(
110
- account_id: options.account_id,
111
- region: options.region,
112
- project_id: options.project_id,
113
- project_name: options.project_name,
114
- environ_name: environ_name.presence,
115
- commit:,
116
- shell:
117
- )
124
+ target = create_target(path:, commit:)
125
+ deployment = Envirobly::Deployment.new(target:, commit:, shell:)
118
126
  deployment.perform(dry_run: options.dry_run)
119
127
  end
120
128
 
@@ -130,35 +138,65 @@ class Envirobly::Cli::Main < Envirobly::Base
130
138
  Keep in mind, your container might not have a shell installed. In such cases you won't be able
131
139
  to start an interactive session.
132
140
  TXT
133
- method_option :account_id, type: :numeric
134
- method_option :project_id, type: :numeric
141
+ method_option :account_url, type: :string
135
142
  method_option :project_name, type: :string
136
143
  method_option :environ_name, type: :string
137
144
  method_option :instance_slot, type: :numeric, default: 0
138
145
  method_option :shell, type: :string
139
146
  method_option :user, type: :string
140
- def exec(service_name, *command)
141
- Envirobly::ContainerShell.new(service_name, options, shell:).exec(command)
147
+ method_option :dry_run, type: :boolean, default: false
148
+ def exec(path, *command)
149
+ target = create_target(path:, context: :service)
150
+
151
+ Envirobly::ContainerShell.
152
+ new(target:, instance_slot: options.instance_slot, shell:, exec_shell: options.shell, exec_user: options.user).
153
+ exec(command, dry_run: options.dry_run)
142
154
  end
143
155
 
144
156
  desc "rsync [SERVICE_NAME:]SOURCE_PATH [SERVICE_NAME:]DESTINATION_PATH", <<~TXT
145
157
  Synchronize files between you and your service's data volume.
146
158
  TXT
147
- method_option :account_id, type: :numeric
148
- method_option :project_id, type: :numeric
159
+ method_option :account_url, type: :string
149
160
  method_option :project_name, type: :string
150
161
  method_option :environ_name, type: :string
151
162
  method_option :args, type: :string, default: "-avzP"
163
+ method_option :dry_run, type: :boolean, default: false
152
164
  def rsync(source, destination)
153
- service_name = nil
154
-
155
- [ source, destination ].each do |path|
156
- if path =~ /\A([a-z0-9\-_]+):/i
157
- service_name = $1
165
+ path = nil
166
+ [ source, destination ].each do |arg|
167
+ if arg =~ /\A([a-z0-9\-_\/]+):/i
168
+ path = $1
158
169
  break
159
170
  end
160
171
  end
161
172
 
162
- Envirobly::ContainerShell.new(service_name, options, shell:).rsync(source, destination)
173
+ target = create_target(path:, context: :service)
174
+
175
+ Envirobly::ContainerShell.
176
+ new(target:, shell:, rsync_args: options.args).
177
+ rsync(source, destination, path:, dry_run: options.dry_run)
163
178
  end
179
+
180
+ private
181
+ def create_target(path:, commit: Envirobly::Git::Commit.new("HEAD"), context: nil)
182
+ target = Envirobly::Target.new(
183
+ path,
184
+ account_url: options.account_url,
185
+ project_name: options.project_name,
186
+ region: options.region,
187
+ default_project_name: File.basename(Dir.pwd),
188
+ default_environ_name: commit.current_branch,
189
+ shell:,
190
+ context:
191
+ )
192
+ target.render_and_exit_on_errors!
193
+
194
+ if options.unattended
195
+ target.save
196
+ else
197
+ target.configure!(missing_only: true)
198
+ end
199
+
200
+ target
201
+ end
164
202
  end
@@ -4,7 +4,8 @@ module Envirobly
4
4
  class Config
5
5
  DIR = ".envirobly"
6
6
  BASE = "deploy.yml"
7
- OVERRIDES_PATTERN = /deploy\.([a-z0-9\-_]+)\.yml/i
7
+ ENVIRON_OVERRIDE_REGEXP = /deploy\.([a-z0-9\-_]+)\.yml/i
8
+ TARGETS_PATH = Pathname.new(DIR).join(".targets")
8
9
 
9
10
  attr_reader :errors
10
11
 
@@ -43,7 +44,7 @@ module Envirobly
43
44
 
44
45
  private
45
46
  def config_file?(file)
46
- file == BASE || file.match?(OVERRIDES_PATTERN)
47
+ file == BASE || file.match?(ENVIRON_OVERRIDE_REGEXP)
47
48
  end
48
49
 
49
50
  def parse(content, path)
@@ -17,67 +17,48 @@ module Envirobly
17
17
  ]
18
18
  USER_AND_HOST = "envirobly-service@%s"
19
19
 
20
- attr_reader :options, :service_name
21
-
22
- def initialize(service_name, options, shell:)
23
- @service_name = service_name
24
- @options = options
25
-
26
- commit = Git::Commit.new "HEAD"
27
- default_account = Defaults::Account.new(shell:)
28
- default_project = Defaults::Project.new(shell:)
29
-
30
- target = Target.new(
31
- default_account_id: default_account.value,
32
- default_project_id: default_project.value,
33
- default_project_name: Defaults::Project.dirname,
34
- default_environ_name: commit.current_branch,
35
- account_id: options.account_id,
36
- project_id: options.project_id,
37
- project_name: options.project_name,
38
- environ_name: options.environ_name
39
- )
40
-
41
- if target.missing_params.include?(:account_id)
42
- target.account_id = default_account.require_value
43
- end
44
-
45
- target.ignored_params.each do |param|
46
- shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it"
47
- end
48
-
20
+ def initialize(target:, shell:, instance_slot: 0, rsync_args: nil, exec_shell: nil, exec_user: nil)
21
+ @shell = shell
22
+ @rsync_args = rsync_args
23
+ @exec_shell = exec_shell
24
+ @exec_user = exec_user
49
25
  @params = {
50
26
  account_id: target.account_id,
51
- project_id: target.project_id,
52
27
  project_name: target.project_name,
53
28
  environ_name: target.environ_name,
54
- service_name:,
55
- instance_slot: options.instance_slot || 0
29
+ service_name: target.service_name,
30
+ instance_slot: instance_slot
56
31
  }
57
-
58
- if options.project_name.blank? && options.account_id.blank? && options.project_id.blank?
59
- @params[:project_id] = Defaults::Project.new.value
60
- end
61
32
  end
62
33
 
63
- def exec(command = nil)
34
+ def exec(command = nil, dry_run: false)
35
+ do_dry_run if dry_run
36
+
64
37
  with_private_key do
65
38
  system join(env_vars, ssh, user_and_host, command)
66
39
  end
67
40
  end
68
41
 
69
- def rsync(source, destination)
42
+ def rsync(source, destination, path:, dry_run: false)
43
+ do_dry_run if dry_run
44
+
70
45
  with_private_key do
71
46
  system join(
72
47
  env_vars,
73
- %(rsync #{options.args} -e "#{ssh}"),
74
- source.sub("#{service_name}:", "#{user_and_host}:"),
75
- destination.sub("#{service_name}:", "#{user_and_host}:")
48
+ %(rsync #{@rsync_args} -e "#{ssh}"),
49
+ source.sub("#{path}:", "#{user_and_host}:"),
50
+ destination.sub("#{path}:", "#{user_and_host}:")
76
51
  )
77
52
  end
78
53
  end
79
54
 
80
55
  private
56
+ def do_dry_run
57
+ @shell.say "Dry run", :green
58
+ @shell.say @params.to_yaml
59
+ exit
60
+ end
61
+
81
62
  def join(*parts)
82
63
  parts.flatten.compact.join(" ")
83
64
  end
@@ -110,12 +91,12 @@ module Envirobly
110
91
  credentials.fetch("session_token")
111
92
  )
112
93
 
113
- if options.shell.present?
114
- result = join "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{options.shell}'", result
94
+ if @exec_shell.present?
95
+ result = join "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{@exec_shell}'", result
115
96
  end
116
97
 
117
- if options.user.present?
118
- result = join "ENVIROBLY_SERVICE_SHELL_USER='#{options.user}'", result
98
+ if @exec_user.present?
99
+ result = join "ENVIROBLY_SERVICE_SHELL_USER='#{@exec_user}'", result
119
100
  end
120
101
 
121
102
  result
@@ -1,64 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "yaml"
4
-
5
3
  module Envirobly
6
4
  class Deployment
7
5
  include Colorize
8
6
 
9
7
  attr_reader :params, :shell
10
8
 
11
- def initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:)
9
+ def initialize(target:, commit:, shell:)
10
+ @target = target
12
11
  @commit = commit
13
- @config = Config.new
14
- @default_account = Defaults::Account.new(shell:)
15
- @default_project = Defaults::Project.new(shell:)
16
- @default_region = Defaults::Region.new(shell:)
17
12
  @shell = shell
13
+ @api = Api.new
14
+ @config = Config.new
15
+ end
18
16
 
19
- target = Target.new(
20
- default_account_id: @default_account.value,
21
- default_project_id: @default_project.value,
22
- default_region: @default_region.value,
23
- default_project_name: Defaults::Project.dirname,
24
- default_environ_name: commit.current_branch,
25
- account_id:,
26
- project_id:,
27
- region:,
28
- project_name:,
29
- environ_name:
30
- )
31
-
32
- if target.missing_params.include?(:account_id)
33
- target.account_id = @default_account.require_value
34
- end
35
-
36
- if target.missing_params.include?(:region)
37
- target.region = @default_region.require_value
38
- end
39
-
40
- target.ignored_params.each do |param|
41
- shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it"
42
- end
43
-
44
- @environ_name = target.environ_name
45
- @params = {
46
- account_id: target.account_id,
47
- project_id: target.project_id,
48
- project_name: target.project_name,
49
- region: target.region,
17
+ def perform(dry_run:)
18
+ params = {
19
+ account_id: @target.account_id,
20
+ project_name: @target.project_name,
21
+ region: @target.region,
50
22
  deployment: {
51
- environ_name: target.environ_name,
23
+ environ_name: @target.environ_name,
52
24
  commit_ref: @commit.ref,
53
25
  commit_time: @commit.time,
54
26
  commit_message: @commit.message,
55
27
  object_tree_checksum: @commit.object_tree_checksum,
56
- config: @config.merge(@environ_name).to_yaml
28
+ config: @config.merge(@target.environ_name).to_yaml
57
29
  }
58
30
  }
59
- end
60
31
 
61
- def perform(dry_run:)
62
32
  if dry_run
63
33
  shell.say "This is a dry run, nothing will be deployed.", :green
64
34
  end
@@ -72,17 +42,16 @@ module Envirobly
72
42
 
73
43
  if dry_run
74
44
  puts green("Config:")
75
- puts @params[:deployment][:config]
45
+ puts params[:deployment][:config]
76
46
 
77
47
  shell.say
78
- shell.say "Targeting:", :green
48
+ shell.say "Target:", :green
79
49
 
80
50
  targets_and_values = [
81
- [ "Account ID", @params[:account_id].to_s ],
82
- [ "Project ID", @params[:project_id].to_s ],
83
- [ "Region", @params[:region] ],
84
- [ "Project Name", @params[:project_name] ],
85
- [ "Environ Name", @params[:deployment][:environ_name] ]
51
+ [ "Account", @target.account_url ],
52
+ [ "Region", params[:region] ],
53
+ [ "Project", params[:project_name] ],
54
+ [ "Environ", params[:deployment][:environ_name] ]
86
55
  ]
87
56
 
88
57
  shell.print_table targets_and_values, borders: true
@@ -90,36 +59,30 @@ module Envirobly
90
59
  return
91
60
  end
92
61
 
93
- # Create deployment
94
- api = Api.new
95
-
96
62
  Duration.measure do
97
- response = api.create_deployment @params
63
+ # Create deployment
64
+ response = @api.create_deployment params
98
65
 
99
66
  print "Preparing project..."
100
67
 
101
- @default_account.save_if_none response.object.fetch("account_id")
102
- @default_project.save_if_none response.object.fetch("project_id")
103
- @default_region.save_if_none response.object.fetch("region")
104
-
105
68
  # Fetch credentials for build context upload
106
69
  @deployment_url = response.object.fetch("url")
107
- @credentials_response = api.get_deployment_with_delay_and_retry @deployment_url
70
+ @credentials_response = @api.get_deployment_with_delay_and_retry @deployment_url
108
71
  end
109
72
 
110
73
  credentials = @credentials_response.object.fetch("credentials")
111
74
  region = @credentials_response.object.fetch("region")
112
75
  bucket = @credentials_response.object.fetch("bucket")
113
- watch_deployment_url = @credentials_response.object.fetch("deployment_url")
114
76
 
115
77
  Duration.measure do
116
78
  # Upload build context
117
79
  Aws::S3.new(bucket:, region:, credentials:).push @commit
118
80
 
119
81
  # Perform deployment
120
- api.put_as_json @deployment_url
82
+ @api.put_as_json @deployment_url
121
83
  end
122
84
 
85
+ watch_deployment_url = @credentials_response.object.fetch("deployment_url")
123
86
  puts "Follow at #{watch_deployment_url}"
124
87
  end
125
88
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envirobly
4
+ class Name
5
+ NAME_FORMAT = /\A[a-z0-9\-_]+\z/i
6
+ ERROR_MESSAGE = "must contain only alphanumerical characters, dashes and underscores"
7
+
8
+ attr_reader :error
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ @error = nil
13
+ end
14
+
15
+ def validate
16
+ if @name =~ NAME_FORMAT
17
+ true
18
+ else
19
+ @error = ERROR_MESSAGE
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,60 +2,88 @@
2
2
 
3
3
  module Envirobly
4
4
  class Target
5
- attr_accessor :account_id, :project_id, :region
5
+ attr_accessor :account_url, :project_name, :region, :name
6
+ attr_reader :service_name, :shell
7
+
8
+ DEFAULT_NAME = ".default"
6
9
 
7
10
  def initialize(
8
- default_account_id: nil,
9
- default_project_id: nil,
10
- default_region: nil,
11
- default_project_name: nil,
12
- default_environ_name: nil,
13
- account_id: nil,
14
- project_id: nil,
11
+ path = nil,
12
+ account_url: nil,
15
13
  region: nil,
16
14
  project_name: nil,
17
- environ_name: nil
15
+ default_environ_name: nil,
16
+ default_project_name: nil,
17
+ config_path: Config::TARGETS_PATH,
18
+ context: nil,
19
+ shell: nil
18
20
  )
19
- @default_account_id = default_account_id
20
- @default_project_id = default_project_id
21
- @default_region = default_region
22
- @default_project_name = default_project_name
23
- @default_environ_name = default_environ_name
24
- @account_id = account_id
25
- @project_id = project_id
21
+ @account_url = account_url
26
22
  @region = region
27
23
  @project_name = project_name
28
- @environ_name = environ_name
24
+ @default_environ_name = default_environ_name
25
+ @default_project_name = default_project_name
26
+ @config_path = config_path
27
+ @context = context
28
+ @name = DEFAULT_NAME
29
+ @shell = shell
30
+
31
+ load_path path
32
+ end
33
+
34
+ def errors(attributes = %i[ name project_name environ_name ])
35
+ [].tap do |result|
36
+ Array(attributes).each_with_index do |attr, index|
37
+ value = send attr
38
+
39
+ next if index.zero? && value == DEFAULT_NAME
40
+
41
+ name = Name.new(value)
42
+
43
+ unless name.validate
44
+ result << "Name '#{value}' #{name.error}"
45
+ end
46
+ end
47
+ end.uniq
48
+ end
49
+
50
+ def render_and_exit_on_errors!
51
+ messages = errors
52
+ return if messages.empty?
53
+
54
+ messages.each do |message|
55
+ shell.say_error message
56
+ end
57
+
58
+ exit 1
29
59
  end
30
60
 
31
61
  def missing_params
32
62
  [].tap do |result|
33
- if project_id.blank? && account_id.blank?
34
- result << :account_id
63
+ if account_url.blank?
64
+ result << :account_url
35
65
  end
36
66
 
37
- if project_id.blank? && region.blank?
67
+ if region.blank?
38
68
  result << :region
39
69
  end
40
70
  end
41
71
  end
42
72
 
43
- def account_id
44
- return if @project_id
45
-
46
- @account_id || @default_account_id
73
+ def account_url
74
+ @account_url.presence || stored_value_for("account_url")
47
75
  end
48
76
 
49
- def project_id
50
- return if @project_id.blank? && (@account_id.present? || @project_name.present?)
51
-
52
- @project_id || @default_project_id
77
+ def account_id
78
+ if account_url =~ /accounts\/(\d)+/i
79
+ $1.to_i
80
+ else
81
+ nil
82
+ end
53
83
  end
54
84
 
55
85
  def project_name
56
- return if @project_id
57
-
58
- @project_name.presence || @default_project_name
86
+ @project_name.presence || stored_value_for("project_name").presence || @default_project_name
59
87
  end
60
88
 
61
89
  def environ_name
@@ -63,25 +91,158 @@ module Envirobly
63
91
  end
64
92
 
65
93
  def region
66
- return if @project_id
94
+ @region.presence || stored_value_for("region")
95
+ end
67
96
 
68
- @region || @default_region
97
+ def save
98
+ save_attribute "account_url"
99
+ save_attribute "project_name"
100
+ save_attribute "region"
69
101
  end
70
102
 
71
- def ignored_params
72
- [].tap do |result|
73
- if @account_id && @project_id
74
- result << :account_id
103
+ def configure!(missing_only: false)
104
+ configure_account unless missing_only && stored_value_for("account_url").present?
105
+ configure_project_name unless missing_only && stored_value_for("project_name").present?
106
+ configure_region unless missing_only && stored_value_for("region").present?
107
+ end
108
+
109
+ private
110
+ def storage_dir
111
+ @config_path.join(@name)
112
+ end
113
+
114
+ def stored_value_for(type)
115
+ File.read(storage_dir.join(type)).strip
116
+ rescue Errno::ENOENT
117
+ nil
118
+ end
119
+
120
+ def save_attribute(type)
121
+ FileUtils.mkdir_p storage_dir
122
+ File.write storage_dir.join(type), send(type)
123
+ end
124
+
125
+ def load_path(path)
126
+ return if path.blank?
127
+
128
+ parts = path.split("/").map &:strip
129
+
130
+ if @context == :service
131
+ case parts.size
132
+ when 1
133
+ @service_name = parts.first
134
+ when 2
135
+ @environ_name, @service_name = parts
136
+ when 3
137
+ @name, @environ_name, @service_name = parts
138
+ @default_project_name = @name
139
+ end
140
+
141
+ return
75
142
  end
76
143
 
77
- if @project_id && @region
78
- result << :region
144
+ case parts.size
145
+ when 1
146
+ if path.end_with?("/")
147
+ @name = parts.first
148
+ @default_project_name = parts.first
149
+ else
150
+ @environ_name = parts.first
151
+ end
152
+ when 2
153
+ @name, @environ_name = parts
154
+ @default_project_name = @name
79
155
  end
156
+ end
80
157
 
81
- if @project_id && @project_name.present?
82
- result << :project_name
158
+ def configure_account
159
+ shell.say "Configuring "
160
+ shell.say "#{@name} ", :green
161
+ shell.say "deploy target"
162
+ shell.say
163
+
164
+ api = Envirobly::Api.new
165
+ accounts = api.list_accounts
166
+
167
+ if accounts.object.blank?
168
+ shell.say_error "Please connect an AWS account to your Envirobly account first."
169
+ exit 1
83
170
  end
171
+
172
+ data = [ [ "ID", "Name", "AWS number", "URL" ] ] +
173
+ accounts.object.pluck("id", "name", "aws_id", "url")
174
+
175
+ shell.say "Available accounts:"
176
+ shell.print_table data, borders: true
177
+
178
+ limited_to = accounts.object.pluck("id").map(&:to_s)
179
+ account_id = send(:account_id).to_s.presence || limited_to.first
180
+
181
+ begin
182
+ account_id = shell.ask("Choose Account ID:", limited_to:, default: account_id).to_i
183
+ rescue Interrupt
184
+ shell.say_error "Cancelled", :red
185
+ exit
186
+ end
187
+
188
+ accounts.object.each do |account|
189
+ if account_id == account["id"]
190
+ @account_url = account["url"]
191
+ break
192
+ end
193
+ end
194
+
195
+ save_attribute "account_url"
196
+ end
197
+
198
+ def configure_project_name
199
+ result = nil
200
+
201
+ while result.nil?
202
+ begin
203
+ result = shell.ask("Name your project:", default: project_name)
204
+ rescue interrupt
205
+ shell.say_error "cancelled", :red
206
+ end
207
+
208
+ name = Name.new(result)
209
+ unless name.validate
210
+ result = nil
211
+ shell.say_error "Name #{name.error}"
212
+ end
213
+ end
214
+
215
+ @project_name = result
216
+ save_attribute "project_name"
217
+ end
218
+
219
+ def configure_region
220
+ api = Envirobly::Api.new
221
+ response = api.list_regions
222
+
223
+ shell.say "Choose region:"
224
+ shell.print_table [ [ "Name", "Location", "Group" ] ] +
225
+ response.object.pluck("code", "title", "group_title"), borders: true
226
+
227
+ code = nil
228
+ limited_to = response.object.pluck("code")
229
+
230
+ while code.nil?
231
+ begin
232
+ code = shell.ask("Region name:", default: region.presence || "us-east-1")
233
+ rescue Interrupt
234
+ shell.say_error "Cancelled", :red
235
+ exit
236
+ end
237
+
238
+ unless code.in?(limited_to)
239
+ shell.say_error "'#{code}' is not a supported region, please try again"
240
+ code = nil
241
+ end
242
+ end
243
+
244
+ @region = code
245
+ save_attribute "region"
84
246
  end
85
- end
86
247
  end
87
248
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Envirobly
4
- VERSION = "1.10.0"
4
+ VERSION = "1.11.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envirobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi
@@ -171,14 +171,12 @@ files:
171
171
  - lib/envirobly/container_shell.rb
172
172
  - lib/envirobly/default.rb
173
173
  - lib/envirobly/defaults.rb
174
- - lib/envirobly/defaults/account.rb
175
- - lib/envirobly/defaults/project.rb
176
- - lib/envirobly/defaults/region.rb
177
174
  - lib/envirobly/deployment.rb
178
175
  - lib/envirobly/duration.rb
179
176
  - lib/envirobly/git.rb
180
177
  - lib/envirobly/git/commit.rb
181
178
  - lib/envirobly/git/unstaged.rb
179
+ - lib/envirobly/name.rb
182
180
  - lib/envirobly/numeric.rb
183
181
  - lib/envirobly/secret.rb
184
182
  - lib/envirobly/target.rb
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Envirobly::Defaults::Account < Envirobly::Default
4
- include Envirobly::Colorize
5
-
6
- def require_value
7
- api = Envirobly::Api.new
8
- accounts = api.list_accounts
9
-
10
- if accounts.object.blank?
11
- shell.say_error "Please connect an AWS account to your Envirobly account first."
12
- exit 1
13
- end
14
-
15
- # If only one account exists, it will be used
16
- id = accounts.object.first.fetch("id")
17
-
18
- if accounts.object.size > 1
19
- puts "Choose default account to deploy this project to:"
20
-
21
- data = [ [ "ID", "Name", "AWS number", "URL" ] ] +
22
- accounts.object.pluck("id", "name", "aws_id", "url")
23
-
24
- shell.print_table data, borders: true
25
-
26
- limited_to = accounts.object.pluck("id").map(&:to_s)
27
-
28
- begin
29
- id = shell.ask("Type in the account ID:", limited_to:).to_i
30
- rescue Interrupt
31
- shell.say_error "Cancelled"
32
- exit
33
- end
34
- end
35
-
36
- save id
37
-
38
- shell.say "Account ##{id} set as project default "
39
- shell.say green_check
40
-
41
- id
42
- end
43
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Envirobly::Defaults::Project < Envirobly::Default
4
- def self.dirname
5
- File.basename(Dir.pwd)
6
- end
7
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Envirobly::Defaults::Region < Envirobly::Default
4
- include Envirobly::Colorize
5
-
6
- def require_value
7
- api = Envirobly::Api.new
8
- response = api.list_regions
9
-
10
- shell.say "Choose default project region to deploy to:"
11
- shell.print_table [ [ "Name", "Location", "Group" ] ] +
12
- response.object.pluck("code", "title", "group_title"), borders: true
13
-
14
- code = nil
15
- limited_to = response.object.pluck("code")
16
-
17
- while code.nil?
18
- begin
19
- code = shell.ask("Type in the region name:", default: "us-east-1")
20
- rescue Interrupt
21
- shell.say_error "Cancelled"
22
- exit
23
- end
24
-
25
- unless code.in?(limited_to)
26
- shell.say_error "'#{code}' is not a supported region, please try again"
27
- code = nil
28
- end
29
- end
30
-
31
- save code
32
-
33
- shell.say "Region '#{code}' set as project default "
34
- shell.say green_check
35
-
36
- code
37
- end
38
-
39
- private
40
- def cast_value(value)
41
- value.to_s
42
- end
43
- end