mimas 0.1.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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/Gemfile +12 -0
  4. data/Gemfile.lock +106 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +346 -0
  7. data/Rakefile +4 -0
  8. data/bin/mimas +5 -0
  9. data/lib/mimas/archiver.rb +68 -0
  10. data/lib/mimas/base_command.rb +22 -0
  11. data/lib/mimas/cli.rb +22 -0
  12. data/lib/mimas/commands/console.rb +21 -0
  13. data/lib/mimas/commands/init.rb +63 -0
  14. data/lib/mimas/commands/install.rb +21 -0
  15. data/lib/mimas/commands/provision.rb +50 -0
  16. data/lib/mimas/commands/push.rb +28 -0
  17. data/lib/mimas/commands/setup/caddy.rb +18 -0
  18. data/lib/mimas/commands/setup/deploy_user.rb +16 -0
  19. data/lib/mimas/commands/setup/ruby.rb +17 -0
  20. data/lib/mimas/commands/setup.rb +10 -0
  21. data/lib/mimas/config.rb +124 -0
  22. data/lib/mimas/deployment/caddy.rb +39 -0
  23. data/lib/mimas/deployment/files.rb +51 -0
  24. data/lib/mimas/deployment/paths.rb +54 -0
  25. data/lib/mimas/deployment/ruby_app.rb +126 -0
  26. data/lib/mimas/deployment/static_site.rb +28 -0
  27. data/lib/mimas/deployment.rb +27 -0
  28. data/lib/mimas/hooks.rb +25 -0
  29. data/lib/mimas/plugins.rb +19 -0
  30. data/lib/mimas/scripts/configure_ruby.sh +19 -0
  31. data/lib/mimas/scripts/create_deploy_user.sh +30 -0
  32. data/lib/mimas/scripts/harden.sh +125 -0
  33. data/lib/mimas/scripts/install_caddy.sh +51 -0
  34. data/lib/mimas/scripts/install_ruby_prerequisites.sh +26 -0
  35. data/lib/mimas/server/caddy.rb +17 -0
  36. data/lib/mimas/server/console.rb +34 -0
  37. data/lib/mimas/server/deploy_user.rb +11 -0
  38. data/lib/mimas/server/harden.rb +20 -0
  39. data/lib/mimas/server/prerequisites.rb +25 -0
  40. data/lib/mimas/server/ruby.rb +37 -0
  41. data/lib/mimas/server.rb +37 -0
  42. data/lib/mimas/site.rb +24 -0
  43. data/lib/mimas/ssh.rb +78 -0
  44. data/lib/mimas/template.rb +28 -0
  45. data/lib/mimas/templates/Caddyfile.ruby.erb +12 -0
  46. data/lib/mimas/templates/Caddyfile.static.erb +15 -0
  47. data/lib/mimas/templates/caddy.service.erb +19 -0
  48. data/lib/mimas/templates/config.rb.erb +51 -0
  49. data/lib/mimas/templates/falcon.rb.erb +12 -0
  50. data/lib/mimas/templates/mimas.env.erb +2 -0
  51. data/lib/mimas/templates/puma.rb +11 -0
  52. data/lib/mimas/templates/systemd.service.erb +20 -0
  53. data/lib/mimas/terminal/ansi.rb +71 -0
  54. data/lib/mimas/terminal/printer.rb +14 -0
  55. data/lib/mimas/version.rb +3 -0
  56. data/lib/mimas.rb +48 -0
  57. data/mimas.gemspec +29 -0
  58. data/scripts/release +8 -0
  59. data/scripts/test +7 -0
  60. data/tmp/.keep +0 -0
  61. metadata +181 -0
