Skip to content

Commit

Permalink
DEV: Wait for initdb to complete in docker.rake (discourse#15614)
Browse files Browse the repository at this point in the history
On slower hardware it can take a while to init the database. If we don't wait, the `rake db:create` step will fail.
  • Loading branch information
davidtaylorhq authored Jan 17, 2022
1 parent 31b27b3 commit ed2f700
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/tasks/docker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ task 'docker:test' do
puts "Starting background redis"
@redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')

puts "Initializing postgres"
system("script/start_test_db.rb --skip-run", exception: true)

puts "Starting postgres"
@pg_pid = Process.spawn("script/start_test_db.rb --exec")
@pg_pid = Process.spawn("script/start_test_db.rb --skip-setup --exec")

ENV["RAILS_ENV"] = "test"
# this shaves all the creation of the multisite db off
Expand Down
20 changes: 14 additions & 6 deletions script/start_test_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@ def run(*args)
system(*args, exception: true)
end

should_setup = true
should_run = true
should_exec = false
while a = ARGV.pop
if a == "--exec"
if a == "--skip-setup"
should_setup = false
elsif a == "--skip-run"
should_run = false
elsif a == "--exec"
should_exec = true
else
raise "Unknown argument #{a}"
end
end

run "#{BIN}/initdb -D #{DATA}"
if should_setup
run "#{BIN}/initdb -D #{DATA}"

run "echo fsync = off >> #{DATA}/postgresql.conf"
run "echo full_page_writes = off >> #{DATA}/postgresql.conf"
run "echo shared_buffers = 500MB >> #{DATA}/postgresql.conf"
run "echo fsync = off >> #{DATA}/postgresql.conf"
run "echo full_page_writes = off >> #{DATA}/postgresql.conf"
run "echo shared_buffers = 500MB >> #{DATA}/postgresql.conf"
end

if should_exec
exec "#{BIN}/postmaster -D #{DATA}"
else
elsif should_run
run "#{BIN}/pg_ctl -D #{DATA} start"
end

0 comments on commit ed2f700

Please sign in to comment.