Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Dec 12, 2024
1 parent 7cf587f commit 3b2b772
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
68 changes: 31 additions & 37 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,25 +421,12 @@ def generate_app
end

if File.exist?("fly.toml")
env = {}

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
env = fly_toml_env

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")
toml += "\n[env]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n") + "\n"
File.write "fly.toml", toml
end
end
Expand Down Expand Up @@ -1442,36 +1429,43 @@ def configure_tigris
end
end

def fly_make_toml
toml = File.read("fly.toml")
def fly_toml_env
env = {}
dockerfile = File.read("Dockerfile") rescue ""

list = fly_processes
if list
env = {}
if using_thruster?
env["PORT"] = "8080"
end

if using_thruster?
primary = list.keys.first
list[primary] = list[primary].sub(/^.*thrust /, "")
if (options.sqlite3? || @sqlite3) && !dockerfile.include?("DATABASE_URL")
env["DATABASE_URL"] = "sqlite3:///data/production.sqlite3"
end

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

if (options.sqlite3? || @sqlite3) && !dockerfile.include?("DATABASE_URL")
env["DATABASE_URL"] = "sqlite3:///data/production.sqlite3"
end
if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
env["SOLID_QUEUE_IN_PUMA"] = "true"
end

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

if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
env["SOLID_QUEUE_IN_PUMA"] = "true"
end
def fly_make_toml
toml = File.read("fly.toml")
env = fly_toml_env

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

unless env.empty? || toml.include?("[env]")
toml += "\n[env]\n" + env.map { |key, value| " #{key} = #{value.inspect}" }.join("\n") + "\n"
list = fly_processes
if list
if using_thruster?
primary = list.keys.first
list[primary] = list[primary].sub(/^.*thrust /, "")
end

if toml.include? "[processes]"
Expand Down
2 changes: 1 addition & 1 deletion test/results/postgresql/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# gem install pg -- --with-pg-config=/opt/homebrew/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
Expand Down
3 changes: 3 additions & 0 deletions test/results/solid_queue_sqlite3/fly.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

[env]
PORT = "8080"
[mounts]
source="data"
destination="/data"
Expand Down

0 comments on commit 3b2b772

Please sign in to comment.