Deploy Ruby Apps
Ruby installation is powered by rvm. To install stable (latest - 1) version with deployment script:
features:
- ruby
Without this, you're using OS-dependent ruby
and gem
which the version can't be customized.
Install other version using ruby latest
, ruby stable
, ruby 3.1
, ruby 3.1.1
, etc. To uninstall use ruby off
or ruby system
(the latter leaves rvm installed). Check the current version using ruby --version
from SSH.
Example
The deployment script below installs the latest ruby
compiler and writes app.rb
and serves that through config.ru
bindings.
features:
- ruby latest
nginx:
root: public_html/public
passenger:
enabled: "on"
ruby: .rvm/rubies/default/bin/ruby
source: clear
commands:
- filename: app.rb
content: |
$html_text = <<-TEXT
<!DOCTYPE html>
<html>
<head>
<title>Ruby App</title>
<link rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css">
</head>
<body class="p-5 text-center">
<p><img src="//images.unsplash.com/photo-1465153690352-10c1b29577f8?fit=crop&w=200&h=200"
class="img-fluid rounded-circle"></p>
<h1 class="mb-3">Hello, world!</h1>
<p>Serving from Ruby version %{ver}</p>
<p class="text-muted">DOM Cloud</p>
</body>
</html>
TEXT
class App
def call(env)
return [200,
{"content-type" => "text/html"},
[$html_text % {ver: RUBY_VERSION}]]
end
end
- filename: config.ru
content: |
require './app'
run App.new
Existing Ruby projects
For existing ruby apps, use the deployment script below. Note this template requires config.ru
to be exist within project files, additionally with Gemfile to install packages.
features:
- ruby latest
nginx:
root: public_html/public
passenger:
enabled: "on"
ruby: .rvm/rubies/default/bin/ruby
commands:
- test -f Gemfile && bundle install
For Ruby on Rails, the template below includes basic setup like rake db migration and precompiling frontend assets.
features:
- ruby latest
nginx:
root: public_html/public
passenger:
enabled: "on"
ruby: .rvm/rubies/default/bin/ruby
commands:
- test -f Gemfile && bundle install || (bundle init && bundle add rails)
- rails db:migrate && rake db:setup && rails db:seed || true
- rake assets:precompile
App Management
Your app do not restarted automatically after file changes. To restart, run restart
via SSH.
Environment variables can be set either using NGINX's env_var_list
or ~/.bashrc
. Usually your language framework also reads .env
files.
See NGINX and App Daemon for more information about NGINX and App managements including restarting, environment variables, and other global limitations.
App Logging
You can see app log from Check -> Check Process Logs tab. Only startup problems displayed in the browser.
You might want to use a proper logging mechanism such as the standard logging library then write it to a log file, or any other solution that suits you.
NGINX errors and traffic logs can be examined via Webmin or Check -> Check Process Logs tab.