Skip to content

Commit

Permalink
more complete fly.toml if Dockerfile already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Dec 12, 2024
1 parent f157935 commit 7cf587f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
28 changes: 22 additions & 6 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ def generate_app

unless env.empty?
toml = IO.read("fly.toml")
if !toml.include?("[[env]]")
toml += "\n[[env]]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n")
if !toml.include?("[env]")
toml += "\n[env]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n")
File.write "fly.toml", toml
end
end
Expand Down Expand Up @@ -1444,18 +1444,34 @@ def configure_tigris

def fly_make_toml
toml = File.read("fly.toml")
dockerfile = File.read("Dockerfile") rescue ""

list = fly_processes
if list
env = {}

if using_thruster?
primary = list.keys.first
list[primary] = list[primary].sub(/^.*thrust /, "")

env = { "PORT" => "8080" }
env["PORT"] = "8080"
end

if !toml.include?("[[env]]")
toml += "\n[[env]]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n") + "\n"
end
if (options.sqlite3? || @sqlite3) && !dockerfile.include?("DATABASE_URL")
env["DATABASE_URL"] = "sqlite3:///data/production.sqlite3"
end

if using_thruster? # && !dockerfile.include?("HTTP_PORT")
# env["HTTP_PORT"] = "8080"
env["PORT"] = "8080"
end

if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
env["SOLID_QUEUE_IN_PUMA"] = "true"
end

unless env.empty? || toml.include?("[env]")
toml += "\n[env]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n") + "\n"
end

if toml.include? "[processes]"
Expand Down
2 changes: 1 addition & 1 deletion test/results/no_prep/fly.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[[env]]
[env]
PORT = "8080"

[processes]
Expand Down
2 changes: 1 addition & 1 deletion test/results/sidekiq/fly.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[[env]]
[env]
PORT = "8080"

[processes]
Expand Down
2 changes: 1 addition & 1 deletion test/results/solid_queue_postgres/fly.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[[env]]
[env]
PORT = "8080"

[processes]
Expand Down
2 changes: 1 addition & 1 deletion test/results/sqlite3/fly.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[[env]]
[env]
PORT = "8080"

[processes]
Expand Down

0 comments on commit 7cf587f

Please sign in to comment.