meroku 2.0.24 → 2.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/lib/meroku.rb +3 -1
- data/lib/meroku/app.rb +50 -0
- data/lib/meroku/cli.rb +23 -6
- data/lib/meroku/key.rb +46 -0
- data/lib/meroku/options.rb +36 -11
- data/lib/meroku/response_handler.rb +20 -0
- data/lib/meroku/user.rb +10 -15
- data/lib/meroku/version.rb +1 -1
- metadata +5 -3
- data/lib/meroku/api.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83ad90672b1ba754f3a9d60a73014e33fae3f7a9
|
4
|
+
data.tar.gz: c2059ae0f7f906600851aeef0e9ea111005fe434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05757a4e2eb0895c4caa7174c48ec415d307c69f25ab55a84e41e59c6edaacd6263c2f0a8a26c3f4294e35a9372c502e5a73d99c2169fe364cf168f9e59c0091
|
7
|
+
data.tar.gz: 595532afb78715dc0b3610b841896ddf3845545889834c557c4a31f535c3ca02f66d91049609de7b98eb9cc57aa98dab3dd2377bcae3c723f177a81133af3e40
|
data/README.md
CHANGED
@@ -9,7 +9,9 @@ because hosting 100 apps costs $700 ($7x100) at you-know-where.com
|
|
9
9
|
[![Dependencies](https://img.shields.io/gemnasium/meroku/meroku.svg?style=flat-square)](https://gemnasium.com/meroku/meroku)
|
10
10
|
[![Issues](https://img.shields.io/github/issues/meroku/meroku.svg?style=flat-square)](https://github.com/meroku/meroku/issues)
|
11
11
|
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
|
12
|
+
<br>
|
12
13
|
[![Gem Version](https://badge.fury.io/rb/meroku.svg)](https://badge.fury.io/rb/meroku)
|
14
|
+
<br>
|
13
15
|
[![Donate](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/meroku/donate)
|
14
16
|
|
15
17
|
|
@@ -27,8 +29,31 @@ And then execute:
|
|
27
29
|
|
28
30
|
## Usage
|
29
31
|
|
32
|
+
When inside a git repository containing a rails application,
|
33
|
+
do a single command deployment by running
|
34
|
+
|
35
|
+
$ git push meroku master
|
36
|
+
|
37
|
+
Get additional help by doing
|
38
|
+
|
30
39
|
$ meroku --help
|
31
40
|
|
41
|
+
Usage: meroku [options]
|
42
|
+
--help Prints this help
|
43
|
+
--signup EMAIL,PASSWORD
|
44
|
+
--unregister EMAIL,PASSWORD
|
45
|
+
--login EMAIL,PASSWORD
|
46
|
+
--logout
|
47
|
+
--keys-add
|
48
|
+
--keys List already uploaded keys
|
49
|
+
--keys-remove ID
|
50
|
+
--create NAME Create an app
|
51
|
+
--list-apps
|
52
|
+
--delete-app NAME
|
53
|
+
|
54
|
+
--spawn MEROKU_SECRET Spawn infrastructure
|
55
|
+
--despawn MEROKU_SECRET
|
56
|
+
|
32
57
|
## Development
|
33
58
|
|
34
59
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/meroku.rb
CHANGED
@@ -7,12 +7,14 @@ require 'open-uri'
|
|
7
7
|
require 'net/ssh'
|
8
8
|
require 'aws-sdk-ec2'
|
9
9
|
require 'meroku/version'
|
10
|
+
require 'meroku/response_handler'
|
10
11
|
require 'meroku/user'
|
12
|
+
require 'meroku/app'
|
13
|
+
require 'meroku/key'
|
11
14
|
require 'meroku/secrets'
|
12
15
|
require 'meroku/shared'
|
13
16
|
require 'meroku/aws'
|
14
17
|
require 'meroku/node'
|
15
|
-
require 'meroku/api'
|
16
18
|
require 'meroku/options'
|
17
19
|
require 'meroku/error'
|
18
20
|
require 'meroku/cli'
|
data/lib/meroku/app.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Meroku
|
4
|
+
# Logic related to Consumer Apps
|
5
|
+
class App
|
6
|
+
extend Meroku::User
|
7
|
+
extend Meroku::ResponseHandler
|
8
|
+
|
9
|
+
def self.create(name)
|
10
|
+
raise Meroku::Error, 'Not in a git repository' unless Dir.exist?('.git')
|
11
|
+
data = { 'token' => saved_token, 'name' => name }.to_json
|
12
|
+
result = RestClient.post 'https://www.meroku.com/apps.json',
|
13
|
+
data,
|
14
|
+
content_type: :json
|
15
|
+
process_error(result)
|
16
|
+
process_success(result) { add_git_remote(result) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.delete_app(name)
|
20
|
+
data = { 'name' => name, 'token' => saved_token }
|
21
|
+
result = RestClient::Request.execute(
|
22
|
+
method: :delete,
|
23
|
+
url: 'https://www.meroku.com/apps.json',
|
24
|
+
headers: { params: data }
|
25
|
+
)
|
26
|
+
process_error(result)
|
27
|
+
process_success(result)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.list_apps
|
31
|
+
result = RestClient.get 'https://www.meroku.com/apps.json',
|
32
|
+
params: { 'token' => saved_token },
|
33
|
+
content_type: :json
|
34
|
+
process_error(result)
|
35
|
+
process_success(result) do
|
36
|
+
JSON.parse(result).dig('data', 'apps_names').each do |k|
|
37
|
+
puts k
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.add_git_remote(result)
|
43
|
+
username = JSON.parse(result).dig('data', 'username')
|
44
|
+
appname = JSON.parse(result).dig('data', 'name')
|
45
|
+
remote_uri = "#{username}@www.meroku.com:#{appname}.git"
|
46
|
+
Kernel.system('git remote remove meroku 2>/dev/null')
|
47
|
+
Kernel.system("git remote add meroku #{remote_uri}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/meroku/cli.rb
CHANGED
@@ -5,7 +5,6 @@ module Meroku
|
|
5
5
|
# logic.
|
6
6
|
class CLI
|
7
7
|
include Meroku::Shared
|
8
|
-
include Meroku::Api
|
9
8
|
attr_reader :options
|
10
9
|
|
11
10
|
def initialize
|
@@ -14,7 +13,6 @@ module Meroku
|
|
14
13
|
|
15
14
|
def run(args = ARGV)
|
16
15
|
@options = Options.new.parse(args)
|
17
|
-
act_on_user_options
|
18
16
|
act_on_options
|
19
17
|
rescue Meroku::Success
|
20
18
|
return 0
|
@@ -28,12 +26,31 @@ module Meroku
|
|
28
26
|
private
|
29
27
|
|
30
28
|
def act_on_options
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
act_on_key_options
|
30
|
+
act_on_app_options
|
31
|
+
act_on_user_options
|
32
|
+
act_on_misc_options
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def act_on_app_options
|
37
|
+
App.create(@options[:name]) if @options[:create]
|
38
|
+
App.list_apps if @options[:list_apps]
|
39
|
+
App.delete_app(@options[:name]) if @options[:delete_app]
|
40
|
+
end
|
41
|
+
|
42
|
+
def act_on_key_options
|
43
|
+
Key.upload if @options[:keys_add]
|
44
|
+
Key.list if @options[:keys]
|
45
|
+
Key.remove(@options[:key_id]) if @options[:keys_remove]
|
46
|
+
end
|
47
|
+
|
48
|
+
def act_on_misc_options
|
49
|
+
Meroku::Shared.secrets.meroku_secret = @options[:meroku_secret] \
|
50
|
+
if @options[:meroku_secret]
|
51
|
+
|
34
52
|
Node.new if @options[:spawn]
|
35
53
|
Meroku::Aws.terminate_all(tag: 'node') if @options[:despawn]
|
36
|
-
true
|
37
54
|
end
|
38
55
|
|
39
56
|
def act_on_user_options
|
data/lib/meroku/key.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Meroku
|
4
|
+
# Logic related to Ssh keys
|
5
|
+
# eg. Uploading of users public key
|
6
|
+
module Key
|
7
|
+
extend Meroku::ResponseHandler
|
8
|
+
extend Meroku::User
|
9
|
+
|
10
|
+
def self.list
|
11
|
+
result = RestClient.get 'https://www.meroku.com/keys.json',
|
12
|
+
params: { 'token' => saved_token },
|
13
|
+
content_type: :json
|
14
|
+
process_error(result)
|
15
|
+
process_success(result) do
|
16
|
+
JSON.parse(result).dig('data', 'keys_ids').each do |k|
|
17
|
+
puts "Key id: #{k}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.upload
|
23
|
+
data = {
|
24
|
+
'token' => saved_token,
|
25
|
+
'key_name' => 'id_rsa.pub',
|
26
|
+
'key_data' => IO.read(Dir.home + '/.ssh/id_rsa.pub')
|
27
|
+
}.to_json
|
28
|
+
result = RestClient.post 'https://www.meroku.com/keys.json',
|
29
|
+
data,
|
30
|
+
content_type: :json
|
31
|
+
process_error(result)
|
32
|
+
process_success(result) { true }
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.remove(key_id)
|
36
|
+
data = { 'id' => key_id, 'token' => saved_token }
|
37
|
+
result = RestClient::Request.execute(
|
38
|
+
method: :delete,
|
39
|
+
url: 'https://www.meroku.com/keys.json',
|
40
|
+
headers: { params: data }
|
41
|
+
)
|
42
|
+
process_error(result)
|
43
|
+
process_success(result)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/meroku/options.rb
CHANGED
@@ -17,19 +17,42 @@ module Meroku
|
|
17
17
|
def define_options(_args)
|
18
18
|
OptionParser.new do |opts|
|
19
19
|
opts.banner = 'Usage: meroku [options]'
|
20
|
+
opts.on('--help', 'Prints this help') { puts opts }
|
21
|
+
add_user_options(opts)
|
22
|
+
add_key_options(opts)
|
23
|
+
add_app_options(opts)
|
24
|
+
opts.separator ''
|
25
|
+
add_maintainer_options(opts)
|
26
|
+
end
|
27
|
+
end
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
def add_key_options(opts)
|
30
|
+
option(opts, '--keys-add') { @options[:keys_add] = true }
|
31
|
+
option(opts, '--keys') { @options[:keys] = true }
|
32
|
+
option(opts, '--keys-remove ID') do |key_id|
|
33
|
+
@options[:keys_remove] = true
|
34
|
+
@options[:key_id] = key_id
|
35
|
+
end
|
36
|
+
end
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
38
|
+
def add_app_options(opts)
|
39
|
+
option(opts, '--create NAME') do |name|
|
40
|
+
@options[:create] = true
|
41
|
+
@options[:name] = name
|
42
|
+
end
|
43
|
+
option(opts, '--list-apps') { @options[:list_apps] = true }
|
44
|
+
option(opts, '--delete-app NAME') do |name|
|
45
|
+
@options[:delete_app] = true
|
46
|
+
@options[:name] = name
|
29
47
|
end
|
30
48
|
end
|
31
49
|
|
32
|
-
def
|
50
|
+
def add_user_options(opts)
|
51
|
+
add_user_registration_options(opts)
|
52
|
+
add_user_login_options(opts)
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_user_registration_options(opts)
|
33
56
|
option(opts, '--signup EMAIL,PASSWORD', Array) do |list|
|
34
57
|
@options[:signup] = true
|
35
58
|
@options[:email] = list[0]
|
@@ -42,7 +65,7 @@ module Meroku
|
|
42
65
|
end
|
43
66
|
end
|
44
67
|
|
45
|
-
def
|
68
|
+
def add_user_login_options(opts)
|
46
69
|
option(opts, '--login EMAIL,PASSWORD', Array) do |list|
|
47
70
|
@options[:login] = true
|
48
71
|
@options[:email] = list[0]
|
@@ -53,7 +76,7 @@ module Meroku
|
|
53
76
|
end
|
54
77
|
end
|
55
78
|
|
56
|
-
def
|
79
|
+
def add_maintainer_options(opts)
|
57
80
|
option(opts, '--spawn MEROKU_SECRET') do |meroku_secret|
|
58
81
|
@options[:spawn] = true
|
59
82
|
@options[:meroku_secret] = meroku_secret
|
@@ -87,7 +110,9 @@ module Meroku
|
|
87
110
|
module OptionsHelp
|
88
111
|
TEXT = {
|
89
112
|
version: 'Display version.',
|
90
|
-
spawn: 'Spawn infrastructure'
|
113
|
+
spawn: 'Spawn infrastructure',
|
114
|
+
keys: 'List already uploaded keys',
|
115
|
+
create: 'Create an app'
|
91
116
|
}.freeze
|
92
117
|
end
|
93
118
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Meroku
|
4
|
+
# Logic related to making rest api calls to backend rails server
|
5
|
+
module ResponseHandler
|
6
|
+
def process_error(result)
|
7
|
+
raise Meroku::Error, JSON.parse(result).dig('errors') \
|
8
|
+
if JSON.parse(result).dig('errors')
|
9
|
+
end
|
10
|
+
|
11
|
+
def process_success(result)
|
12
|
+
id = JSON.parse(result).dig('data', 'id')
|
13
|
+
if id
|
14
|
+
yield(result) if block_given?
|
15
|
+
puts "OK [#{id}]"
|
16
|
+
end
|
17
|
+
raise Meroku::Success
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/meroku/user.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
module Meroku
|
4
4
|
# Logic related to Users login, logout etc
|
5
5
|
module User
|
6
|
+
extend Meroku::ResponseHandler
|
7
|
+
|
6
8
|
def self.login(email, password)
|
7
9
|
data = { 'email' => email, 'password' => password }.to_json
|
8
10
|
result = RestClient.post 'https://www.meroku.com/login.json',
|
@@ -12,22 +14,8 @@ module Meroku
|
|
12
14
|
process_success(result) { |x| save_token(x) }
|
13
15
|
end
|
14
16
|
|
15
|
-
def self.process_error(result)
|
16
|
-
raise Meroku::Error, JSON.parse(result).dig('errors') \
|
17
|
-
if JSON.parse(result).dig('errors')
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.process_success(result)
|
21
|
-
id = JSON.parse(result).dig('data', 'id')
|
22
|
-
if id
|
23
|
-
yield(result) if block_given?
|
24
|
-
puts "OK [#{id}]"
|
25
|
-
end
|
26
|
-
raise Meroku::Success
|
27
|
-
end
|
28
|
-
|
29
17
|
def self.save_token(x)
|
30
|
-
token = JSON.parse(x).dig('data', '
|
18
|
+
token = JSON.parse(x).dig('data', 'token')
|
31
19
|
IO.write("#{Dir.home}/.meroku_token", token) if token
|
32
20
|
end
|
33
21
|
|
@@ -62,5 +50,12 @@ module Meroku
|
|
62
50
|
file = "#{Dir.home}/.meroku_token"
|
63
51
|
File.delete(file) if File.exist?(file)
|
64
52
|
end
|
53
|
+
|
54
|
+
def saved_token
|
55
|
+
token_path = Dir.home + '/.meroku_token'
|
56
|
+
IO.read(token_path)
|
57
|
+
rescue StandardError => e
|
58
|
+
raise Meroku::Error, "Login failed #{e.class}"
|
59
|
+
end
|
65
60
|
end
|
66
61
|
end
|
data/lib/meroku/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meroku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meroku System
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -175,12 +175,14 @@ files:
|
|
175
175
|
- data/etc_nginx_sites-enabled_template
|
176
176
|
- guard
|
177
177
|
- lib/meroku.rb
|
178
|
-
- lib/meroku/
|
178
|
+
- lib/meroku/app.rb
|
179
179
|
- lib/meroku/aws.rb
|
180
180
|
- lib/meroku/cli.rb
|
181
181
|
- lib/meroku/error.rb
|
182
|
+
- lib/meroku/key.rb
|
182
183
|
- lib/meroku/node.rb
|
183
184
|
- lib/meroku/options.rb
|
185
|
+
- lib/meroku/response_handler.rb
|
184
186
|
- lib/meroku/secrets.rb
|
185
187
|
- lib/meroku/shared.rb
|
186
188
|
- lib/meroku/user.rb
|
data/lib/meroku/api.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Meroku
|
4
|
-
# Logic related to making rest api calls to backend rails server
|
5
|
-
module Api
|
6
|
-
def post(data)
|
7
|
-
# response = RestClient.post "https://www.example.net", data.to_json
|
8
|
-
# puts "DB8 #{response.inspect}"
|
9
|
-
# true
|
10
|
-
# response = RestClient.post(url, data.to_json,
|
11
|
-
# timeout: 1,
|
12
|
-
# content_type: :json,
|
13
|
-
# accept: :json)
|
14
|
-
# r = JSON.parse(response)
|
15
|
-
# yield(r["data"]) if r.key?("data")
|
16
|
-
# return unless r.key?("errors") && r["errors"].size.positive?
|
17
|
-
# puts "error: #{r['errors'].map { |x| x['detail'] }.join('. ')}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|