Retrofits Kamal + Dockerfile etc. to an Rails >= 8.0 app.
Used 6 times
S
Stefan Wienert
Usage
Retrofits Kamal + Dockerfile etc. to an Rails >= 8.0 app.
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/Vp7s41"
Template Source
Review the code before running this template on your machine.
if Rails.version < '8.0.0'
fail 'please use rails 8.0.0 or above'
end
# check if gem
gemfile = File.read('Gemfile')
if !gemfile[/^\s*gem .*kamal/]
gem 'kamal', require: false
else
puts "kamal already in Gemfile"
end
if !gemfile[/^\s*gem .*thruster/]
gem 'thruster', require: false
else
puts "thruster already in Gemfile"
end
run "kamal init"
route %{get "up" => "rails/health#show", as: :rails_health_check}
file "bin/thrust", <<~BASH
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
load Gem.bin_path("thruster", "thrust")
BASH
run 'chmod +x bin/thrust'
inject_into_file 'config/environments/production.rb', after: /log_level =.*\n/ do
%{ config.silence_healthcheck_path = "/up"\n}
end
inject_into_file 'config/environments/production.rb', after: /silence_healthcheck_path.*=.*\n/ do
%{ config.assume_ssl = true\n}
end
create_dockerfiles