Skip to content

Commit

Permalink
Rough in support for thruster
Browse files Browse the repository at this point in the history
See: rails/rails#50479

Needs more testing, and complementary changes in flyctl
  • Loading branch information
rubys committed Mar 17, 2024
1 parent 9e6ea16 commit 271bcd2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ different contents. If both are specified, `--force` takes precedence.
* `--compose` - generate a `docker-compose.yml` file
* `--max-idle=n` - exit afer *n* seconds of inactivity. Supports [iso 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) and [sleep](https://man7.org/linux/man-pages/man1/sleep.1.html#DESCRIPTION) syntaxes. Uses passenger for now, awaiting [puma](https://github.com/puma/puma/issues/2580) support.
* `--nginx` - serve static files via [nginx](https://www.nginx.com/). May require `--root` on some targets to access `/dev/stdout`
* `--thruster` - serve static files via [thruster](https://github.com/basecamp/thruster?tab=readme-ov-file#thruster).
* `--no-link` - don't add [--link](https://docs.docker.com/engine/reference/builder/#copy---link) to COPY statements. Some tools (like at the moment, [buildah](https://www.redhat.com/en/topics/containers/what-is-buildah)) don't yet support this feature.
* `--no-lock` - don't add linux platforms, set `BUNDLE_DEPLOY`, or `--frozen-lockfile`. May be needed at times to work around a [rubygems bug](https://github.com/rubygems/rubygems/issues/6082#issuecomment-1329756343).
* `--sudo` - install and configure sudo to enable `sudo -iu rails` access to full environment
Expand Down
27 changes: 25 additions & 2 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DockerfileGenerator < Rails::Generators::Base
"sentry" => false,
"sudo" => false,
"swap" => nil,
"thruster" => false,
"variant" => nil,
"windows" => false,
"yjit" => false,
Expand Down Expand Up @@ -185,6 +186,9 @@ class DockerfileGenerator < Rails::Generators::Base
class_option :label, type: :hash, default: {},
desc: "Add Docker label(s)"

class_option :thruster, type: :boolean, default: OPTION_DEFAULTS.thruster,
desc: "use Thruster HTTP/2 proxy"

class_option :nginx, type: :boolean, default: OPTION_DEFAULTS.nginx,
desc: "Serve static files with nginx"

Expand Down Expand Up @@ -507,6 +511,10 @@ def install_gems
system "bundle add sentry-rails --skip-install" unless @gemfile.include? "sentry-rails"
end

if options.thruster?
system "bundle add thruster --skip-install" unless @gemfile.include? "thruster"
end

if options.rollbar?
system "bundle add rollbar --skip-install" unless @gemfile.include? "rollbar"
end
Expand Down Expand Up @@ -1126,6 +1134,10 @@ def procfile
nginx: '/usr/sbin/nginx -g "daemon off;"',
rails: "./bin/rails server -p 3001"
}
elsif options.thruster?
{
rails: "thruster ./bin/rails server"
}
else
{
rails: "./bin/rails server"
Expand Down Expand Up @@ -1249,7 +1261,7 @@ def fly_make_toml
list.map { |name, cmd| " #{name} = #{cmd.inspect}" }.join("\n") + '\1')
else
toml += "\n[processes]\n" +
list.map { |name, cmd| " #{name} = #{cmd.inspect}\n" }.join
list.map { |name, cmd| " #{name} = #{cmd.inspect}\n" }.join + "\n"

app = list.has_key?("app") ? "app" : list.keys.first

Expand Down Expand Up @@ -1291,7 +1303,18 @@ def fly_make_toml

if match
size = ((match[1].to_i * (suffixes[match[2]] || 1)) / 1048576.0).round
toml += "swap_size_mb = #{size}"
if toml.include? "swap_size_mb"
toml.sub!(/swap_size_mb.*/, "swap_size_mb = #{size}")
else
toml += "swap_size_mb = #{size}\n\n"
end
end
end

puts @gemfile.inspect
unless options.nginx? || using_passenger? || options.thruster? || @gemfile.include?("thruster")
unless toml.include? "[statics]"
toml += "[[statics]]\n guest_path = \"/rails/public\"\n url_prefix = \"/\"\n\n"
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/results/no_prep/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
source="data"
destination="/data"

[[statics]]
guest_path = "/rails/public"
url_prefix = "/"

5 changes: 5 additions & 0 deletions test/results/sidekiq/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
[processes]
app = "./bin/rails server"
sidekiq = "bundle exec sidekiq"

[[statics]]
guest_path = "/rails/public"
url_prefix = "/"

5 changes: 5 additions & 0 deletions test/results/solid_queue/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
[processes]
app = "./bin/rails server"
solidq = "bundle exec rake solid_queue:start"

[[statics]]
guest_path = "/rails/public"
url_prefix = "/"

4 changes: 4 additions & 0 deletions test/results/sqlite3/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
source="data"
destination="/data"

[[statics]]
guest_path = "/rails/public"
url_prefix = "/"

0 comments on commit 271bcd2

Please sign in to comment.