envirobly 1.3.0 → 1.4.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 +4 -4
- data/lib/envirobly/cli/main.rb +22 -1
- data/lib/envirobly/container_shell.rb +82 -36
- data/lib/envirobly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 826c2cc2bbd5fe59d2e90e2ce7860025c327794a214735b08090b91008b3908e
|
4
|
+
data.tar.gz: d3390a6c48429e76a1cd1bc2f5a1d00a237996d63398f9cd521f512b0bc09964
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74d0637bc3e704e07e2927f37ebbd68cc8c694bf1269f2a7d73536480798aad3985c91320654dac18b14532399d744820c4075d87f9cf7d072099db5908c264a
|
7
|
+
data.tar.gz: '08e97323c8c3ceffa549e64f5580d2edd33ebb6dac899a83773f92ae599ae33a645980ded7bfa3d93dfa019c0492a5314287a844cb64c5fee409a9cdb2b56cbc'
|
data/lib/envirobly/cli/main.rb
CHANGED
@@ -126,6 +126,27 @@ class Envirobly::Cli::Main < Envirobly::Base
|
|
126
126
|
method_option :shell, type: :string
|
127
127
|
method_option :user, type: :string
|
128
128
|
def exec(service_name, *command)
|
129
|
-
Envirobly::ContainerShell.new(service_name,
|
129
|
+
Envirobly::ContainerShell.new(service_name, options).exec(command)
|
130
|
+
end
|
131
|
+
|
132
|
+
desc "rsync [SERVICE_NAME:]SOURCE_PATH [SERVICE_NAME:]DESTINATION_PATH", <<~TXT
|
133
|
+
Synchronize files between you and your service's data volume.
|
134
|
+
TXT
|
135
|
+
method_option :account_id, type: :numeric
|
136
|
+
method_option :project_id, type: :numeric
|
137
|
+
method_option :project_name, type: :string
|
138
|
+
method_option :environ_name, type: :string
|
139
|
+
method_option :args, type: :string, default: "-avzP"
|
140
|
+
def rsync(source, destination)
|
141
|
+
service_name = nil
|
142
|
+
|
143
|
+
[ source, destination ].each do |path|
|
144
|
+
if path =~ /\A([a-z0-9\-_]+):/i
|
145
|
+
service_name = $1
|
146
|
+
break
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
Envirobly::ContainerShell.new(service_name, options).rsync(source, destination)
|
130
151
|
end
|
131
152
|
end
|
@@ -1,17 +1,25 @@
|
|
1
1
|
class Envirobly::ContainerShell
|
2
|
-
|
3
|
-
"AWS_ACCESS_KEY_ID='%s'
|
4
|
-
"AWS_SECRET_ACCESS_KEY='%s'
|
5
|
-
"AWS_SESSION_TOKEN='%s'
|
6
|
-
|
7
|
-
|
8
|
-
"
|
2
|
+
AWS_ENV = [
|
3
|
+
"AWS_ACCESS_KEY_ID='%s'",
|
4
|
+
"AWS_SECRET_ACCESS_KEY='%s'",
|
5
|
+
"AWS_SESSION_TOKEN='%s'"
|
6
|
+
]
|
7
|
+
SSH = [
|
8
|
+
"ssh -i %s",
|
9
|
+
"-o StrictHostKeyChecking=accept-new",
|
10
|
+
"-o SendEnv=ENVIROBLY_SERVICE_INTERACTIVE_SHELL",
|
11
|
+
"-o SendEnv=ENVIROBLY_SERVICE_SHELL_USER",
|
9
12
|
"-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id %s --region %s'"
|
13
|
+
]
|
14
|
+
USER_AND_HOST = "envirobly-service@%s"
|
10
15
|
|
11
|
-
|
12
|
-
|
16
|
+
attr_reader :options, :service_name
|
17
|
+
|
18
|
+
def initialize(service_name, options)
|
19
|
+
@service_name = service_name
|
13
20
|
@options = options
|
14
21
|
commit = Envirobly::Git::Commit.new "HEAD"
|
22
|
+
|
15
23
|
@params = {
|
16
24
|
project: {
|
17
25
|
account_id: options.account_id || Envirobly::Defaults::Account.new.id,
|
@@ -20,7 +28,7 @@ class Envirobly::ContainerShell
|
|
20
28
|
},
|
21
29
|
environ: { name: options.environ_name || commit.current_branch },
|
22
30
|
service: { name: service_name },
|
23
|
-
instance: { slot: options.instance_slot }
|
31
|
+
instance: { slot: options.instance_slot || 0 }
|
24
32
|
}
|
25
33
|
|
26
34
|
if options.project_name.blank? && options.account_id.blank? && options.project_id.blank?
|
@@ -28,39 +36,77 @@ class Envirobly::ContainerShell
|
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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")
|
39
|
+
def exec(command = nil)
|
40
|
+
with_private_key do
|
41
|
+
system join(env_vars, ssh, user_and_host, command)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def rsync(source, destination)
|
46
|
+
with_private_key do
|
47
|
+
system join(
|
48
|
+
env_vars,
|
49
|
+
%(rsync #{options.args} -e "#{ssh}"),
|
50
|
+
source.sub("#{service_name}:", "#{user_and_host}:"),
|
51
|
+
destination.sub("#{service_name}:", "#{user_and_host}:")
|
49
52
|
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def join(*parts)
|
58
|
+
parts.flatten.compact.join(" ")
|
59
|
+
end
|
60
|
+
|
61
|
+
def connect_data
|
62
|
+
@connect_data ||= begin
|
63
|
+
api = Envirobly::Api.new
|
64
|
+
api.create_service_shell_connection(@params).object
|
65
|
+
end
|
66
|
+
end
|
50
67
|
|
51
|
-
|
52
|
-
|
68
|
+
def with_private_key
|
69
|
+
Tempfile.create do |file|
|
70
|
+
file.write connect_data.fetch("instance").fetch("private_key")
|
71
|
+
file.flush
|
72
|
+
|
73
|
+
@private_key_path = file.path
|
74
|
+
|
75
|
+
yield
|
53
76
|
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def env_vars
|
80
|
+
credentials = connect_data.fetch("open_tunnel_credentials")
|
81
|
+
|
82
|
+
result = sprintf(
|
83
|
+
join(AWS_ENV),
|
84
|
+
credentials.fetch("access_key_id"),
|
85
|
+
credentials.fetch("secret_access_key"),
|
86
|
+
credentials.fetch("session_token")
|
87
|
+
)
|
54
88
|
|
55
|
-
if
|
56
|
-
|
89
|
+
if options.shell.present?
|
90
|
+
result = join "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{options.shell}'", result
|
57
91
|
end
|
58
92
|
|
59
|
-
if
|
60
|
-
|
93
|
+
if options.user.present?
|
94
|
+
result = join "ENVIROBLY_SERVICE_SHELL_USER='#{options.user}'", result
|
61
95
|
end
|
62
96
|
|
63
|
-
|
97
|
+
result
|
98
|
+
end
|
99
|
+
|
100
|
+
def ssh
|
101
|
+
sprintf(
|
102
|
+
join(SSH),
|
103
|
+
@private_key_path,
|
104
|
+
connect_data.fetch("instance").fetch("aws_id"),
|
105
|
+
connect_data.fetch("region")
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
def user_and_host
|
110
|
+
sprintf USER_AND_HOST, connect_data.fetch("instance").fetch("private_ipv4")
|
64
111
|
end
|
65
|
-
end
|
66
112
|
end
|
data/lib/envirobly/version.rb
CHANGED
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starsi
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
|
-
rubygems_version: 3.
|
202
|
+
rubygems_version: 3.7.1
|
203
203
|
specification_version: 4
|
204
204
|
summary: Envirobly command line interface
|
205
205
|
test_files: []
|