gleis 0.3.2 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b6a2a9fc4d3430d52a2d06173bb90376a9ac36610cea8c4b575e5842304e6e6
4
- data.tar.gz: 0ed2b9286e7e55e15657724273fb7f03ef3c49e1b1c939aa7314967f7e225e06
3
+ metadata.gz: e259aa0549f7f0a6e982128032b6229870ec360d1f8ff5df5cde09d0b56ac46b
4
+ data.tar.gz: 79c8e30feb451306648f510cc03fabdfc7d1d38f5c80c722c18e70b0baa5781d
5
5
  SHA512:
6
- metadata.gz: 62ed6e20c3eae5fb1295676d3bef32c63622c4116193ed5a75b57810e3e46612565ef81f11f8c53ac70581fb241ccb73296ab97618d9af6704ddc8f5aa348b07
7
- data.tar.gz: e0ad98a6a3933c3edf2d31fadb7172ae509252b7678b80bdbfd49c5e71effb8e0f39881eb39b418c44dcb561375a36faa5ce443a52d152c5802e68439c661c3f
6
+ metadata.gz: c9c407ddec056aa78d8b05675bdc7563444aa5978eb0cdf073fda9bffa62ad7ed348d1cfde96a51e4fe1ff6ff1405e31985e305d6bba6b8cf01c2b7f0eece7a5
7
+ data.tar.gz: ad2c83adeab38fe45a52024f2e9df85ca2f6fc2f370b4aa9220079ed00ab0b20048e26793b9c4e3c06f2eb0345cb36c313a5d60b90b70795598be63b1cc731af
data/CHANGELOG.md CHANGED
@@ -5,6 +5,26 @@ 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.4.0 - 2019-02-10
9
+
10
+ ### Added
11
+
12
+ - Application rollback for deploying a previous deployment referred by its commit hash
13
+ - Application maintenance mode for temporary taking app offline
14
+ - Description to the --app/-a option for specifying the name of the app
15
+ - Reverse storage synchronisation (from Gleis storage to local computer) using -x option
16
+
17
+ ### Changed
18
+
19
+ - Application status to use generic data key instead of status key
20
+ - Addon listing format to be clearer and add more spacing
21
+ - Listing of deployments to show with an asterisk which deployment is currently in use
22
+ - Status of app to show current deployment commit short hash and version
23
+
24
+ ### Fixed
25
+
26
+ - Missing credential information for syncing storage
27
+
8
28
  ## 0.3.2 - 2018-12-15
9
29
 
10
30
  ### Added
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 towards GmbH - v#{Gleis::VERSION} - https://gleis.cloud ###\n\n" \
5
+ puts "\n### Gleis CLI Copyright (c) 2018-2019 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/addon.rb CHANGED
@@ -17,11 +17,12 @@ module Gleis
17
17
  addons = body ['data']
18
18
  if addons.any?
19
19
  puts "List of available add-ons:\n\n"
20
- printf("\t%-30s %-15s %s\n", 'ADD-ON NAME', 'VERSION', 'CATEGORY')
21
- printf("\t%s\n\n", 'DESCRIPTION')
20
+ printf("\t%s\n", 'ADD-ON NAME')
21
+ printf("\t%-30s %-15s %s\n", 'DESCRIPTION', 'VERSION', 'CATEGORY')
22
+ printf("\t%-30s %-15s %s\n\n", '-----------', '-------', '--------')
22
23
  addons.each do |addon|
23
24
  printf("\t%-30s %-15s %s\n", addon['name'], addon['version'], addon['category'])
24
- puts "\t#{addon['description']}\n"
25
+ puts "\t#{addon['description']}\n\n"
25
26
  end
26
27
  else
27
28
  puts 'No add-ons avaialble.'
@@ -47,9 +47,11 @@ module Gleis
47
47
  body = API.request('get', action, token)
48
48
  if body['deployments'].any?
49
49
  body['deployments'].reverse_each do |d|
50
- puts "v#{d['version']} | #{d['commit'][0, 7]} | #{d['email']} | #{d['subject']}\n" \
50
+ deployed = d['deployed'] ? '(*)' : ''
51
+ puts "v#{d['version']}#{deployed} | #{d['commit'][0, 7]} | #{d['email']} | #{d['subject']}\n" \
51
52
  "deployed by #{d['name']} on #{Time.parse(d['created_at']).strftime('%c')}\n\n"
