gleis 0.5.0 → 0.6.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: 130f0b723f904109cb4cb38df148a8dc5a7748e40e3e4106ea646a004ccf1aa8
4
- data.tar.gz: 2a9754ec31b238984825eb7d6a22f54e90528de1b3feb6c178f765bb18375057
3
+ metadata.gz: dd8f6576940149755d70e4ea02a3f5bcf7ab4e525464f028586a834f45611865
4
+ data.tar.gz: dc3be857698d158c6a52980a2689946484ca2091ada419b98c384eb3c82fefbe
5
5
  SHA512:
6
- metadata.gz: b122513b42305f9764f184e65772db36fb7bcec1743e9404b3836c8c78d2efe0ed01f7a1c9445ddf83a4a2032b816c0b54fa245fa3af87b840d99234ed76c297
7
- data.tar.gz: 5cb296c2bfcf9529328a7efaf73efa34963deffbf1bb7097d5fd831820089707f79cd077ab91e4fe3a2235bdbfa1ecc526da95051509d4f55b4ac36545d5fe04
6
+ metadata.gz: 442e5c846df04518a366ac19cbdb077f1fb439366526f3d6f1983832864089e2af0d98ef1044f83a04e60b868881d61635e305d1f5663a1ab1e5fa7da6b15c9f
7
+ data.tar.gz: 00dc1fb43a246242db2e70f1a35dce3af1c98ce3202d2ec7d954866263705e1b1b0b35f21c96232880027e70b108452a996e8d51a037c0774ebcb5a61469d3a1
data/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ All notable changes to the Gleis CLI will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.6.0 - 2019-08-20
9
+
10
+ ### Added
11
+
12
+ - Parameter --follow/-f to app logs command to follow live the log file of an app
13
+
14
+ ### Changed
15
+
16
+ - Requests to API to include CLI version in HTTP User-Agent header
17
+
18
+ ### Fixed
19
+
20
+ - Missing application scale command
21
+
22
+ ### Removed
23
+
24
+ - Occurrences of the safe navigation operator in order to support Ruby <2.3
25
+
8
26
  ## 0.5.0 - 2019-02-25
9
27
 
10
28
  ### Added
data/lib/gleis/api.rb CHANGED
@@ -5,17 +5,29 @@ module Gleis
5
5
  class API
6
6
  def self.request(method, action, token = nil, body = {})
7
7
  url = Config::API_URL + Config::API_VERSION + '/cli/' + action
8
+ user_agent = RestClient::Platform.default_user_agent + ' Gleis/' + VERSION
8
9
  begin
9
10
  case method
10
11
  when 'get', 'delete'
11
- resp = RestClient.send(method, url, 'X-Gleis-Token': token, content_type: :json, accept: :json)
12
+ resp = RestClient.send(method, url, 'X-Gleis-Token': token, content_type: :json, accept: :json,
13
+ user_agent: user_agent)
12
14
  when 'post', 'put'
13
15
  if token
14
16
  resp =
15
- RestClient.send(method, url, body.to_json, 'X-Gleis-Token': token, content_type: :json, accept: :json)
17
+ RestClient.send(method, url, body.to_json, 'X-Gleis-Token': token, content_type: :json, accept: :json,
18
+ user_agent: user_agent)
16
19
  else
17
- resp = RestClient.send(method, url, body.to_json, content_type: :json, accept: :json)
20
+ resp = RestClient.send(method, url, body.to_json, content_type: :json, accept: :json,
21
+ user_agent: user_agent)
18
22
  end
23
+ when 'stream'
24
+ stream_output = proc { |response|
25
+ response.read_body do |chunk|
26
+ puts chunk
27
+ end
28
+ }
29
+ RestClient::Request.execute(method: :get, url: url, block_response: stream_output,
30
+ headers: { 'X-Gleis-Token': token })
19
31
  end
20
32
  rescue RestClient::BadRequest
21
33
  abort('Authentication failed.')
@@ -35,12 +47,16 @@ module Gleis
35
47
  rescue StandardError # (e.g. SocketError, Errno::ECONNREFUSED, RestClient::BadGateway, ...)
36
48
  abort('There was an issue connecting to the Gleis API server.')
37
49
  else
38
- if resp.body.empty?
39
- # If there is no body return whole response object
40
- resp
41
- else
42
- # Return Ruby data structure of the JSON parsed body
43
- JSON.parse(resp.body)
50
+ # Streaming GET returns Net::HTTPInternalServerError in case of issue and no usable response body
51
+ # In that case the class of resp.body == Net::ReadAdapter
52
+ if defined? resp
53
+ if resp.body.empty?
54
+ # If there is no body return whole response object
55
+ resp
56
+ else
57
+ # Return Ruby data structure of the JSON parsed body
58
+ JSON.parse(resp.body)
59
+ end
44
60
  end