@@ -0,0 +1,51 @@
1
+ <% if site_type == :static -%>
2
+ site do
3
+ domain "<%= domain %>"
4
+ root_dir "output"
5
+ glob "**/*"
6
+ end
7
+ <% elsif site_type == :ruby -%>
8
+ site do
9
+ domain "<%= domain %>"
10
+ files do
11
+ `git ls-files -z`.split("\x0")
12
+ .reject { it.match(%r!(bin|mimas.rb|Caddyfile)!) }
13
+ end
14
+
15
+ healthcheck_path "/"
16
+
17
+ # Define the console command for your app here.
18
+ # You can then access the console by running `mimas console SERVER_NAME`
19
+ # console "bundle console"
20
+
21
+ # env do
22
+ # <<~STRING
23
+ # STRING
24
+ # end
25
+
26
+ # Mimas automatically runs `bundle install` on deploy if no deploy script is defined.
27
+ # Ensure you invoke `bundle install` if you provide your own script here.
28
+ # deploy do
29
+ # <<~STRING
30
+ # STRING
31
+ # end
32
+
33
+ services do
34
+ web do
35
+ <% if app_server == "puma" -%>
36
+ start "bundle exec puma -C deploy/puma.rb"
37
+ <% elsif app_server == "falcon" -%>
38
+ start "bundle exec falcon host deploy/falcon.rb"
39
+ <% else -%>
40
+ # TODO: Add your server's start command
41
+ start "bundle exec #start server"
42
+ <% end -%>
43
+ end
44
+ end
45
+ end
46
+ <% end -%>
47
+
48
+ server :production do
49
+ host "<%= ip %>"
50
+ user "deploy"
51
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env falcon-host
2
+
3
+ require "falcon/environment/rack"
4
+
5
+ service "<%= domain %>" do
6
+ include Falcon::Environment::Rack
7
+
8
+ rackup_path File.expand_path("../config.ru", root)
9
+ ipc_path ENV["MIMAS_UNIX_SOCKET"]
10
+ scheme "http"
11
+ protocol Async::HTTP::Protocol::HTTP
12
+ end
@@ -0,0 +1,2 @@
1
+ MIMAS_UNIX_SOCKET=<%= unix_socket %>
2
+ <%= env %>
@@ -0,0 +1,11 @@
1
+ # Puma config file
2
+ #
3
+ # Learn more at: https://puma.io
4
+ #
5
+ # This is not a production ready Puma configuration.
6
+ # Customise you worker and thread count as per your needs.
7
+ # Mimas requires the `bind` directive as defined below to configure the reverse proxy
8
+ # and perform health checks.
9
+
10
+ bind "unix://#{ENV["MIMAS_UNIX_SOCKET"]
11
+
@@ -0,0 +1,20 @@
1
+ [Unit]
2
+ Description=<%= domain %>--<%= service_name %>--<%= version %>
3
+ After=network.target
4
+
5
+ [Service]
6
+ Type=notify
7
+ NotifyAccess=all
8
+ User=<%= user %>
9
+ EnvironmentFile=<%= site_root %>/.env
10
+ EnvironmentFile=<%= site_root %>/mimas/mimas.env
11
+ WorkingDirectory=<%= site_root %>/current
12
+ ExecStart=/usr/bin/env bash -lc '<%= command %>'
13
+ StandardOutput=append:<%= site_root %>/logs/<%= service_name %>.log
14
+ StandardError=append:<%= site_root %>/logs/<%= service_name %>.log
15
+ KillMode=mixed
16
+ TimeoutStopSec=60
17
+ Restart=always
18
+
19
+ [Install]
20
+ WantedBy=default.target
@@ -0,0 +1,71 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2020-present Jared White and Bridgetown contributors
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ module Mimas
24
+ module Terminal
25
+ module Ansi
26
+ ESCAPE = format("%c", 27)
27
+ MATCH = %r!#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m!ix
28
+ COLORS = {
29
+ bold: 1,
30
+ black: 30,
31
+ red: 31,
32
+ green: 32,
33
+ yellow: 33,
34
+ blue: 34,
35
+ magenta: 35,
36
+ cyan: 36,
37
+ white: 37,
38
+ }.freeze
39
+
40
+ # Strip ANSI from the current string. It also strips cursor stuff,
41
+ # well some of it, and it also strips some other stuff that a lot of
42
+ # the other ANSI strippers don't.
43
+ def strip_ansi
44
+ gsub MATCH, ""
45
+ end
46
+
47
+ # Does the string include ANSI color codes?
48
+ def has_ansi?
49
+ !!(self =~ MATCH)
50
+ end
51
+
52
+ # Reset the color back to the default color so that you do not leak any
53
+ # colors when you move onto the next line. This is probably normally
54
+ # used as part of a wrapper so that we don't leak colors.
55
+ def reset_ansi
56
+ @reset_ansi ||= format("%c[0m", 27)
57
+ end
58
+
59
+ # SEE: `self::COLORS` for a list of methods. They are mostly
60
+ # standard base colors supported by pretty much any xterm-color, we do
61
+ # not need more than the base colors so we do not include them.
62
+ COLORS.each do |color, num|
63
+ define_method color do
64
+ "#{format("%c", 27)}[#{num}m#{self}#{reset_ansi}"
65
+ end
66
+ end
67
+ end
68
+
69
+ ::String.include Ansi
70
+ end
71
+ end
@@ -0,0 +1,14 @@
1
+ module Mimas
2
+ module Terminal
3
+ module Printer
4
+ def say(sentence)
5
+ $stdout.puts sentence
6
+ end
7
+
8
+ def ask(question)
9
+ $stdout.print "#{question}: "
10
+ $stdin.gets.chomp
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Mimas
2
+ VERSION = "0.1.0"
3
+ end
data/lib/mimas.rb ADDED
@@ -0,0 +1,48 @@
1
+ require "dry/cli"
2
+ require "net/ssh"
3
+ require "net/scp"
4
+ require "erb"
5
+
6
+ require_relative "mimas/terminal/printer"
7
+ require_relative "mimas/terminal/ansi"
8
+ require_relative "mimas/template"
9
+ require_relative "mimas/archiver"
10
+ require_relative "mimas/ssh"
11
+ require_relative "mimas/hooks"
12
+
13
+ require_relative "mimas/config"
14
+
15
+ require_relative "mimas/site"
16
+
17
+ require_relative "mimas/server/prerequisites"
18
+ require_relative "mimas/server/harden"
19
+ require_relative "mimas/server/deploy_user"
20
+ require_relative "mimas/server/caddy"
21
+ require_relative "mimas/server/ruby"
22
+ require_relative "mimas/server"
23
+
24
+ require_relative "mimas/deployment/caddy"
25
+ require_relative "mimas/deployment/files"
26
+ require_relative "mimas/deployment/paths"
27
+ require_relative "mimas/deployment/ruby_app"
28
+ require_relative "mimas/deployment/static_site"
29
+ require_relative "mimas/deployment"
30
+
31
+ require_relative "mimas/plugins"
32
+
33
+ require_relative "mimas/base_command"
34
+ require_relative "mimas/commands/console"
35
+ require_relative "mimas/commands/init"
36
+ require_relative "mimas/commands/install"
37
+ require_relative "mimas/commands/provision"
38
+ require_relative "mimas/commands/push"
39
+ require_relative "mimas/commands/setup"
40
+ require_relative "mimas/commands/setup/caddy"
41
+ require_relative "mimas/commands/setup/deploy_user"
42
+ require_relative "mimas/commands/setup/ruby"
43
+
44
+ Bundler.load.requested_specs
45
+ .filter { it.metadata[:mimas_plugin] }
46
+ .each { require it.name }
47
+
48
+ require_relative "mimas/cli"
data/mimas.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mimas/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mimas"
7
+ spec.version = Mimas::VERSION
8
+ spec.author = "Ayush Newatia"
9
+ spec.email = "ayush@hey.com"
10
+ spec.summary = "Deploy Ruby apps to a single server using an omakase setup"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test)/!) }
14
+ spec.test_files = spec.files.grep(%r!^test/!)
15
+
16
+ spec.executables = ["mimas"]
17
+ spec.bindir = "bin"
18
+
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 3.4.0"
22
+
23
+ spec.add_dependency "dry-cli", "~> 1.4"
24
+ spec.add_dependency "net-ssh", "~> 7.3"
25
+ spec.add_dependency "net-scp", "~> 4.1"
26
+ spec.add_dependency "ed25519", "~> 1.2"
27
+ spec.add_dependency "bcrypt_pbkdf", "~> 1.0"
28
+ spec.add_dependency "logger", "~> 1.7" # Needed for net-ssh
29
+ end
data/scripts/release ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ # Tag and push a release to Rubygems
4
+
5
+ set -e
6
+
7
+ script/test
8
+ bundle exec rake release
data/scripts/test ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ # Run the tests
4
+
5
+ set -e
6
+
7
+ bundle exec rake test
data/tmp/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mimas
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ayush Newatia
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-07-22 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: dry-cli
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.4'
26
+ - !ruby/object:Gem::Dependency
27
+ name: net-ssh
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.3'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.3'
40
+ - !ruby/object:Gem::Dependency
41
+ name: net-scp
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: ed25519
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.2'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.2'
68
+ - !ruby/object:Gem::Dependency
69
+ name: bcrypt_pbkdf
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: logger
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.7'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.7'
96
+ email: ayush@hey.com
97
+ executables:
98
+ - mimas
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - bin/mimas
109
+ - lib/mimas.rb
110
+ - lib/mimas/archiver.rb
111
+ - lib/mimas/base_command.rb
112
+ - lib/mimas/cli.rb
113
+ - lib/mimas/commands/console.rb
114
+ - lib/mimas/commands/init.rb
115
+ - lib/mimas/commands/install.rb
116
+ - lib/mimas/commands/provision.rb
117
+ - lib/mimas/commands/push.rb
118
+ - lib/mimas/commands/setup.rb
119
+ - lib/mimas/commands/setup/caddy.rb
120
+ - lib/mimas/commands/setup/deploy_user.rb
121
+ - lib/mimas/commands/setup/ruby.rb
122
+ - lib/mimas/config.rb
123
+ - lib/mimas/deployment.rb
124
+ - lib/mimas/deployment/caddy.rb
125
+ - lib/mimas/deployment/files.rb
126
+ - lib/mimas/deployment/paths.rb
127
+ - lib/mimas/deployment/ruby_app.rb
128
+ - lib/mimas/deployment/static_site.rb
129
+ - lib/mimas/hooks.rb
130
+ - lib/mimas/plugins.rb
131
+ - lib/mimas/scripts/configure_ruby.sh
132
+ - lib/mimas/scripts/create_deploy_user.sh
133
+ - lib/mimas/scripts/harden.sh
134
+ - lib/mimas/scripts/install_caddy.sh
135
+ - lib/mimas/scripts/install_ruby_prerequisites.sh
136
+ - lib/mimas/server.rb
137
+ - lib/mimas/server/caddy.rb
138
+ - lib/mimas/server/console.rb
139
+ - lib/mimas/server/deploy_user.rb
140
+ - lib/mimas/server/harden.rb
141
+ - lib/mimas/server/prerequisites.rb
142
+ - lib/mimas/server/ruby.rb
143
+ - lib/mimas/site.rb
144
+ - lib/mimas/ssh.rb
145
+ - lib/mimas/template.rb
146
+ - lib/mimas/templates/Caddyfile.ruby.erb
147
+ - lib/mimas/templates/Caddyfile.static.erb
148
+ - lib/mimas/templates/caddy.service.erb
149
+ - lib/mimas/templates/config.rb.erb
150
+ - lib/mimas/templates/falcon.rb.erb
151
+ - lib/mimas/templates/mimas.env.erb
152
+ - lib/mimas/templates/puma.rb
153
+ - lib/mimas/templates/systemd.service.erb
154
+ - lib/mimas/terminal/ansi.rb
155
+ - lib/mimas/terminal/printer.rb
156
+ - lib/mimas/version.rb
157
+ - mimas.gemspec
158
+ - scripts/release
159
+ - scripts/test
160
+ - tmp/.keep
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: 3.4.0
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubygems_version: 3.6.2
179
+ specification_version: 4
180
+ summary: Deploy Ruby apps to a single server using an omakase setup
181
+ test_files: []