envirobly 1.2.0 → 1.3.1

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: 58cece10b3dc2908e0bce6a78f509463c8261fa34d54c9a45059b95205c494d3
4
- data.tar.gz: 71b06913da6f29967a5f779c62a76423f30242474daeda744b34be44f7ba494a
3
+ metadata.gz: 2991e127dfd64a68b47720bf70561343e3b7107304d9f5da9c1423cd4a3f0105
4
+ data.tar.gz: 8d80a93f0af7427bd44668aaf47b68598ae9a62abd27168a35b52e9102cf9bf2
5
5
  SHA512:
6
- metadata.gz: d67d5afc046a25396f822f86d17d584172468e277ff5626efbb1d11fadffdad86e821118b2d8dc0ee89f33b9d316d999fce182f5001be7e7029977aeb3a9604c
7
- data.tar.gz: 224f58f13842244a423fbef3ab69540a97969a15c168e09a090f8a8c255340ec65657db6bf680d6c384d2dbda804d51708dc2bc99928ac03785495e00341837f
6
+ metadata.gz: ab2ba4141f8bbc95fa907bdbfe78d30a9b1600862c9a97a34412de4bc295a4db6a8d46d52d0c97bc744792b15d57b051cf467b7d638287fb2c23e26593832e8f
7
+ data.tar.gz: d9a69cb24f0d30fa89bdef0dfd06bfb07c78bc99f9fd32e9b2a2fbcfb136f81e1d72adfc39548b834b1c9ebe499fc6bb429e0dd5f9eeb1272448cf21f0018f26
data/lib/envirobly/api.rb CHANGED
@@ -26,6 +26,10 @@ class Envirobly::Api
26
26
  post_as_json(api_v1_deployments_url, params:, headers: authorization_headers)
27
27
  end
28
28
 
29
+ def create_service_shell_connection(params)
30
+ post_as_json(api_v1_service_shell_connections_url, params:, headers: authorization_headers)
31
+ end
32
+
29
33
  def list_accounts
30
34
  get_as_json api_v1_accounts_url, headers: authorization_headers
31
35
  end
@@ -98,6 +102,10 @@ class Envirobly::Api
98
102
  api_url_for "v1/instance_types", query: "region=#{region}"
99
103
  end
100
104
 
105
+ def api_v1_service_shell_connections_url
106
+ api_url_for "v1/service_shell_connections"
107
+ end
108
+
101
109
  def api_url_for(path, query: nil)
102
110
  URI::HTTPS.build(host: HOST, path: "/api/#{path}", query:)
103
111
  end
@@ -126,8 +134,8 @@ class Envirobly::Api
126
134
  (200..299).include?(code.to_i)
127
135
  end
128
136
 
129
- if @exit_on_error && !response.success? && response.object[:error_message].present?
130
- puts response.object[:error_message] # TODO: Replace with shell.say_error
137
+ if @exit_on_error && !response.success? && response.object["error_message"].present?
138
+ puts response.object["error_message"] # TODO: Replace with shell.say_error
131
139
  exit 1
132
140
  end
133
141
  end
@@ -53,7 +53,7 @@ class Envirobly::Cli::Main < Envirobly::Base
53
53
  end
54
54
  end
55
55
 
56
- desc "instance_types [region]", "List instance types in a given region, including price and performance characteristics."
56
+ desc "instance_types [REGION]", "List instance types in the given region, including price and performance characteristics."
57
57
  def instance_types(region = nil)
58
58
  default_region = Envirobly::Defaults::Region.new(shell:)
59
59
  region = region.presence || default_region.require_if_none
@@ -88,7 +88,7 @@ class Envirobly::Cli::Main < Envirobly::Base
88
88
  commit = Envirobly::Git::Commit.new options.commit
89
89
 
90
90
  unless commit.exists?
91
- say_error "Commit '#{commit.ref}' doesn't exist in this repository. Aborting."
91
+ say_error "Commit '#{commit.ref}' doesn't exist in this repository"
92
92
  exit 1
93
93
  end
94
94
 
@@ -106,11 +106,26 @@ class Envirobly::Cli::Main < Envirobly::Base
106
106
  deployment.perform(dry_run: options.dry_run)
107
107
  end
108
108
 
109
- desc "pull [REGION] [BUCKET] [REF] [PATH]", "Download build context. Used by Envirobly builders."
109
+ desc "pull REGION BUCKET REF PATH", "Download build context. Used by Envirobly builders."
110
110
  def pull(region, bucket, ref, path)
111
111
  Envirobly::Duration.measure("Build context download took %s") do
112
- s3 = Envirobly::Aws::S3.new(region:, bucket:)
113
- s3.pull ref, path
112
+ Envirobly::Aws::S3.new(region:, bucket:).pull ref, path
114
113
  end
115
114
  end