45
61
  end
46
62
  end
@@ -108,18 +108,22 @@ module Gleis
108
108
  end
109
109
  end
110
110
 
111
- def self.logs(app_name, process)
111
+ def self.logs(app_name, follow, process)
112
112
  token = Token.check
113
- action = "logs/#{app_name}/#{process}"
114
- body = API.request('get', action, token)
115
- if body['log'].nil?
116
- puts 'Failed to get logs: ' + body['message']
117
- elsif body['log'].empty?
118
- puts 'No log entries found yet.'
113
+ action = "logs/#{app_name}/#{process}?follow=#{follow}"
114
+ if follow == true
115
+ puts "Following log for the #{app_name} #{process} process:\n\n"
116
+ API.request('stream', action, token)
119
117
  else
120
- puts "Most recent entries of consolidated log for #{app_name} (#{process} process):"
121
- puts
122
- puts body['log']
118
+ body = API.request('get', action, token)
119
+ if body['log'].nil?
120
+ puts 'Failed to get logs: ' + body['message']
121
+ elsif body['log'].empty?
122
+ puts 'No log entries found yet.'
123
+ else
124
+ puts "Most recent entries of consolidated log for the #{app_name} #{process} process:\n\n"
125
+ puts body['log']
126
+ end
123
127
  end
124
128
  end
125
129
 
@@ -176,7 +180,7 @@ module Gleis
176
180
  token = Token.check
177
181
  body = API.request('get', "ps/#{app_name}", token)
178
182
  puts 'Failed to get processes.' unless body['success'] == 1
179
- if body['data']&.size&.positive?
183
+ if body['data'] && body['data'].size && body['data'].size.positive?
180
184
  body['data'].each_with_index do |service, index|
181
185
  puts "=== #{service[0]}: `#{service[1]['command']}`"
182
186
  if service[1]['tasks'].empty?
@@ -191,6 +195,20 @@ module Gleis
191
195
  end
192
196
  end
193
197
 
198
+ def self.scale(app_name, replica)
199
+ token = Token.check
200
+ count = Utils.validate_scale_count(replica)
201
+ body = API.request('post', 'scale', token, 'name': app_name, 'count': count)
202
+ if body['success'] == 1
203
+ puts "Successfully scaled app to #{count} replica"
204
+ if body['message']
205
+ puts 'Note that your app is currently not running, hence scaling will take effect as soon as you start it'
206
+ end
207
+ else
208
+ puts "Failed to scale app: #{body['message']}"
209
+ end
210
+ end
211
+
194
212
  def self.status(app_name)
195
213
  token = Token.check
196
214
  action = 'status/' + app_name
data/lib/gleis/cli/app.rb CHANGED
@@ -36,10 +36,12 @@ module Gleis
36
36
  end
37
37
 
38
38
  desc 'logs', 'View last log entries of a process'
39
+ option :follow, aliases: :'-f', type: :boolean, default: false,
40
+ desc: 'Follow live log data'
39
41
  option :process, aliases: :'-p', type: :string, default: 'web',
40
42
  desc: 'Process type (valid types are: scheduler, worker and web)'
41
43
  def logs
42
- Application.logs(options[:app], options[:process])
44
+ Application.logs(options[:app], options[:follow], options[:process])
43
45
  end
44
46
 
45
47
  desc 'maintenance', 'Enable or disable maintenance mode'
data/lib/gleis/utils.rb CHANGED
@@ -38,7 +38,7 @@ module Gleis
38
38
  def self.validate_scale_count(count)
39
39
  count_i = count.to_i
40
40
  abort('Please specifiy a number between 1 and 10 as parameter in order to scale your app.') unless
41
- count_i&.between?(1, 10)
41
+ count_i && count_i.between?(1, 10)
42
42
  count_i
43
43
  end
44
44
 
data/lib/gleis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gleis
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gleis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Bigler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2019-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.57'
89
+ version: '0.66'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.57'
96
+ version: '0.66'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rest-client
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -185,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubyforge_project:
189
- rubygems_version: 2.7.6
188
+ rubygems_version: 3.0.3
190
189
  signing_key:
191
190
  specification_version: 4
192
191
  summary: Gleis CLI to deploy and manage Rails apps on the Gleis PaaS