Skip to content

Commit

Permalink
update fly.toml (if it exists) with swap instead of docker entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jul 22, 2023
1 parent 29c5c79 commit c33dddf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def generate_app
fly_attach_consul
end

if File.exist?("fly.toml") && (fly_processes || !options.prepare)
if File.exist?("fly.toml") && (fly_processes || !options.prepare || options.swap)
if File.stat("fly.toml").size > 0
template "fly.toml.erb", "fly.toml"
else
Expand Down Expand Up @@ -1086,6 +1086,29 @@ def fly_make_toml
end
end

if options.swap
suffixes = {
"kib" => 1024,
"k" => 1024,
"kb" => 1000,
"mib" => 1048576,
"m" => 1048576,
"mb" => 100000,
"gib" => 1073741824,
"g" => 1073741824,
"gb" => 100000000,
}

pattern = Regexp.new("^(\\d+)(#{suffixes.keys.join('|')})?$", "i")

match = pattern.match(options.swap)

if match
size = ((match[1].to_i * (suffixes[match[2]] || 1)) / 1048576.0).round
toml += "swap_size_mb = #{size}"
end
end

toml
end
end
2 changes: 1 addition & 1 deletion lib/generators/templates/docker-entrypoint.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

<% if options.swap -%>
<% if options.swap && !File.exist?("fly.toml")-%>
<% if run_as_root? or using_passenger? -%>
<% @space = "" -%>
<% else -%>
Expand Down

0 comments on commit c33dddf

Please sign in to comment.