Skip to content

Commit

Permalink
When --no-prepare is selected, actually update fly.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jun 27, 2023
1 parent 7b3235b commit befe8ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
38 changes: 24 additions & 14 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,12 @@ def generate_app
fly_attach_consul
end

if fly_processes # therefore File.exist?('fly.toml')
if File.exist?('fly.toml') && (fly_processes || !options.prepare)
if File.stat("fly.toml").size > 0
template "fly.toml.erb", "fly.toml"
else
toml = fly_make_processes(fly_processes)
if toml != IO.read("fly.toml")
File.write "fly.toml", toml
end
toml = fly_make_toml
File.write "fly.toml", toml if toml != ""
end
end

Expand Down Expand Up @@ -1042,19 +1040,31 @@ def fly_attach_consul
system "#{flyctl} consul attach"
end

def fly_make_processes(list)
def fly_make_toml
toml = File.read("fly.toml")

if toml.include? "[processes]"
toml.sub!(/\[processes\].*?(\n\n|\n?\z)/m, "[processes]\n" +
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 = fly_processes
if list
if toml.include? "[processes]"
toml.sub!(/\[processes\].*?(\n\n|\n?\z)/m, "[processes]\n" +
list.map { |name, cmd| " #{name} = #{cmd.inspect}" }.join("\n") + '\1')
else
toml += "\n[processes]\n" +
list.map { |name, cmd| " #{name} = #{cmd.inspect}\n" }.join

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

app = list.has_key?("app") ? "app" : list.keys.first
toml.sub! "[http_service]\n", "\\0 processes = [#{app.inspect}]\n"
end
end

toml.sub! "[http_service]\n", "\\0 processes = [#{app.inspect}]\n"
if options.prepare == false
deploy = "[deploy]\n release_command = #{dbprep_command.inspect}\n\n"
if toml.include? "[deploy]"
toml.sub! /\[deploy\].*?(\n\n|\n?\z)/m, deploy
else
toml += deploy
end
end

toml
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/fly.toml.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= fly_make_processes(fly_processes) -%>
<%= fly_make_toml -%>
3 changes: 3 additions & 0 deletions test/results/no_prep/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deploy]
release_command = "./bin/rails db:prepare"

5 changes: 5 additions & 0 deletions test/test_no_prep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ class TestNoPrep < TestBase
@rails_options = "--minimal"
@generate_options = "--no-prepare"

def app_setup
FileUtils.touch "fly.toml"
end

def test_no_prep
check_dockerfile
check_entrypoint
check_toml
end
end

0 comments on commit befe8ed

Please sign in to comment.