mimas 0.4.0 → 0.5.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: 89a173c94a94713193d4a7c75a56b3aea832ac73d414fece78c19b4a331e4065
4
- data.tar.gz: 5cba822934db35c755f15109611c970c9e417309df4888f17a6ec1fc0a485634
3
+ metadata.gz: 8dc43f51b6e12503251f7aae375c26c7231f0ae96549c675bf82b040604560d6
4
+ data.tar.gz: 03fbdf89bcb00a7f976cb25fe21ae3c662ad0c5abb904509bd986e5743f789bc
5
5
  SHA512:
6
- metadata.gz: e8a56d19ff9fa37ed56e486b5cc6caedb172ce9b78e8b9232ef6706fa2ed2daef0bbde3ab5721aee683e3f8a2ed0aef09a8fb60c5449085712aeab2751d9cb90
7
- data.tar.gz: 1a02a80c18fb91f212052d6cbe68bf6b418328e5597611ed95659d34df4bf780558bf05d60ebc642fc2a7f79d86767e1a73aee65e8e72b1a65d8266d9fcc4e19
6
+ metadata.gz: 02ad0133e8c2d58f3b8b1d2b666da86ce006d6f7fd402e3818478e80f41a6cc226957244fd8ac7b16927b2afb722dd3b143404d597d0694dded2da8fd3e92e0a
7
+ data.tar.gz: 17a0cfda68a7a0e8f37479435b9efb472043447d09f126d774fd9905d53b94681a87cfcfc55cac7a6a46755d5322c7e97ced66212d11ce22c95b8181d70dfb62
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 ruby", 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.commands.each do |command, target|
23
- CLI::Commands.register(command.to_s, target)
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(server_name:, site:, **)
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
 
@@ -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 app # Push the `:app` site to the production server"
12
+ "app production # Push the `:app` site to the production server"
13
13
  ]
14
14
 
15
- def call(server_name:, site:, **)
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
@@ -1,7 +1,7 @@
1
1
  module Mimas
2
2
  module CLI
3
3
  module Commands
4
- class Install < BaseCommand
4
+ class Ruby::Install < BaseCommand
5
5
  desc "Install a new version of Ruby on the server."
6
6
 
7
7
  argument :ruby_version, required: true, desc: "The version of Ruby to install."
@@ -0,0 +1,8 @@
1
+ module Mimas
2
+ module CLI
3
+ module Commands
4
+ class Ruby < BaseCommand
5
+ end
6
+ end
7
+ end
8
+ end
@@ -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)=(root) NOPASSWD:ALL" > /etc/sudoers.d/admin
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
@@ -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
- system('stty cbreak -echo')
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 cbreak -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
- class Session
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
@@ -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] }
@@ -1,4 +1,6 @@
1
1
  MIMAS_UNIX_SOCKET=<%= unix_socket %>
2
2
  RUBY_YJIT_ENABLE=1
3
+ <%# https://gist.github.com/jjb/9ff0d3f622c8bbe904fe7a82e35152fc %>
3
4
  LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so
5
+ MALLOC_CONF='dirty_decay_ms:1000,narenas:2,background_thread:true'
4
6
  <%= env %>
data/lib/mimas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mimas
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
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.0
4
+ version: 0.5.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