gleis 0.6.1 → 0.9.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/CHANGELOG.md +54 -0
- data/exe/gleis +1 -1
- data/lib/gleis.rb +3 -2
- data/lib/gleis/api.rb +18 -10
- data/lib/gleis/application.rb +17 -3
- data/lib/gleis/cli/app.rb +5 -0
- data/lib/gleis/config.rb +4 -4
- data/lib/gleis/database.rb +2 -2
- data/lib/gleis/main.rb +0 -1
- data/lib/gleis/management.rb +1 -1
- data/lib/gleis/ssh.rb +10 -6
- data/lib/gleis/storage.rb +1 -1
- data/lib/gleis/utils.rb +16 -5
- data/lib/gleis/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52cf754e60ba92b22285232e14abc4771f3771d39835e822f3ade4ea8d83c6b8
|
4
|
+
data.tar.gz: 12a49af88befe9f5675ee1891b39be4b5ff5d9b0acd9046f1514cdfcf6a0fe9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec4cd4a23de25800f03f35fbb47ff2860a7e6a99812ab49e069edcfe3c23726d07ac7dbb53a5c7fa2dad7abc5b06d735cb7ed283d992d60c4b70820495f33a37
|
7
|
+
data.tar.gz: d50b397a83a7c166fede102391e17aab3a3df9f75de0158a52bcf95c2ecb2ecb2591efb3047252e9b3d71ddf349ad2a9e678a02dbbae72cf32318ded7bff9608
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,60 @@ 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.9.0 - 2020-06-26
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Meaningful reason why app create command failed in case of problem
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
|
16
|
+
- Extra space in SSH key generator comment and typo in user message when command is unavailable
|
17
|
+
- Raw invalid token message when session times out during the app logs command in follow mode
|
18
|
+
|
19
|
+
## 0.8.0 - 2020-04-19
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- Calls to system commands to check first if external system command exists
|
24
|
+
- External system call to which command with own which method
|
25
|
+
- Path separator to be dynamic for cross-platform compatibility
|
26
|
+
- Password prompt to use IO.noecho instead of depending on stty system command
|
27
|
+
- Save path of database dump file to be stored into user home directory instead of tmp
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
|
31
|
+
- Adding SSH Host configuration in non-existing SSH config file
|
32
|
+
|
33
|
+
## 0.7.1 - 2020-03-20
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
|
37
|
+
- API URL to use .app top-level domain
|
38
|
+
|
39
|
+
## 0.7.0 - 2020-03-07
|
40
|
+
|
41
|
+
### Changed
|
42
|
+
|
43
|
+
- Version dependency of mdl, rest-client and rubocop
|
44
|
+
- Actual year of copyright to be dynamic
|
45
|
+
- API POST request read timeout from default of 60s to 600s
|
46
|
+
|
47
|
+
### Added
|
48
|
+
|
49
|
+
- New command called rebuild in order to rebuild an app image from the git repo
|
50
|
+
- Rescue read timeout from API request
|
51
|
+
|
52
|
+
### Fixed
|
53
|
+
|
54
|
+
- Error message when restarting a not yet deployed app by deprecating error_text usage
|
55
|
+
|
56
|
+
## 0.6.2 - 2019-08-24
|
57
|
+
|
58
|
+
### Fixed
|
59
|
+
|
60
|
+
- Load external gems such as thor before any other internal gleis libraries
|
61
|
+
|
8
62
|
## 0.6.1 - 2019-08-20
|
9
63
|
|
10
64
|
### Changed
|
data/exe/gleis
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'gleis/main'
|
4
4
|
|
5
|
-
puts "\n### Gleis CLI Copyright (c) 2018
|
5
|
+
puts "\n### Gleis CLI Copyright (c) 2018-#{Time.new.year} towards GmbH - v#{Gleis::VERSION} - https://gleis.cloud ###\n\n" \
|
6
6
|
unless ARGF.argv.include?('-q')
|
7
7
|
|
8
8
|
trap 'SIGINT' do
|
data/lib/gleis.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'thor'
|
3
|
+
|
1
4
|
require 'gleis/utils'
|
2
5
|
require 'gleis/authentication'
|
3
6
|
require 'gleis/addon'
|
@@ -26,8 +29,6 @@ require 'gleis/storage'
|
|
26
29
|
require 'gleis/token'
|
27
30
|
require 'gleis/version'
|
28
31
|
|
29
|
-
require 'json'
|
30
|
-
|
31
32
|
# Top-level gleis module namespace
|
32
33
|
module Gleis
|
33
34
|
end
|
data/lib/gleis/api.rb
CHANGED
@@ -12,17 +12,22 @@ module Gleis
|
|
12
12
|
resp = RestClient.send(method, url, 'X-Gleis-Token': token, content_type: :json, accept: :json,
|
13
13
|
user_agent: user_agent)
|
14
14
|
when 'post', 'put'
|
15
|
-
if token
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
resp = if token
|
16
|
+
RestClient::Request.execute(method: method.to_s, url: url, payload: body.to_json, read_timeout: 600,
|
17
|
+
headers: { 'X-Gleis-Token': token, 'Content-Type': 'application/json',
|
18
|
+
'Accept': 'application/json', 'User-Agent': user_agent })
|
19
|
+
else
|
20
|
+
RestClient.send(method, url, body.to_json, content_type: :json, accept: :json,
|
21
21
|
user_agent: user_agent)
|
22
|
-
|
22
|
+
end
|
23
23
|
when 'stream'
|
24
24
|
stream_output = proc { |response|
|
25
25
|
response.read_body do |chunk|
|
26
|
+
# Catch timed out session during streaming response to client (e.g. follow log)
|
27
|
+
# in order not to display raw "invalid token" JSON response from API
|
28
|
+
chunk == '{"message":"invalid token"}' && abort('Session has timed out, please login again (invalid token).')
|
29
|
+
# Catch application not found raw JSON response from API
|
30
|
+
chunk == '{"message":"app not found"}' && abort('Application not found.')
|
26
31
|
puts chunk
|
27
32
|
end
|
28
33
|
}
|
@@ -44,12 +49,15 @@ module Gleis
|
|
44
49
|
abort('Application not found.')
|
45
50
|
rescue RestClient::InternalServerError
|
46
51
|
abort('An error occured on the platform. Please contact support if this problem persists.')
|
52
|
+
rescue RestClient::Exceptions::ReadTimeout
|
53
|
+
abort('The request timed out reading data from the platform.')
|
47
54
|
rescue StandardError # (e.g. SocketError, Errno::ECONNREFUSED, RestClient::BadGateway, ...)
|
48
55
|
abort('There was an issue connecting to the Gleis API server.')
|
49
56
|
else
|
50
|
-
#
|
51
|
-
|
52
|
-
|
57
|
+
# In case the user's session expires during streaming the response class will be NilClass
|
58
|
+
if (defined? resp) && resp.class != NilClass
|
59
|
+
# Streaming GET returns Net::HTTPInternalServerError in case of issue and no usable response body,
|
60
|
+
# in that case the class of resp.body == Net::ReadAdapter
|
53
61
|
if resp.body.empty?
|
54
62
|
# If there is no body return whole response object
|
55
63
|
resp
|
data/lib/gleis/application.rb
CHANGED
@@ -38,6 +38,7 @@ module Gleis
|
|
38
38
|
puts "You can then access your app using the URL https://#{body['dns_name']}" if body.key? 'dns_name'
|
39
39
|
else
|
40
40
|
puts 'failed!'
|
41
|
+
puts "\nReason for failure: #{body['message']}" unless body['message'].nil?
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -74,6 +75,7 @@ module Gleis
|
|
74
75
|
|
75
76
|
def self.exec(app_name, command)
|
76
77
|
token = Token.check
|
78
|
+
abort('The SSH client command ssh is not installed on this system.') unless Utils.which('ssh')
|
77
79
|
config_body = Config.get_env_vars(app_name, token)
|
78
80
|
# Get storage and generate mount parameter
|
79
81
|
mount_param = Utils.generate_exec_mount_param(API.request('get', "storage/#{app_name}", token), app_name)
|
@@ -86,8 +88,8 @@ module Gleis
|
|
86
88
|
-p #{p['run_port']} \
|
87
89
|
#{p['run_username']}@#{p['run_server']} \
|
88
90
|
'#{Utils.generate_exec_env_param(config_body['env_vars'])} #{mount_param} \
|
89
|
-
|
90
|
-
|
91
|
+
#{p['registry_server']}/#{dp_body['namespace']}/#{app_name}:#{dp_body['deployments'].last['commit'][0..6]} \
|
92
|
+
#{command}'")
|
91
93
|
else
|
92
94
|
puts 'No deployments found, please deploy your app first.'
|
93
95
|
end
|
@@ -145,13 +147,25 @@ module Gleis
|
|
145
147
|
end
|
146
148
|
end
|
147
149
|
|
150
|
+
def self.rebuild(app_name)
|
151
|
+
token = Token.check
|
152
|
+
puts 'Please wait while rebuilding, it could take a few minutes depending on app dependencies and complexity...'
|
153
|
+
body = API.request('post', 'rebuild', token, 'name': app_name)
|
154
|
+
if body['success'] == 1
|
155
|
+
puts "\nSuccessfully rebuilt app from git repo, detailed output from image build below:"
|
156
|
+
puts body['data']
|
157
|
+
else
|
158
|
+
puts 'Failed to rebuild app: ' + body['message']
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
148
162
|
def self.restart(app_name)
|
149
163
|
token = Token.check
|
150
164
|
body = API.request('post', 'restart', token, 'name': app_name)
|
151
165
|
if body['success'] == 1
|
152
166
|
puts 'Successfully restarted app using rolling update'
|
153
167
|
else
|
154
|
-
puts 'Failed to restart app: ' + body['
|
168
|
+
puts 'Failed to restart app: ' + body['message']
|
155
169
|
end
|
156
170
|
end
|
157
171
|
|
data/lib/gleis/cli/app.rb
CHANGED
@@ -62,6 +62,11 @@ module Gleis
|
|
62
62
|
Application.ps(options[:app])
|
63
63
|
end
|
64
64
|
|
65
|
+
desc 'rebuild', 'Rebuild app from git repo'
|
66
|
+
def rebuild
|
67
|
+
Application.rebuild(options[:app])
|
68
|
+
end
|
69
|
+
|
65
70
|
desc 'restart', 'Restart application (rolling update)'
|
66
71
|
def restart
|
67
72
|
Application.restart(options[:app])
|
data/lib/gleis/config.rb
CHANGED
@@ -2,14 +2,14 @@ module Gleis
|
|
2
2
|
# Global parameters of gleis gem and app config env variables
|
3
3
|
class Config
|
4
4
|
# Override default API URL if GLEIS_API_URL env variable is set
|
5
|
-
API_URL = ENV['GLEIS_API_URL'].nil? ? 'https://api.basel.gleis.
|
5
|
+
API_URL = ENV['GLEIS_API_URL'].nil? ? 'https://api.basel.gleis.app/' : ENV['GLEIS_API_URL']
|
6
6
|
API_VERSION = 'v0'.freeze
|
7
|
-
SSH_KEY_FILE_BASE = Dir.home
|
8
|
-
TOKEN_FILE = Dir.home
|
7
|
+
SSH_KEY_FILE_BASE = File.join(Dir.home, '.ssh', 'gleis')
|
8
|
+
TOKEN_FILE = File.join(Dir.home, '.gleis-token')
|
9
9
|
|
10
10
|
def self.get_env_vars(app_name, token)
|
11
11
|
body = API.request('get', "config/#{app_name}", token)
|
12
|
-
abort("Failed to get app environment variables: #{body['
|
12
|
+
abort("Failed to get app environment variables: #{body['message']}") if body['success'] != 1
|
13
13
|
body
|
14
14
|
end
|
15
15
|
|
data/lib/gleis/database.rb
CHANGED
@@ -8,7 +8,7 @@ module Gleis
|
|
8
8
|
abort('There is no database configured under the DATABASE_URL variable.') unless url
|
9
9
|
db_name = url.split('/').last
|
10
10
|
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
11
|
-
backup_file = "
|
11
|
+
backup_file = File.join(Dir.home, "#{app_name}_#{db_name}_#{timestamp}.pgdump")
|
12
12
|
if system("pg_dump -f #{backup_file} #{url}")
|
13
13
|
puts "Database configured at DATABASE_URL succesfully backed up locally in #{backup_file}"
|
14
14
|
else
|
@@ -102,7 +102,7 @@ module Gleis
|
|
102
102
|
|
103
103
|
def self.psql(app_name)
|
104
104
|
token = Token.check
|
105
|
-
abort('The PostgreSQL client psql is not installed on this system.') unless
|
105
|
+
abort('The PostgreSQL client psql is not installed on this system.') unless Utils.which('psql')
|
106
106
|
url = Config.get_env_var(app_name, token, 'DATABASE_URL')
|
107
107
|
abort('There is no database configured under the DATABASE_URL variable.') unless url
|
108
108
|
ENV['PGCONNECT_TIMEOUT'] = '5'
|
data/lib/gleis/main.rb
CHANGED
data/lib/gleis/management.rb
CHANGED
@@ -21,7 +21,7 @@ module Gleis
|
|
21
21
|
def self.license
|
22
22
|
puts <<LICENSE
|
23
23
|
Gleis Command Line Interface for the Gleis Platform as a Service
|
24
|
-
Copyright (C) 2018
|
24
|
+
Copyright (C) 2018-#{Time.new.year} towards GmbH
|
25
25
|
|
26
26
|
This program is free software: you can redistribute it and/or modify
|
27
27
|
it under the terms of the GNU General Public License as published by
|
data/lib/gleis/ssh.rb
CHANGED
@@ -11,9 +11,13 @@ module Gleis
|
|
11
11
|
|
12
12
|
hostname = Socket.gethostname
|
13
13
|
datetime = Time.now.strftime('%Y-%m-%d %H:%M')
|
14
|
-
# returns true on success
|
15
|
-
|
16
|
-
|
14
|
+
# returns true on success and nil if command is not found or failed
|
15
|
+
if Utils.which('ssh-keygen')
|
16
|
+
system('ssh-keygen', '-f', key_file, '-b 4096',
|
17
|
+
"-Cgenerated by Gleis CLI for #{username} by #{ENV['USER']}@#{hostname} on #{datetime}")
|
18
|
+
else
|
19
|
+
puts 'The SSH key generator command ssh-keygen is not installed on this system.'
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def self.load_public_key(public_key_file)
|
@@ -21,10 +25,10 @@ module Gleis
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def self.add_host_to_config(host_name, private_key_file)
|
24
|
-
config_file = Dir.home
|
28
|
+
config_file = File.join(Dir.home, '.ssh', 'config')
|
25
29
|
ssh_host_line = "Host #{host_name}"
|
26
|
-
#
|
27
|
-
return if Utils.line_exists_in_file(config_file, ssh_host_line)
|
30
|
+
# Do not continue if host already exists in current SSH config file
|
31
|
+
return if File.exist?(config_file) && Utils.line_exists_in_file(config_file, ssh_host_line)
|
28
32
|
|
29
33
|
f = File.open(config_file, 'a')
|
30
34
|
f.puts "\n# Added by Gleis CLI on #{Time.now.strftime('%Y-%m-%d %H:%M')}"
|
data/lib/gleis/storage.rb
CHANGED
@@ -51,7 +51,7 @@ module Gleis
|
|
51
51
|
abort("Directory #{dir} does not exist or is not a directory.") unless Dir.exist?(dir)
|
52
52
|
# Get CLI parameters from API server
|
53
53
|
params = Params.get_cli_parameters(token)
|
54
|
-
abort('The rsync tool is not installed on this system.') unless
|
54
|
+
abort('The rsync tool is not installed on this system.') unless Utils.which('rsync')
|
55
55
|
body = API.request('get', "storage/#{app_name}", token)
|
56
56
|
if body['success'] == 1
|
57
57
|
if (storage = body['data']['storage'].first)
|
data/lib/gleis/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'io/console'
|
2
|
+
|
1
3
|
module Gleis
|
2
4
|
# This class gathers various utilities as small methods
|
3
5
|
class Utils
|
@@ -7,9 +9,7 @@ module Gleis
|
|
7
9
|
|
8
10
|
def self.prompt_password
|
9
11
|
print 'Password: '
|
10
|
-
|
11
|
-
password = $stdin.gets.chomp
|
12
|
-
system 'stty echo'
|
12
|
+
password = STDIN.noecho(&:gets).chomp
|
13
13
|
puts
|
14
14
|
password
|
15
15
|
end
|
@@ -32,7 +32,7 @@ module Gleis
|
|
32
32
|
|
33
33
|
def self.check_for_local_pg_command(command)
|
34
34
|
abort("The PostgreSQL client required to run the command #{command}) is not installed on this system.") unless
|
35
|
-
|
35
|
+
which(command)
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.validate_scale_count(count)
|
@@ -48,7 +48,7 @@ module Gleis
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def self.add_remote_to_git_config(remote_url)
|
51
|
-
config_file = Dir.pwd
|
51
|
+
config_file = File.join(Dir.pwd, '.git', 'config')
|
52
52
|
return false unless File.exist?(config_file)
|
53
53
|
|
54
54
|
# Check if gleis remote already exists
|
@@ -119,5 +119,16 @@ module Gleis
|
|
119
119
|
def self.update_available?(actual_version)
|
120
120
|
Gem::Version.new(Gleis::VERSION) < Gem::Version.new(actual_version)
|
121
121
|
end
|
122
|
+
|
123
|
+
def self.which(command)
|
124
|
+
file_extensions = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
125
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
126
|
+
file_extensions.each do |extension|
|
127
|
+
executable = File.join(path, "#{command}#{extension}")
|
128
|
+
return executable if File.executable?(executable) && !File.directory?(executable)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
nil
|
132
|
+
end
|
122
133
|
end
|
123
134
|
end
|
data/lib/gleis/version.rb
CHANGED
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.
|
4
|
+
version: 0.9.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:
|
11
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.8'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.68.0
|
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:
|
96
|
+
version: 0.68.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rest-client
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.
|
103
|
+
version: 2.1.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.
|
110
|
+
version: 2.1.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: thor
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,8 +122,8 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.20.0
|
125
|
-
description: Command-line interface to deploy and manage your Rails apps on the
|
126
|
-
|
125
|
+
description: " Command-line interface to deploy and manage your Rails apps on the
|
126
|
+
https://gleis.cloud Swiss Platform as a Service.\n"
|
127
127
|
email:
|
128
128
|
- gleis@towards.ch
|
129
129
|
executables:
|