Closed garethrees closed 1 year ago
On trying to run a console immediately after:
gareth: ~/src/mysociety/alaveteli (develop $=)
$ dc run --rm app bin/rails c
[+] Running 1/0
⠿ Container alaveteli-db-1 Created 0.0s
[+] Running 1/1
⠿ Container alaveteli-db-1 Started 0.2s
/bundle/vendor/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client': could not translate host name "db" to address: Name or service not known (ActiveRecord::ConnectionNotEstablished)
from /bundle/vendor/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
from /bundle/vendor/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
# …snip…
My config/database.yml
isn't trying to connect to the database by hostname though:
default: &default
adapter: postgresql
template: template_utf8
host: /var/run/postgresql/
port: 5432
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
I think it probably should be! Wonder if the reset
script trashed a change I'd made there? Still, I don't have a host configured so why is it trying to access the "db" hostname?
The issue was that the db
container couldn't boot because the postgres version was out of date.
We found it by doing:
diff --git a/docker/setup b/docker/setup
index ba25badd1..ea84fe9eb 100755
--- a/docker/setup
+++ b/docker/setup
@@ -24,6 +24,9 @@ if [ -L config/general.yml ]; then
theme=$(basename -s .yml $(readlink config/general.yml) | sed 's/^general-//')
notice_msg "Switching to $theme..."
bundle exec script/switch-theme.rb $theme 2>/dev/null
+
+ /bin/wait-for-it db:5432 --strict -- echo 'Database is up'
+
bin/rails assets:clean >/dev/null
success_msg 'done'
fi
Running docker ps
in a different terminal window while docker/reset
was running, we could see that only the app
container was booting, even though app
depends on db
.
Booting the db
container manually (docker-compose run db
) revealed the error message that the database was created using postgres 9.6 and that it needed to be migrated to postgres 13.x (annoyingly I closed the terminal window before capturing the message).
Choosing "Yes" when asked whether I wanted to reset the development database on running script/reset
resolved the issue.