52
53
  end
54
+ puts "\t(*) current version in use\n\n"
53
55
  else
54
56
  puts 'No deployments found, please deploy your app first.'
55
57
  end
@@ -119,6 +121,24 @@ module Gleis
119
121
  end
120
122
  end
121
123
 
124
+ def self.maintenance(app_name, mode = nil)
125
+ token = Token.check
126
+ body = API.request('get', "maintenance/#{app_name}", token)
127
+ current_mode_text = body['data'] == true ? 'on' : 'off'
128
+ if mode.nil?
129
+ puts "Maintenance mode is currently #{current_mode_text}"
130
+ else
131
+ abort("Maintenance mode is already #{current_mode_text}") if body['data'] == mode
132
+ body = API.request('put', 'maintenance', token, 'name': app_name, 'mode': mode)
133
+ new_mode_text = mode == true ? 'on' : 'off'
134
+ if body['success'] == 1
135
+ puts "Successfully turned #{new_mode_text} maintenance mode"
136
+ else
137
+ puts "Failed to turn #{new_mode_text} maintenance mode"
138
+ end
139
+ end
140
+ end
141
+
122
142
  def self.restart(app_name)
123
143
  token = Token.check
124
144
  body = API.request('post', 'restart', token, 'name': app_name)
@@ -129,17 +149,14 @@ module Gleis
129
149
  end
130
150
  end
131
151
 
132
- def self.scale(app_name, replica)
152
+ def self.rollback(app_name, commit)
133
153
  token = Token.check
134
- count = Utils.validate_scale_count(replica)
135
- body = API.request('post', 'scale', token, 'name': app_name, 'count': count)
154
+ Utils.validate_commit_hash(commit)
155
+ body = API.request('post', 'rollback', token, 'name': app_name, 'commit': commit)
136
156
  if body['success'] == 1
137
- puts "Successfully scaled app to #{count} replica"
138
- if body['message']
139
- puts 'Note that your app is currently not running, hence scaling will take effect as soon as you start it'
140
- end
157
+ puts "Successfully rolled back app to deployment with commit hash #{commit}"
141
158
  else
142
- puts "Failed to scale app: #{body['message']}"
159
+ puts "Failed to rollback app: #{body['message']}"
143
160
  end
144
161
  end
145
162
 
@@ -178,10 +195,14 @@ module Gleis
178
195
  body = API.request('get', action, token)
179
196
  puts "Status of app #{app_name}:\n\n"
180
197
  if body['success'] == 1
181
- status = body['status']
198
+ status = body['data']
199
+ if status['deployment_commit'] && status['deployment_version']
200
+ deployment = "\tDeployment:\t#{status['deployment_commit']} (v#{status['deployment_version']})\n"
201
+ end
182
202
  puts "\tStatus:\t\trunning\n" \
183
203
  "\tStarted at:\t#{Time.parse(status['createdat']).localtime.strftime('%c')}\n" \
184
204
  "\tUpdated at:\t#{Time.parse(status['updatedat']).localtime.strftime('%c')}\n" \
205
+ "#{deployment}" \
185
206
  "\tUpdate count:\t#{status['forceupdate']}\n" \
186
207
  "\tReplicas:\t#{status['replicas']}"
187
208
  else
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Add-ons-related CLI commands
4
4
  class Addon < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name
5
+ class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add ADDON', 'Add add-on to app'
8
8
  def add(name)
data/lib/gleis/cli/app.rb CHANGED
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Application-related CLI commands
4
4
  class App < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name
5
+ class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'config [VAR=value]', 'Show, set or delete environment variables'
8
8
  def config(env_var = '')
@@ -40,6 +40,19 @@ module Gleis
40
40
  Application.logs(options[:app])
41
41
  end
42
42
 
43
+ desc 'maintenance', 'Enable or disable maintenance mode'
44
+ option :on, type: :boolean, default: false, desc: 'Turn on maintenance mode'
45
+ option :off, type: :boolean, default: false, desc: 'Turn off maintenance mode'
46
+ def maintenance
47
+ abort('On and off are mutually exclusive options.') if options[:on] && options[:off]
48
+ if options[:on]
49
+ mode = true
50
+ elsif options[:off]
51
+ mode = false
52
+ end
53
+ Application.maintenance(options[:app], mode)
54
+ end
55
+
43
56
  desc 'ps', 'Show running processes'
