envirobly 1.0.0 → 1.2.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/access_token.rb +1 -1
- data/lib/envirobly/api.rb +19 -3
- data/lib/envirobly/cli/main.rb +26 -17
- data/lib/envirobly/config.rb +1 -1
- data/lib/envirobly/numeric.rb +14 -0
- data/lib/envirobly/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58cece10b3dc2908e0bce6a78f509463c8261fa34d54c9a45059b95205c494d3
|
4
|
+
data.tar.gz: 71b06913da6f29967a5f779c62a76423f30242474daeda744b34be44f7ba494a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d67d5afc046a25396f822f86d17d584172468e277ff5626efbb1d11fadffdad86e821118b2d8dc0ee89f33b9d316d999fce182f5001be7e7029977aeb3a9604c
|
7
|
+
data.tar.gz: 224f58f13842244a423fbef3ab69540a97969a15c168e09a090f8a8c255340ec65657db6bf680d6c384d2dbda804d51708dc2bc99928ac03785495e00341837f
|
@@ -69,7 +69,7 @@ class Envirobly::AccessToken
|
|
69
69
|
exit
|
70
70
|
end
|
71
71
|
|
72
|
-
api = Envirobly::Api.new(access_token: self)
|
72
|
+
api = Envirobly::Api.new(access_token: self, exit_on_error: false)
|
73
73
|
|
74
74
|
# TODO: Eventually replace with custom `whoami` API that returns name, email...
|
75
75
|
if api.list_accounts.success?
|
data/lib/envirobly/api.rb
CHANGED
@@ -8,7 +8,8 @@ class Envirobly::Api
|
|
8
8
|
USER_AGENT = "Envirobly CLI v#{Envirobly::VERSION}"
|
9
9
|
CONTENT_TYPE = "application/json"
|
10
10
|
|
11
|
-
def initialize(access_token: Envirobly::AccessToken.new)
|
11
|
+
def initialize(access_token: Envirobly::AccessToken.new, exit_on_error: true)
|
12
|
+
@exit_on_error = exit_on_error
|
12
13
|
@access_token = access_token
|
13
14
|
end
|
14
15
|
|
@@ -33,6 +34,10 @@ class Envirobly::Api
|
|
33
34
|
get_as_json api_v1_regions_url, headers: authorization_headers
|
34
35
|
end
|
35
36
|
|
37
|
+
def list_instance_types(region)
|
38
|
+
get_as_json api_v1_instance_types_url(region), headers: authorization_headers
|
39
|
+
end
|
40
|
+
|
36
41
|
MAX_RETRIES = 30
|
37
42
|
SHORT_RETRY_INTERVAL = 2.seconds
|
38
43
|
LONG_RETRY_INTERVAL = 6.seconds
|
@@ -89,8 +94,12 @@ class Envirobly::Api
|
|
89
94
|
api_url_for "v1/regions"
|
90
95
|
end
|
91
96
|
|
92
|
-
def
|
93
|
-
|
97
|
+
def api_v1_instance_types_url(region)
|
98
|
+
api_url_for "v1/instance_types", query: "region=#{region}"
|
99
|
+
end
|
100
|
+
|
101
|
+
def api_url_for(path, query: nil)
|
102
|
+
URI::HTTPS.build(host: HOST, path: "/api/#{path}", query:)
|
94
103
|
end
|
95
104
|
|
96
105
|
def request(url, type:, headers: {})
|
@@ -109,11 +118,18 @@ class Envirobly::Api
|
|
109
118
|
http.request(request).tap do |response|
|
110
119
|
def response.object
|
111
120
|
@json_parsed_body ||= JSON.parse(body)
|
121
|
+
rescue
|
122
|
+
@json_parsed_body = { error_message: body }
|
112
123
|
end
|
113
124
|
|
114
125
|
def response.success?
|
115
126
|
(200..299).include?(code.to_i)
|
116
127
|
end
|
128
|
+
|
129
|
+
if @exit_on_error && !response.success? && response.object[:error_message].present?
|
130
|
+
puts response.object[:error_message] # TODO: Replace with shell.say_error
|
131
|
+
exit 1
|
132
|
+
end
|
117
133
|
end
|
118
134
|
end
|
119
135
|
|
data/lib/envirobly/cli/main.rb
CHANGED
@@ -53,6 +53,26 @@ 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."
|
57
|
+
def instance_types(region = nil)
|
58
|
+
default_region = Envirobly::Defaults::Region.new(shell:)
|
59
|
+
region = region.presence || default_region.require_if_none
|
60
|
+
|
61
|
+
api = Envirobly::Api.new
|
62
|
+
table_data = api.list_instance_types(region).object.map do |item|
|
63
|
+
[
|
64
|
+
item["code"],
|
65
|
+
item["vcpu"],
|
66
|
+
Envirobly::Numeric.new(item["memory"], short: true),
|
67
|
+
Envirobly::Numeric.new(item["monthly_price"]),
|
68
|
+
item["group"]
|
69
|
+
]
|
70
|
+
end
|
71
|
+
|
72
|
+
print_table [ [ "Name", "vCPU", "Memory (GB)", "Monthly price ($)", "Group" ] ] +
|
73
|
+
table_data, borders: true
|
74
|
+
end
|
75
|
+
|
56
76
|
desc "deploy [ENVIRON_NAME]", <<~TXT
|
57
77
|
Deploy to environ identified by name.
|
58
78
|
Name can contain letters, numbers, dashes or underscores.
|
@@ -60,7 +80,8 @@ class Envirobly::Cli::Main < Envirobly::Base
|
|
60
80
|
TXT
|
61
81
|
method_option :account_id, type: :numeric
|
62
82
|
method_option :region, type: :string
|
63
|
-
method_option :
|
83
|
+
method_option :project_id, type: :numeric
|
84
|
+
method_option :project_name, type: :string
|
64
85
|
method_option :commit, type: :string, default: "HEAD"
|
65
86
|
method_option :dry_run, type: :boolean, default: false
|
66
87
|
def deploy(environ_name = nil)
|
@@ -73,31 +94,19 @@ class Envirobly::Cli::Main < Envirobly::Base
|
|
73
94
|
|
74
95
|
Envirobly::AccessToken.new(shell:).require!
|
75
96
|
|
76
|
-
environ_name = environ_name.presence || commit.current_branch
|
77
|
-
project_name = nil
|
78
|
-
project_id = nil
|
79
|
-
|
80
|
-
if options.project.present?
|
81
|
-
if options.project =~ Envirobly::Defaults::Project.regexp
|
82
|
-
project_id = $1.to_i
|
83
|
-
else
|
84
|
-
project_name = options.project
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
97
|
deployment = Envirobly::Deployment.new(
|
89
98
|
account_id: options.account_id,
|
90
99
|
region: options.region,
|
91
|
-
|
92
|
-
|
93
|
-
|
100
|
+
project_id: options.project_id,
|
101
|
+
project_name: options.project_name,
|
102
|
+
environ_name: environ_name.presence || commit.current_branch,
|
94
103
|
commit:,
|
95
104
|
shell:
|
96
105
|
)
|
97
106
|
deployment.perform(dry_run: options.dry_run)
|
98
107
|
end
|
99
108
|
|
100
|
-
desc "pull", "Download build context"
|
109
|
+
desc "pull [REGION] [BUCKET] [REF] [PATH]", "Download build context. Used by Envirobly builders."
|
101
110
|
def pull(region, bucket, ref, path)
|
102
111
|
Envirobly::Duration.measure("Build context download took %s") do
|
103
112
|
s3 = Envirobly::Aws::S3.new(region:, bucket:)
|
data/lib/envirobly/config.rb
CHANGED
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starsi
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/envirobly/git.rb
|
179
179
|
- lib/envirobly/git/commit.rb
|
180
180
|
- lib/envirobly/git/unstaged.rb
|
181
|
+
- lib/envirobly/numeric.rb
|
181
182
|
- lib/envirobly/version.rb
|
182
183
|
homepage: https://github.com/envirobly/envirobly-cli
|
183
184
|
licenses:
|
@@ -197,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
198
|
- !ruby/object:Gem::Version
|
198
199
|
version: '0'
|
199
200
|
requirements: []
|
200
|
-
rubygems_version: 3.6.
|
201
|
+
rubygems_version: 3.6.9
|
201
202
|
specification_version: 4
|
202
203
|
summary: Envirobly command line interface
|
203
204
|
test_files: []
|