mimas 0.4.0 → 0.6.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/lib/mimas/cli.rb +3 -4
- data/lib/mimas/commands/console.rb +3 -3
- data/lib/mimas/commands/push.rb +4 -4
- data/lib/mimas/commands/{install.rb → ruby/install.rb} +1 -1
- data/lib/mimas/commands/ruby.rb +8 -0
- data/lib/mimas/scripts/harden.sh +1 -1
- data/lib/mimas/server/console.rb +2 -24
- data/lib/mimas/ssh/interactive.rb +33 -0
- data/lib/mimas/ssh/session.rb +74 -0
- data/lib/mimas/ssh.rb +1 -70
- data/lib/mimas/template.rb +11 -0
- data/lib/mimas/templates/mimas.env.erb +2 -0
- data/lib/mimas/version.rb +1 -1
- data/lib/mimas.rb +4 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6dc4a3414f0933e28ec8423cfe5a196ab7d71e7f29bf49ebe90c769a0ad639e5
|
|
4
|
+
data.tar.gz: 828a20632f35dc23aec49355b97f542b71453be576bc2054becf95d6b489b316
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4d3bd8d2c05458282bac661ef17eca0bb75b945c4c09c95bf8aedaac7b7ea9109caf775dc1d6406db6238538504def83fccf616496423d6e464d3a6f6c9e1e3
|
|
7
|
+
data.tar.gz: b37b16ff9c64cfb233dc2a5d1b6274908f4be362b96c8eb9c4bc99536dbe32e173296825116775e158950543d33b95e8cfa3163a8330b838906566a7d48e6086
|
data/lib/mimas/cli.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Mimas
|
|
|
4
4
|
extend Dry::CLI::Registry
|
|
5
5
|
|
|
6
6
|
register "init", Init
|
|
7
|
-
register "install
|
|
7
|
+
register "ruby install", Ruby::Install
|
|
8
8
|
register "provision", Provision
|
|
9
9
|
register "push", Push, aliases: ["deploy"]
|
|
10
10
|
register "console", Console
|
|
@@ -19,9 +19,8 @@ module Mimas
|
|
|
19
19
|
|
|
20
20
|
Plugins.fetch.each do |plugin|
|
|
21
21
|
# Register plugin commands
|
|
22
|
-
plugin.
|
|
23
|
-
|
|
24
|
-
end if plugin.respond_to?(:commands)
|
|
22
|
+
plugin.register_commands(Mimas::CLI::Commands) \
|
|
23
|
+
if plugin.respond_to?(:register_commands)
|
|
25
24
|
|
|
26
25
|
# Add plugin template paths to lookup array
|
|
27
26
|
Mimas::Template.lookup_paths.unshift(Pathname.new(plugin.templates_dir.to_s)) \
|
|
@@ -4,12 +4,12 @@ module Mimas
|
|
|
4
4
|
class Console < BaseCommand
|
|
5
5
|
desc "Run your app's console"
|
|
6
6
|
|
|
7
|
-
argument :server_name, required: true, desc: "The name of the server to run the console on"
|
|
8
7
|
argument :site, default: :default, desc: "The site to run the console for. Uses the default site if unspecified"
|
|
8
|
+
argument :server_name, required: true, desc: "The name of the server to run the console on"
|
|
9
9
|
|
|
10
|
-
def call(
|
|
11
|
-
server = Config.current.servers[server_name.to_sym]
|
|
10
|
+
def call(site:, server_name:, **)
|
|
12
11
|
site = Config.current.sites[site.to_sym]
|
|
12
|
+
server = Config.current.servers[server_name.to_sym]
|
|
13
13
|
|
|
14
14
|
raise "Please add a `console` directive to your config file" unless site.respond_to?(:console)
|
|
15
15
|
|
data/lib/mimas/commands/push.rb
CHANGED
|
@@ -4,17 +4,17 @@ module Mimas
|
|
|
4
4
|
class Push < BaseCommand
|
|
5
5
|
desc "Push your Ruby app to the server"
|
|
6
6
|
|
|
7
|
-
argument :server_name, required: true, desc: "The name of the server to push to"
|
|
8
7
|
argument :site, default: :default, desc: "The site to push. Uses the default site if unspecified"
|
|
8
|
+
argument :server_name, required: true, desc: "The name of the server to push to"
|
|
9
9
|
|
|
10
10
|
example [
|
|
11
11
|
"production # Push the default site to the production server",
|
|
12
|
-
"production
|
|
12
|
+
"app production # Push the `:app` site to the production server"
|
|
13
13
|
]
|
|
14
14
|
|
|
15
|
-
def call(
|
|
16
|
-
server = Config.current.servers[server_name.to_sym]
|
|
15
|
+
def call(site:, server_name:, **)
|
|
17
16
|
site = Config.current.sites[site.to_sym]
|
|
17
|
+
server = Config.current.servers[server_name.to_sym]
|
|
18
18
|
|
|
19
19
|
unless server && site
|
|
20
20
|
say "Server or site not found. Please ensure you've invoked the command correctly.".red
|
data/lib/mimas/scripts/harden.sh
CHANGED
|
@@ -30,7 +30,7 @@ passwd -ld admin
|
|
|
30
30
|
rsync --archive --chown=admin:admin ~/.ssh /home/admin
|
|
31
31
|
|
|
32
32
|
# Allow passwordless sudo for `admin`
|
|
33
|
-
echo "%admin $(cat /etc/hostname)=(
|
|
33
|
+
echo "%admin $(cat /etc/hostname)=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/admin
|
|
34
34
|
|
|
35
35
|
# Validate the modified sudoers file
|
|
36
36
|
if ! visudo -c -f /etc/sudoers.d/admin; then
|
data/lib/mimas/server/console.rb
CHANGED
|
@@ -3,31 +3,9 @@ module Mimas
|
|
|
3
3
|
module Console
|
|
4
4
|
def start_console(site)
|
|
5
5
|
console_command = site.console
|
|
6
|
+
exec_command = "cd #{current_path(site)} && ~/.cargo/bin/rv run #{console_command}"
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
Net::SSH.start(host, user) do |session|
|
|
9
|
-
session.open_channel do |channel|
|
|
10
|
-
channel.request_pty do
|
|
11
|
-
channel.exec("cd #{current_path(site)} && ~/.cargo/bin/rv run #{console_command}") do
|
|
12
|
-
channel.on_data do |_, data|
|
|
13
|
-
$stdout.print(data) if data
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
channel.on_extended_data do |_, data|
|
|
17
|
-
$stdout.print(data) if data
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
session.listen_to($stdin) do |stdin|
|
|
21
|
-
input = stdin.readpartial(1024)
|
|
22
|
-
channel.send_data(input) unless input.empty?
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
session.loop
|
|
28
|
-
end
|
|
29
|
-
ensure
|
|
30
|
-
system('stty sane')
|
|
8
|
+
interactive_ssh(host, user: user, command: exec_command)
|
|
31
9
|
end
|
|
32
10
|
end
|
|
33
11
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Mimas
|
|
2
|
+
module SSH
|
|
3
|
+
module Interactive
|
|
4
|
+
def interactive_ssh(host, user:, command:)
|
|
5
|
+
system('stty raw -echo')
|
|
6
|
+
|
|
7
|
+
Net::SSH.start(host, user) do |session|
|
|
8
|
+
session.open_channel do |channel|
|
|
9
|
+
channel.request_pty do
|
|
10
|
+
channel.exec(command) do
|
|
11
|
+
channel.on_data do |_, data|
|
|
12
|
+
$stdout.print(data) if data
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
channel.on_extended_data do |_, data|
|
|
16
|
+
$stdout.print(data) if data
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
session.listen_to($stdin) do |stdin|
|
|
20
|
+
input = stdin.readpartial(1024)
|
|
21
|
+
channel.send_data(input) unless input.empty?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
session.loop
|
|
27
|
+
end
|
|
28
|
+
ensure
|
|
29
|
+
system('stty sane')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Mimas
|
|
2
|
+
module SSH
|
|
3
|
+
class Session
|
|
4
|
+
class NonZeroExitCode < StandardError
|
|
5
|
+
attr_reader :exit_code, :output
|
|
6
|
+
def initialize(command:, exit_code:, output:)
|
|
7
|
+
@command = command
|
|
8
|
+
@exit_code = exit_code
|
|
9
|
+
@output = output
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_s
|
|
13
|
+
"'#{@command}' exited with code: #{@exit_code}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(server, user:)
|
|
18
|
+
@server = server
|
|
19
|
+
@user = user || server.user
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def perform(&block)
|
|
23
|
+
@ssh = Net::SSH.start(@server.host, @user, timeout: 60, **@server.ssh_options)
|
|
24
|
+
@hostname = run("cat /etc/hostname", capture: true).chomp
|
|
25
|
+
yield(self)
|
|
26
|
+
ensure
|
|
27
|
+
@ssh&.close
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def run(command, capture: false, silent: false)
|
|
31
|
+
status = {}
|
|
32
|
+
output = ""
|
|
33
|
+
@ssh.exec!(command, status: status) do |channel, stream, data|
|
|
34
|
+
if capture
|
|
35
|
+
output << data
|
|
36
|
+
elsif stream == :stderr
|
|
37
|
+
print "#{data}".bold.red
|
|
38
|
+
else
|
|
39
|
+
print "#{data}".white
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if status[:exit_code] != 0 && !silent
|
|
44
|
+
raise NonZeroExitCode.new(command: command, exit_code: status[:exit_code], output: output)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
return output if capture
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def upload(source_file, destination_file)
|
|
51
|
+
@ssh.scp.upload! source_file, destination_file
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def script(name, sudo: false, vars: {})
|
|
55
|
+
filename = "#{name}.sh"
|
|
56
|
+
remote_location = "/tmp/#{filename}"
|
|
57
|
+
|
|
58
|
+
source_path = File.expand_path("../scripts/#{filename}", __dir__)
|
|
59
|
+
upload source_path, remote_location
|
|
60
|
+
run "chmod +x #{remote_location}"
|
|
61
|
+
|
|
62
|
+
vars = vars.to_a.map { it.join("=") }.join(" ")
|
|
63
|
+
|
|
64
|
+
exec_command = remote_location
|
|
65
|
+
exec_command = "#{vars} #{exec_command}".strip
|
|
66
|
+
exec_command = "sudo #{exec_command}" if sudo
|
|
67
|
+
|
|
68
|
+
run exec_command
|
|
69
|
+
|
|
70
|
+
run "rm #{remote_location}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
data/lib/mimas/ssh.rb
CHANGED
|
@@ -4,75 +4,6 @@ module Mimas
|
|
|
4
4
|
Session.new(server, user: user).perform(&block)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
class NonZeroExitCode < StandardError
|
|
9
|
-
attr_reader :exit_code, :output
|
|
10
|
-
def initialize(command:, exit_code:, output:)
|
|
11
|
-
@command = command
|
|
12
|
-
@exit_code = exit_code
|
|
13
|
-
@output = output
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def to_s
|
|
17
|
-
"'#{@command}' exited with code: #{@exit_code}"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def initialize(server, user:)
|
|
22
|
-
@server = server
|
|
23
|
-
@user = user || server.user
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def perform(&block)
|
|
27
|
-
@ssh = Net::SSH.start(@server.host, @user, timeout: 60, **@server.ssh_options)
|
|
28
|
-
@hostname = run("cat /etc/hostname", capture: true).chomp
|
|
29
|
-
yield(self)
|
|
30
|
-
ensure
|
|
31
|
-
@ssh&.close
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def run(command, capture: false, silent: false)
|
|
35
|
-
status = {}
|
|
36
|
-
output = ""
|
|
37
|
-
@ssh.exec!(command, status: status) do |channel, stream, data|
|
|
38
|
-
if capture
|
|
39
|
-
output << data
|
|
40
|
-
elsif stream == :stderr
|
|
41
|
-
print "#{data}".bold.red
|
|
42
|
-
else
|
|
43
|
-
print "#{data}".white
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
if status[:exit_code] != 0 && !silent
|
|
48
|
-
raise NonZeroExitCode.new(command: command, exit_code: status[:exit_code], output: output)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
return output if capture
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def upload(source_file, destination_file)
|
|
55
|
-
@ssh.scp.upload! source_file, destination_file
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def script(name, sudo: false, vars: {})
|
|
59
|
-
filename = "#{name}.sh"
|
|
60
|
-
remote_location = "/tmp/#{filename}"
|
|
61
|
-
|
|
62
|
-
source_path = File.expand_path("./scripts/#{filename}", __dir__)
|
|
63
|
-
upload source_path, remote_location
|
|
64
|
-
run "chmod +x #{remote_location}"
|
|
65
|
-
|
|
66
|
-
vars = vars.to_a.map { it.join("=") }.join(" ")
|
|
67
|
-
|
|
68
|
-
exec_command = remote_location
|
|
69
|
-
exec_command = "#{vars} #{exec_command}".strip
|
|
70
|
-
exec_command = "sudo #{exec_command}" if sudo
|
|
71
|
-
|
|
72
|
-
run exec_command
|
|
73
|
-
|
|
74
|
-
run "rm #{remote_location}"
|
|
75
|
-
end
|
|
76
|
-
end
|
|
7
|
+
include Interactive
|
|
77
8
|
end
|
|
78
9
|
end
|
data/lib/mimas/template.rb
CHANGED
|
@@ -20,6 +20,17 @@ module Mimas
|
|
|
20
20
|
FileUtils.copy(source, File.join(destination, rename || source_file_name))
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def find_files(glob)
|
|
24
|
+
files = []
|
|
25
|
+
|
|
26
|
+
Mimas::Template.lookup_paths.each do |path|
|
|
27
|
+
found_files = Dir.glob(path.join(glob))
|
|
28
|
+
files.push(*found_files)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
files
|
|
32
|
+
end
|
|
33
|
+
|
|
23
34
|
BASE_DIRECTORY = Pathname.new(__dir__).join("templates")
|
|
24
35
|
def self.lookup_paths
|
|
25
36
|
MUTEX.synchronize { @lookup_paths ||= [BASE_DIRECTORY] }
|
data/lib/mimas/version.rb
CHANGED
data/lib/mimas.rb
CHANGED
|
@@ -11,6 +11,8 @@ require_relative "mimas/terminal/printer"
|
|
|
11
11
|
require_relative "mimas/terminal/ansi"
|
|
12
12
|
require_relative "mimas/template"
|
|
13
13
|
require_relative "mimas/archiver"
|
|
14
|
+
require_relative "mimas/ssh/session"
|
|
15
|
+
require_relative "mimas/ssh/interactive"
|
|
14
16
|
require_relative "mimas/ssh"
|
|
15
17
|
require_relative "mimas/hooks"
|
|
16
18
|
|
|
@@ -40,9 +42,10 @@ require_relative "mimas/base_command"
|
|
|
40
42
|
require_relative "mimas/commands/archive"
|
|
41
43
|
require_relative "mimas/commands/console"
|
|
42
44
|
require_relative "mimas/commands/init"
|
|
43
|
-
require_relative "mimas/commands/install"
|
|
44
45
|
require_relative "mimas/commands/provision"
|
|
45
46
|
require_relative "mimas/commands/push"
|
|
47
|
+
require_relative "mimas/commands/ruby"
|
|
48
|
+
require_relative "mimas/commands/ruby/install"
|
|
46
49
|
require_relative "mimas/commands/setup"
|
|
47
50
|
require_relative "mimas/commands/setup/caddy"
|
|
48
51
|
require_relative "mimas/commands/setup/deploy_user"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mimas
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ayush Newatia
|
|
@@ -107,9 +107,10 @@ files:
|
|
|
107
107
|
- lib/mimas/commands/archive.rb
|
|
108
108
|
- lib/mimas/commands/console.rb
|
|
109
109
|
- lib/mimas/commands/init.rb
|
|
110
|
-
- lib/mimas/commands/install.rb
|
|
111
110
|
- lib/mimas/commands/provision.rb
|
|
112
111
|
- lib/mimas/commands/push.rb
|
|
112
|
+
- lib/mimas/commands/ruby.rb
|
|
113
|
+
- lib/mimas/commands/ruby/install.rb
|
|
113
114
|
- lib/mimas/commands/setup.rb
|
|
114
115
|
- lib/mimas/commands/setup/caddy.rb
|
|
115
116
|
- lib/mimas/commands/setup/deploy_user.rb
|
|
@@ -137,6 +138,8 @@ files:
|
|
|
137
138
|
- lib/mimas/site.rb
|
|
138
139
|
- lib/mimas/site/archive.rb
|
|
139
140
|
- lib/mimas/ssh.rb
|
|
141
|
+
- lib/mimas/ssh/interactive.rb
|
|
142
|
+
- lib/mimas/ssh/session.rb
|
|
140
143
|
- lib/mimas/template.rb
|
|
141
144
|
- lib/mimas/templates/Caddyfile.ruby.erb
|
|
142
145
|
- lib/mimas/templates/Caddyfile.static.erb
|