44
57
  def ps
45
58
  Application.ps(options[:app])
@@ -50,6 +63,11 @@ module Gleis
50
63
  Application.restart(options[:app])
51
64
  end
52
65
 
66
+ desc 'rollback COMMIT', 'Rollback to a previous deployment specified by its commit hash'
67
+ def rollback(commit)
68
+ Application.rollback(options[:app], commit)
69
+ end
70
+
53
71
  desc 'scale #REPLICA', 'Scale up or down (horizontal scaling)'
54
72
  def scale(replica)
55
73
  Application.scale(options[:app], replica)
data/lib/gleis/cli/db.rb CHANGED
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Database-related CLI subcommands
4
4
  class Db < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name
5
+ class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'backup', 'Backup locally database DATABASE_URL'
8
8
  def backup
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Domain-related CLI commands
4
4
  class Domain < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name
5
+ class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add DOMAIN', 'Add domain name to app'
8
8
  def add(name)
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Sharing-related CLI commands
4
4
  class Sharing < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name
5
+ class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add EMAIL ROLE', 'Allow user to access app (roles: collaborator, owner)'
8
8
  def add(email, role)
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Storage-related CLI commands
4
4
  class Storage < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name
5
+ class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add TYPE', 'Add storage to app'
8
8
  def add(type)
@@ -19,9 +19,11 @@ module Gleis
19
19
  Gleis::Storage.list(options[:app])
20
20
  end
21
21
 
22
- desc 'sync DIRECTORY', 'Synchronise local directory with remote storage'
22
+ desc 'sync DIRECTORY', 'Synchronise local directory to Gleis storage (from local to remote)'
23
+ option :reverse, aliases: :x, type: :boolean, default: false,
24
+ desc: 'Reverse synchronisation (from remote to local)'
23
25
  def sync(dir)
24
- Gleis::Storage.sync(options[:app], dir)
26
+ Gleis::Storage.sync(options[:app], dir, options[:reverse])
25
27
  end
26
28
  end
27
29
  end
@@ -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 towards GmbH
24
+ Copyright (C) 2018-2019 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/storage.rb CHANGED
@@ -46,7 +46,7 @@ module Gleis
46
46
  end
47
47
  end
48
48
 
49
- def self.sync(app_name, dir)
49
+ def self.sync(app_name, dir, reverse = false)
50
50
  token = Token.check
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
@@ -54,10 +54,15 @@ module Gleis
54
54
  abort('The rsync tool is not installed on this system.') unless system('which rsync >/dev/null')
55
55
  body = API.request('get', "storage/#{app_name}", token)
56
56
  if body['success'] == 1
57
- if body['storage']
58
- ns_app_name = "#{body['namespace']}_#{app_name}"
59
- ENV['RSYNC_PASSWORD'] = body['storage']['password']
60
- exec("rsync -rth --progress #{dir}/ rsync://#{ns_app_name}@#{params['sync_server']}/#{ns_app_name}")
57
+ if (storage = body['data']['storage'].first)
58
+ ns_app_name = "#{body['data']['namespace']}_#{app_name}"
59
+ ENV['RSYNC_PASSWORD'] = storage['password']
60
+ directories = if reverse
61
+ "rsync://#{ns_app_name}@#{params['sync_server']}/#{ns_app_name} #{dir}/"
62
+ else
63
+ "#{dir}/ rsync://#{ns_app_name}@#{params['sync_server']}/#{ns_app_name}"
64
+ end
65
+ exec("rsync -rth --progress #{directories}")
61
66
  else
62
67
  puts 'No storage configured yet.'
63
68
  end
data/lib/gleis/utils.rb CHANGED
@@ -42,6 +42,11 @@ module Gleis
42
42
  count_i
43
43
  end
44
44
 
45
+ def self.validate_commit_hash(commit)
46
+ abort('Please specifiy a valid commit hash (e.g. 3efb741) pointing to another deployment of your app.') unless
47
+ commit =~ /^\h{7,40}$/
48
+ end
49
+
45
50
  def self.add_remote_to_git_config(remote_url)
46
51
  config_file = Dir.pwd + '/.git/config'
47
52
  return false unless File.exist?(config_file)
data/lib/gleis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gleis
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.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.3.2
4
+ version: 0.4.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: 2018-12-15 00:00:00.000000000 Z
11
+ date: 2019-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler