aptible-cli 0.5.2 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +28 -17
- data/lib/aptible/cli/subcommands/db.rb +56 -36
- data/lib/aptible/cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb9dfc6735786325e67752acf288b43d9ebf21a3
|
4
|
+
data.tar.gz: fa7dcfac1d1eefecd10a7ae268d47a7ed379c44b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8e773b844383936d986e66d708001e745b02bc125037c484d66dc6c7ad0286cc36922c7c53eacc1e0ea2568e92dc4fc48b62b3e784af2a1e779448665b0d91e
|
7
|
+
data.tar.gz: 9a1f29d08c93c330aeb442cd6352b6b9c0e2d938b8d1241198eee7d2e2be4863390131014a84239c97eb939c9bc0fc44cc985237818ee4314b47d63daff3c649
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,22 +22,25 @@ From `aptible help`:
|
|
22
22
|
|
23
23
|
```
|
24
24
|
Commands:
|
25
|
-
aptible apps
|
26
|
-
aptible apps:create HANDLE
|
27
|
-
aptible config
|
28
|
-
aptible config:add
|
29
|
-
aptible config:rm
|
30
|
-
aptible config:set
|
31
|
-
aptible config:unset
|
32
|
-
aptible db:clone SOURCE DEST
|
33
|
-
aptible db:create HANDLE
|
34
|
-
aptible db:dump HANDLE
|
35
|
-
aptible db:
|
36
|
-
aptible
|
37
|
-
aptible
|
38
|
-
aptible
|
39
|
-
aptible
|
40
|
-
aptible
|
25
|
+
aptible apps # List all applications
|
26
|
+
aptible apps:create HANDLE # Create a new application
|
27
|
+
aptible config # Print an app's current configuration
|
28
|
+
aptible config:add # Add an ENV variable to an app
|
29
|
+
aptible config:rm # Remove an ENV variable from an app
|
30
|
+
aptible config:set # Alias for config:add
|
31
|
+
aptible config:unset # Alias for config:rm
|
32
|
+
aptible db:clone SOURCE DEST # Clone a database to create a new one
|
33
|
+
aptible db:create HANDLE # Create a new database
|
34
|
+
aptible db:dump HANDLE # Dump a remote database to file
|
35
|
+
aptible db:execute HANDLE SQL_FILE # Executes sql against a database
|
36
|
+
aptible db:tunnel HANDLE # Create a local tunnel to a database
|
37
|
+
aptible help [COMMAND] # Describe available commands or one specific command
|
38
|
+
aptible login # Log in to Aptible
|
39
|
+
aptible logs # Follows logs from a running app
|
40
|
+
aptible rebuild # Rebuild an app, and restart its services
|
41
|
+
aptible restart # Restart all services associated with an app
|
42
|
+
aptible ssh [COMMAND] # Run a command against an app
|
43
|
+
aptible version # Print Aptible CLI version
|
41
44
|
```
|
42
45
|
|
43
46
|
## Contributing
|
@@ -48,10 +51,18 @@ Commands:
|
|
48
51
|
1. If you add a command, update this README with the output of `aptible help | grep -v help`.
|
49
52
|
1. Create a new pull request on GitHub.
|
50
53
|
|
54
|
+
## Contributors
|
55
|
+
|
56
|
+
* Frank Macreery ([@fancyremarker](https://github.com/fancyremarker))
|
57
|
+
* Graham Melcher ([@melcher](https://github.com/melcher))
|
58
|
+
* Pete Browne ([@petebrowne](https://github.com/petebrowne))
|
59
|
+
* Rich Humphrey ([@rdh](https://github.com/rdh))
|
60
|
+
|
61
|
+
|
51
62
|
## Copyright and License
|
52
63
|
|
53
64
|
MIT License, see [LICENSE](LICENSE.md) for details.
|
54
65
|
|
55
|
-
Copyright (c)
|
66
|
+
Copyright (c) 2015 [Aptible](https://www.aptible.com) and contributors.
|
56
67
|
|
57
68
|
[<img src="https://s.gravatar.com/avatar/f7790b867ae619ae0496460aa28c5861?s=60" style="border-radius: 50%;" alt="@fancyremarker" />](https://github.com/fancyremarker)
|
@@ -28,41 +28,20 @@ module Aptible
|
|
28
28
|
|
29
29
|
desc 'db:clone SOURCE DEST', 'Clone a database to create a new one'
|
30
30
|
define_method 'db:clone' do |source_handle, dest_handle|
|
31
|
-
|
32
|
-
|
33
|
-
unless source
|
34
|
-
fail Thor::Error, "Could not find database #{source_handle}"
|
35
|
-
end
|
36
|
-
|
37
|
-
op = source.create_operation(type: 'clone', handle: dest_handle)
|
38
|
-
poll_for_success(op)
|
39
|
-
dest = database_from_handle(dest_handle)
|
31
|
+
dest = clone_database(source_handle, dest_handle)
|
40
32
|
say dest.connection_url
|
41
33
|
end
|
42
34
|
|
43
35
|
desc 'db:dump HANDLE', 'Dump a remote database to file'
|
44
36
|
define_method 'db:dump' do |handle|
|
45
|
-
|
46
|
-
|
47
|
-
unless database
|
48
|
-
fail Thor::Error, "Could not find database #{handle}"
|
49
|
-
end
|
50
|
-
unless database.type == 'postgresql'
|
51
|
-
fail Thor::Error, 'db:dump only works for PostgreSQL'
|
52
|
-
end
|
53
|
-
|
54
|
-
local_port = random_local_port
|
55
|
-
pid = fork { establish_connection(database, local_port) }
|
56
|
-
|
57
|
-
# TODO: Better test for connection readiness
|
58
|
-
sleep 10
|
37
|
+
dump_database(handle)
|
38
|
+
end
|
59
39
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
Process.kill('HUP', pid) if pid
|
40
|
+
desc 'db:execute HANDLE SQL_FILE', 'Executes sql against a database'
|
41
|
+
define_method 'db:execute' do |handle, sql_path|
|
42
|
+
execute_local_tunnel(handle) do |url|
|
43
|
+
puts "Executing #{sql_path} against #{handle}"
|
44
|
+
`psql #{url} < #{sql_path}`
|
66
45
|
end
|
67
46
|
end
|
68
47
|
|
@@ -70,10 +49,6 @@ module Aptible
|
|
70
49
|
option :port, type: :numeric
|
71
50
|
define_method 'db:tunnel' do |handle|
|
72
51
|
database = database_from_handle(handle)
|
73
|
-
unless database
|
74
|
-
fail Thor::Error, "Could not find database #{handle}"
|
75
|
-
end
|
76
|
-
|
77
52
|
local_port = options[:port] || random_local_port
|
78
53
|
puts "Creating tunnel at localhost:#{local_port}..."
|
79
54
|
establish_connection(database, local_port)
|
@@ -93,10 +68,55 @@ module Aptible
|
|
93
68
|
Kernel.exec(command)
|
94
69
|
end
|
95
70
|
|
96
|
-
def database_from_handle(handle)
|
97
|
-
Aptible::Api::Database.all(token: fetch_token)
|
98
|
-
|
71
|
+
def database_from_handle(handle, options = { postgres_only: false })
|
72
|
+
all = Aptible::Api::Database.all(token: fetch_token)
|
73
|
+
database = all.find { |a| a.handle == handle }
|
74
|
+
|
75
|
+
unless database
|
76
|
+
fail Thor::Error, "Could not find database #{handle}"
|
77
|
+
end
|
78
|
+
|
79
|
+
if options[:postgres_only] && database.type != 'postgresql'
|
80
|
+
fail Thor::Error, 'This command only works for PostgreSQL'
|
99
81
|
end
|
82
|
+
|
83
|
+
database
|
84
|
+
end
|
85
|
+
|
86
|
+
def clone_database(source_handle, dest_handle)
|
87
|
+
puts "Cloning #{source_handle} to #{dest_handle}"
|
88
|
+
|
89
|
+
source = database_from_handle(source_handle)
|
90
|
+
op = source.create_operation(type: 'clone', handle: dest_handle)
|
91
|
+
poll_for_success(op)
|
92
|
+
|
93
|
+
database_from_handle(dest_handle)
|
94
|
+
end
|
95
|
+
|
96
|
+
def dump_database(handle)
|
97
|
+
execute_local_tunnel(handle) do |url|
|
98
|
+
filename = "#{handle}.dump"
|
99
|
+
puts "Dumping to #{filename}"
|
100
|
+
`pg_dump #{url} > #{filename}`
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Creates a local tunnel and yields the url to it
|
105
|
+
|
106
|
+
def execute_local_tunnel(handle)
|
107
|
+
database = database_from_handle(handle, postgres_only: true)
|
108
|
+
|
109
|
+
local_port = random_local_port
|
110
|
+
pid = fork { establish_connection(database, local_port) }
|
111
|
+
|
112
|
+
# TODO: Better test for connection readiness
|
113
|
+
sleep 10
|
114
|
+
|
115
|
+
auth = "aptible:#{database.passphrase}"
|
116
|
+
host = "localhost:#{local_port}"
|
117
|
+
yield "postgresql://#{auth}@#{host}/db"
|
118
|
+
ensure
|
119
|
+
Process.kill('HUP', pid) if pid
|
100
120
|
end
|
101
121
|
|
102
122
|
def random_local_port
|
data/lib/aptible/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aptible-api
|