meroku 2.0.3 → 2.0.4
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/bin/meroku +1 -1
- data/frontend/app/controllers/publickeys_controller.rb +1 -0
- data/frontend/app/models/publickey.rb +11 -0
- data/lib/meroku.rb +4 -2
- data/lib/meroku/cli.rb +73 -54
- data/lib/meroku/cli/admin_user.rb +20 -0
- data/lib/meroku/cli/session.rb +65 -0
- data/lib/meroku/cli/user.rb +14 -0
- data/lib/meroku/infrastructure.rb +11 -2
- data/lib/meroku/infrastructure/node.rb +31 -6
- data/lib/meroku/version.rb +1 -1
- metadata +4 -2
- data/lib/meroku/aws.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f5b77a7020b9070c98356c545c6bad3c10cb41f
|
4
|
+
data.tar.gz: 245195d10ba32e577c050181618cabe13a9a3994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9f6674d08add9d0fc57b5b9d8246c7797dfe622b9cf5cbbca2da3b08e95e48dc0410e994c6cc5364cad45c87d5cbf9db37c7f5db5c3cda6f81e7a7cb94cc7b
|
7
|
+
data.tar.gz: 9269502bb855e2cc21526a177bd25832ad1ae83334b65a0699a1092d05ad7cc2baaaed0be6d127cb0bd96f34acc044285e25304d4a987e72f82d6eca188fdafb
|
data/bin/meroku
CHANGED
@@ -1,3 +1,14 @@
|
|
1
1
|
class Publickey < ApplicationRecord
|
2
2
|
belongs_to :user
|
3
|
+
|
4
|
+
# Updates /home/git/.ssh/authorized_keys
|
5
|
+
# called when something added/?/etc to publickeys table
|
6
|
+
def self.refresh
|
7
|
+
Rails.logger.debug "DB8 publickey.rb:def self.refresh called"
|
8
|
+
Rails.logger.debug "wipwip"
|
9
|
+
end
|
10
|
+
|
11
|
+
def after_save
|
12
|
+
Publickey.refresh
|
13
|
+
end
|
3
14
|
end
|
data/lib/meroku.rb
CHANGED
@@ -8,9 +8,11 @@ require "byebug"
|
|
8
8
|
require 'rest-client'
|
9
9
|
require "meroku/version"
|
10
10
|
require "meroku/tunnel"
|
11
|
-
require "meroku/cli"
|
12
|
-
require "meroku/
|
11
|
+
require "meroku/cli/user"
|
12
|
+
require "meroku/cli/admin_user"
|
13
13
|
require "meroku/infrastructure"
|
14
|
+
require "meroku/cli"
|
15
|
+
|
14
16
|
|
15
17
|
module Meroku
|
16
18
|
|
data/lib/meroku/cli.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
require "meroku/cli/session"
|
2
|
+
|
1
3
|
module Meroku
|
2
4
|
module CLI
|
3
5
|
|
4
|
-
|
6
|
+
def help
|
7
|
+
<<~HEREDOC
|
5
8
|
Usage: meroku command subcommand
|
6
9
|
|
7
10
|
Examples
|
@@ -14,38 +17,38 @@ module Meroku
|
|
14
17
|
|
15
18
|
meroku infrastrucuture spawn # Spawns server
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
def self.start(*args)
|
20
|
-
case args.join(" ")
|
21
|
-
when "infrastructure spawn"
|
22
|
-
load_secrets || exit
|
23
|
-
node = Meroku::Infrastructure::Node.new.associate_address.install_packages.install_frontend_app
|
24
|
-
puts "spawned #{node.instance.try(:instance_id)}"
|
25
|
-
when "infrastructure despawn"
|
26
|
-
load_secrets || exit
|
27
|
-
Meroku::Infrastructure.despawn
|
28
|
-
when "signup"
|
29
|
-
signup
|
30
|
-
when "keys:add"
|
31
|
-
token_check || exit
|
32
|
-
keys_add
|
33
|
-
when "create"
|
34
|
-
token_check || exit
|
35
|
-
create
|
36
|
-
else
|
37
|
-
puts HELP
|
38
|
-
end
|
20
|
+
HEREDOC
|
39
21
|
end
|
40
|
-
|
41
|
-
def self.
|
22
|
+
|
23
|
+
#def self.start(*args)
|
24
|
+
# case args.join(" ")
|
25
|
+
# when "infrastructure spawn"
|
26
|
+
# load_secrets || exit
|
27
|
+
# node = Meroku::Infrastructure::Node.new.associate_address.install_packages.install_frontend_app
|
28
|
+
# puts "spawned #{node.instance.try(:instance_id)}"
|
29
|
+
# when "infrastructure despawn"
|
30
|
+
# load_secrets || exit
|
31
|
+
# Meroku::Infrastructure.despawn
|
32
|
+
# when "signup"
|
33
|
+
# signup
|
34
|
+
# when "keys:add"
|
35
|
+
# token_check || exit
|
36
|
+
# keys_add
|
37
|
+
# when "create"
|
38
|
+
# token_check || exit
|
39
|
+
# create
|
40
|
+
# else
|
41
|
+
# puts HELP
|
42
|
+
# end
|
43
|
+
#end
|
44
|
+
|
45
|
+
def signup
|
42
46
|
print "Email: "
|
43
47
|
email = STDIN.gets
|
44
48
|
print "Password: "
|
45
49
|
password = STDIN.noecho(&:gets).chomp
|
46
50
|
print "\n"
|
47
51
|
url = "https://www.meroku.com/users.json"
|
48
|
-
#url = "http://localhost:3000/users.json"
|
49
52
|
response_json = RestClient.post url, {:user=>{:email => email, :password => password, :password_confirmation => password}}.to_json, timeout: 1, :content_type => :json, :accept => :json
|
50
53
|
if JSON.parse(response_json)["errors"] && JSON.parse(response_json)["errors"].size > 0
|
51
54
|
puts JSON.parse(response_json)["errors"].map{|x| x["detail"]}.join(".")
|
@@ -53,11 +56,33 @@ module Meroku
|
|
53
56
|
email = JSON.parse(response_json)["data"]["attributes"]["email"]
|
54
57
|
token = JSON.parse(response_json)["data"]["attributes"]["token"]
|
55
58
|
puts "Signed up #{email}"
|
56
|
-
|
59
|
+
dirname = File.dirname("#{Dir.home}/.meroku")
|
60
|
+
FileUtils.mkdir(dirname) if !File.directory?(dirname)
|
61
|
+
File.open("#{Dir.home}/.meroku/.token", 'w') { |file| file.write(token) }
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
|
-
def
|
65
|
+
def keys_add(session)
|
66
|
+
if !File.exist? "#{Dir.home}/.ssh/id_rsa.pub"
|
67
|
+
puts "error: File #{Dir.home}/.ssh/id_rsa.pub not found"
|
68
|
+
puts "You can use this command to generate a key:"
|
69
|
+
puts " ssh-keygen -t rsa"
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
name = "id_rsa.pub"
|
73
|
+
data = `cat ~/.ssh/id_rsa.pub`.chomp
|
74
|
+
url = "https://www.meroku.com/publickeys.json"
|
75
|
+
response_json = RestClient.post url, {:publickey=>{:name => name, :data=>data}, :token=>session.token}.to_json, timeout: 1, :content_type => :json, :accept => :json
|
76
|
+
|
77
|
+
if JSON.parse(response_json)["errors"] && JSON.parse(response_json)["errors"].size > 0
|
78
|
+
puts JSON.parse(response_json)["errors"].map{|x| x["detail"]}.join(".")
|
79
|
+
else
|
80
|
+
name = JSON.parse(response_json)["data"]["attributes"]["name"]
|
81
|
+
puts "Added #{name}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def create
|
61
86
|
url = "https://www.meroku.com/apps.json"
|
62
87
|
token = `cat ~/.meroku/.token`.chomp
|
63
88
|
response_json = RestClient.post url, {:app=>{:name => "unnamed"}, :token=>token}.to_json, timeout: 1, :content_type => :json, :accept => :json
|
@@ -96,34 +121,28 @@ module Meroku
|
|
96
121
|
Dotenv.load(env_file)
|
97
122
|
end
|
98
123
|
|
99
|
-
def self.save_token(token)
|
100
|
-
dirname = File.dirname("#{Dir.home}/.meroku")
|
101
|
-
unless File.directory?(dirname)
|
102
|
-
FileUtils.mkdir(dirname)
|
103
|
-
end
|
104
|
-
File.open("#{Dir.home}/.meroku/.token", 'w') { |file| file.write(token) }
|
105
|
-
end
|
106
124
|
|
107
|
-
def self.keys_add
|
108
|
-
if !File.exist? "#{Dir.home}/.ssh/id_rsa.pub"
|
109
|
-
puts "error: File #{Dir.home}/.ssh/id_rsa.pub not found"
|
110
|
-
puts "You can use this command to generate a key:"
|
111
|
-
puts " ssh-keygen -t rsa"
|
112
|
-
return nil
|
113
|
-
end
|
114
|
-
name = "id_rsa.pub"
|
115
|
-
data = `cat ~/.ssh/id_rsa.pub`.chomp
|
116
|
-
url = "https://www.meroku.com/publickeys.json"
|
117
|
-
token = `cat ~/.meroku/.token`.chomp
|
118
|
-
response_json = RestClient.post url, {:publickey=>{:name => name, :data=>data}, :token=>token}.to_json, timeout: 1, :content_type => :json, :accept => :json
|
119
125
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
126
|
+
#def self.keys_add
|
127
|
+
# if !File.exist? "#{Dir.home}/.ssh/id_rsa.pub"
|
128
|
+
# puts "error: File #{Dir.home}/.ssh/id_rsa.pub not found"
|
129
|
+
# puts "You can use this command to generate a key:"
|
130
|
+
# puts " ssh-keygen -t rsa"
|
131
|
+
# return nil
|
132
|
+
# end
|
133
|
+
# name = "id_rsa.pub"
|
134
|
+
# data = `cat ~/.ssh/id_rsa.pub`.chomp
|
135
|
+
# url = "https://www.meroku.com/publickeys.json"
|
136
|
+
# token = `cat ~/.meroku/.token`.chomp
|
137
|
+
# response_json = RestClient.post url, {:publickey=>{:name => name, :data=>data}, :token=>token}.to_json, timeout: 1, :content_type => :json, :accept => :json
|
138
|
+
#
|
139
|
+
# if JSON.parse(response_json)["errors"] && JSON.parse(response_json)["errors"].size > 0
|
140
|
+
# puts JSON.parse(response_json)["errors"].map{|x| x["detail"]}.join(".")
|
141
|
+
# else
|
142
|
+
# name = JSON.parse(response_json)["data"]["attributes"]["name"]
|
143
|
+
# puts "Added #{name}"
|
144
|
+
# end
|
145
|
+
#end
|
127
146
|
|
128
147
|
end
|
129
148
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Meroku
|
2
|
+
module CLI
|
3
|
+
|
4
|
+
module AdminUser
|
5
|
+
|
6
|
+
def self.load_secrets(obj)
|
7
|
+
env_file = Dir.home+'/.meroku/meroku.env'
|
8
|
+
if !File.exist?(env_file)
|
9
|
+
puts "error: File not found (#{Dir.home}/.meroku/meroku.env)"
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
Dotenv.load(env_file)
|
13
|
+
obj.ec2_client = ::Aws::EC2::Client.new(
|
14
|
+
region: 'us-east-1',
|
15
|
+
credentials: ::Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET'])
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Meroku
|
4
|
+
module CLI
|
5
|
+
class Session
|
6
|
+
include Meroku::CLI
|
7
|
+
include Meroku::Infrastructure
|
8
|
+
|
9
|
+
attr_accessor :ec2_client, :token
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
case args.join(" ")
|
13
|
+
when "signup"
|
14
|
+
signup
|
15
|
+
when "create"
|
16
|
+
Meroku::CLI::User.load_secrets(self) || exit
|
17
|
+
create
|
18
|
+
when "keys:add"
|
19
|
+
Meroku::CLI::User.load_secrets(self) || exit
|
20
|
+
keys_add(self)
|
21
|
+
when "infrastructure spawn"
|
22
|
+
Meroku::CLI::AdminUser.load_secrets(self) || exit
|
23
|
+
spawn(self)
|
24
|
+
when "infrastructure despawn"
|
25
|
+
Meroku::CLI::AdminUser.load_secrets(self) || exit
|
26
|
+
despawn
|
27
|
+
else
|
28
|
+
puts "Unknown command #{args.join(" ")}\n\n"
|
29
|
+
puts help
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
#case args.join(" ")
|
34
|
+
# when "infrastructure spawn"
|
35
|
+
# load_secrets || exit
|
36
|
+
# node = Meroku::Infrastructure::Node.new.associate_address.install_packages.install_frontend_app
|
37
|
+
# puts "spawned #{node.instance.try(:instance_id)}"
|
38
|
+
# when "infrastructure despawn"
|
39
|
+
# load_secrets || exit
|
40
|
+
# Meroku::Infrastructure.despawn
|
41
|
+
# when "signup"
|
42
|
+
# signup
|
43
|
+
# when "keys:add"
|
44
|
+
# token_check || exit
|
45
|
+
# keys_add
|
46
|
+
# when "create"
|
47
|
+
# token_check || exit
|
48
|
+
# create
|
49
|
+
# else
|
50
|
+
# puts HELP
|
51
|
+
#end
|
52
|
+
end
|
53
|
+
|
54
|
+
def ec2_client
|
55
|
+
@ec2_client ||= ::Aws::EC2::Client.new(
|
56
|
+
region: 'us-east-1',
|
57
|
+
credentials: ::Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET'])
|
58
|
+
)
|
59
|
+
@ec2_client
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -3,15 +3,24 @@ require "meroku/infrastructure/node"
|
|
3
3
|
module Meroku
|
4
4
|
module Infrastructure
|
5
5
|
|
6
|
-
|
6
|
+
def spawn(session)
|
7
|
+
node = Meroku::Infrastructure::Node.new(session.ec2_client)
|
8
|
+
node.associate_address
|
9
|
+
node.install_packages
|
10
|
+
node.tweak_configuration
|
11
|
+
node.install_frontend_app
|
12
|
+
puts "spawned #{node.instance.try(:instance_id)}"
|
13
|
+
end
|
7
14
|
|
8
|
-
def
|
15
|
+
def despawn
|
9
16
|
instances = ec2_client.describe_instances(filters:[{ name: "tag:Name", values: ['node'] }, { name: 'instance-state-name', values: ['running','pending'] }]).reservations.map { |xx| xx.instances.first.instance_id }
|
10
17
|
puts "will despawn #{instances.inspect}"
|
11
18
|
ec2_client.terminate_instances({
|
12
19
|
instance_ids: instances
|
13
20
|
}) if instances.size > 0
|
14
21
|
end
|
22
|
+
|
23
|
+
|
15
24
|
end
|
16
25
|
|
17
26
|
end
|
@@ -2,11 +2,31 @@
|
|
2
2
|
module Meroku
|
3
3
|
module Infrastructure
|
4
4
|
class Node
|
5
|
-
|
6
|
-
attr_accessor :instance, :tunnel
|
5
|
+
attr_accessor :instance, :tunnel, :ec2_client
|
7
6
|
|
8
|
-
def initialize
|
9
|
-
|
7
|
+
def initialize(ec2_client)
|
8
|
+
@ec2_client = ec2_client
|
9
|
+
result = ec2_client.try(
|
10
|
+
:run_instances,
|
11
|
+
{
|
12
|
+
image_id: 'ami-841f46ff', #was xenial 'ami-cd0f5cb6',
|
13
|
+
min_count: 1,
|
14
|
+
max_count: 1,
|
15
|
+
key_name: 'meroku.id_rsa',
|
16
|
+
instance_type: 't2.micro',
|
17
|
+
tag_specifications: [
|
18
|
+
{
|
19
|
+
resource_type: "instance",
|
20
|
+
tags: [
|
21
|
+
{
|
22
|
+
key: "Name",
|
23
|
+
value: "node",
|
24
|
+
},
|
25
|
+
],
|
26
|
+
},
|
27
|
+
]
|
28
|
+
}
|
29
|
+
)
|
10
30
|
@instance = result.instances.first if result
|
11
31
|
@tunnel = Meroku::Tunnel.new(
|
12
32
|
ip: "34.239.241.218",
|
@@ -20,8 +40,7 @@ module Meroku
|
|
20
40
|
|
21
41
|
def associate_address
|
22
42
|
retries ||= 0
|
23
|
-
|
24
|
-
ec2_client.associate_address(
|
43
|
+
@ec2_client.associate_address(
|
25
44
|
allocation_id: "eipalloc-139f7823",
|
26
45
|
instance_id: @instance.try(:instance_id)
|
27
46
|
)
|
@@ -43,6 +62,12 @@ module Meroku
|
|
43
62
|
self
|
44
63
|
end
|
45
64
|
|
65
|
+
def tweak_configuration
|
66
|
+
@tunnel.run 'sudo adduser --disabled-password --gecos "" git'
|
67
|
+
@tunnel.run 'sudo -u git mkdir /home/git/.ssh/'
|
68
|
+
@tunnel.run 'sudo -u git touch /home/git/.ssh/authorized_keys'
|
69
|
+
end
|
70
|
+
|
46
71
|
def install_frontend_app
|
47
72
|
@tunnel.run 'mkdir /home/ubuntu/.meroku'
|
48
73
|
@tunnel.run "cd ~\; git clone https://github.com/oystersauce8/meroku\;"
|
data/lib/meroku/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Weerasinghe
|
@@ -399,8 +399,10 @@ files:
|
|
399
399
|
- frontend/tmp/.keep
|
400
400
|
- frontend/vendor/.keep
|
401
401
|
- lib/meroku.rb
|
402
|
-
- lib/meroku/aws.rb
|
403
402
|
- lib/meroku/cli.rb
|
403
|
+
- lib/meroku/cli/admin_user.rb
|
404
|
+
- lib/meroku/cli/session.rb
|
405
|
+
- lib/meroku/cli/user.rb
|
404
406
|
- lib/meroku/infrastructure.rb
|
405
407
|
- lib/meroku/infrastructure/node.rb
|
406
408
|
- lib/meroku/tunnel.rb
|
data/lib/meroku/aws.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
module Aws
|
3
|
-
|
4
|
-
EC2_PARAMS = {
|
5
|
-
image_id: 'ami-841f46ff', #was xenial 'ami-cd0f5cb6',
|
6
|
-
min_count: 1,
|
7
|
-
max_count: 1,
|
8
|
-
key_name: 'meroku.id_rsa',
|
9
|
-
instance_type: 't2.micro',
|
10
|
-
tag_specifications: [
|
11
|
-
{
|
12
|
-
resource_type: "instance",
|
13
|
-
tags: [
|
14
|
-
{
|
15
|
-
key: "Name",
|
16
|
-
value: "node",
|
17
|
-
},
|
18
|
-
],
|
19
|
-
},
|
20
|
-
]
|
21
|
-
}
|
22
|
-
|
23
|
-
def credentials
|
24
|
-
::Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET'])
|
25
|
-
end
|
26
|
-
|
27
|
-
def ec2_client
|
28
|
-
::Aws::EC2::Client.new(region: 'us-east-1', credentials: credentials)
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|