115
+
116
+ desc "exec SERVICE_NAME [COMMAND] [ARG...]", <<~TXT
117
+ Start interactive service shell when launched without arguments or execute a one-off command.
118
+ Keep in mind, your container might not have a shell installed. In such cases you won't be able
119
+ to start an interactive session.
120
+ TXT
121
+ method_option :account_id, type: :numeric
122
+ method_option :project_id, type: :numeric
123
+ method_option :project_name, type: :string
124
+ method_option :environ_name, type: :string
125
+ method_option :instance_slot, type: :numeric, default: 0
126
+ method_option :shell, type: :string
127
+ method_option :user, type: :string
128
+ def exec(service_name, *command)
129
+ Envirobly::ContainerShell.new(service_name, command, options).connect
130
+ end
116
131
  end
@@ -0,0 +1,66 @@
1
+ class Envirobly::ContainerShell
2
+ CMD_TEMLATE =
3
+ "AWS_ACCESS_KEY_ID='%s' " +
4
+ "AWS_SECRET_ACCESS_KEY='%s' " +
5
+ "AWS_SESSION_TOKEN='%s' " +
6
+ "ssh -i %s " +
7
+ "envirobly-service@%s " +
8
+ "-o StrictHostKeyChecking=accept-new " +
9
+ "-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id %s --region %s'"
10
+
11
+ def initialize(service_name, command, options)
12
+ @command = command
13
+ @options = options
14
+ commit = Envirobly::Git::Commit.new "HEAD"
15
+ @params = {
16
+ project: {
17
+ account_id: options.account_id || Envirobly::Defaults::Account.new.id,
18
+ name: options.project_name || File.basename(Dir.pwd), # TODO: Extract into Defaults::ProjectName
19
+ id: options.project_id
20
+ },
21
+ environ: { name: options.environ_name || commit.current_branch },
22
+ service: { name: service_name },
23
+ instance: { slot: options.instance_slot }
24
+ }
25
+
26
+ if options.project_name.blank? && options.account_id.blank? && options.project_id.blank?
27
+ @params[:project][:id] = Envirobly::Defaults::Project.new.id
28
+ end
29
+ end
30
+
31
+ def connect
32
+ api = Envirobly::Api.new
33
+ response = api.create_service_shell_connection @params
34
+ ssh_params = response.object
35
+
36
+ Tempfile.create do |tempkey|
37
+ tempkey.write ssh_params.fetch("instance").fetch("private_key")
38
+ tempkey.flush
39
+
40
+ cmd = sprintf(
41
+ CMD_TEMLATE,
42
+ ssh_params.fetch("open_tunnel_credentials").fetch("access_key_id"),
43
+ ssh_params.fetch("open_tunnel_credentials").fetch("secret_access_key"),
44
+ ssh_params.fetch("open_tunnel_credentials").fetch("session_token"),
45
+ tempkey.path,
46
+ ssh_params.fetch("instance").fetch("private_ipv4"),
47
+ ssh_params.fetch("instance").fetch("aws_id"),
48
+ ssh_params.fetch("region")
49
+ )
50
+
51
+ if @options.shell.present?
52
+ cmd = "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{@options.shell}' #{cmd} -o SendEnv=ENVIROBLY_SERVICE_INTERACTIVE_SHELL"
53
+ end
54
+
55
+ if @options.user.present?
56
+ cmd = "ENVIROBLY_SERVICE_SHELL_USER='#{@options.user}' #{cmd} -o SendEnv=ENVIROBLY_SERVICE_SHELL_USER"
57
+ end
58
+
59
+ if @command.present?
60
+ cmd = "#{cmd} #{@command.join(" ")}"
61
+ end
62
+
63
+ system cmd
64
+ end
65
+ end
66
+ end
@@ -87,8 +87,7 @@ class Envirobly::Deployment
87
87
 
88
88
  Envirobly::Duration.measure do
89
89
  # Upload build context
90
- s3 = Envirobly::Aws::S3.new(bucket:, region:, credentials:)
91
- s3.push @commit
90
+ Envirobly::Aws::S3.new(bucket:, region:, credentials:).push @commit
92
91
 
93
92
  # Perform deployment
94
93
  api.put_as_json @deployment_url
@@ -1,3 +1,3 @@
1
1
  module Envirobly
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.1"
3
3
  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.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi
@@ -168,6 +168,7 @@ files:
168
168
  - lib/envirobly/cli/main.rb
169
169
  - lib/envirobly/colorize.rb
170
170
  - lib/envirobly/config.rb
171
+ - lib/envirobly/container_shell.rb
171
172
  - lib/envirobly/default.rb
172
173
  - lib/envirobly/defaults.rb
173
174
  - lib/envirobly/defaults/account.rb
@@ -198,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
199
  - !ruby/object:Gem::Version
199
200
  version: '0'
200
201
  requirements: []
201
- rubygems_version: 3.6.9
202
+ rubygems_version: 3.7.1
202
203
  specification_version: 4
203
204
  summary: Envirobly command line interface
204
205
  test_files: []