mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Prior to this commit, the db container would create a database named “ofn” (the same as $POSTGRES_USER). Then, when the web container started, it would run `rake db:reset`. This would load the Rails environment, which ends up requiring some model files, which eventually end up trying to connect to the “open_food_network_dev” database, which doesn’t exist. Therefore setting up the database fails, and it’s impossible to boot the web container. As a side note, I’m not convinced that bootstrapping the database as part of the container’s command is the best strategy (if for no other reason that this will wipe my database every time I run `docker-compose up`). But this commit doesn’t change that. What it does is add the $POSTGRES_DB environment variable so that the db container creates the “open_food_network_dev” database (which is blank). Then, when `rake db:reset` runs, it’ll successfully connect to this (empty) database while loading the environment, before deleting and recreating it. Note that I had to manually delete the `openfoodnetwork_postgres` volume in order to reset my local state, after making this change.
41 lines
1016 B
YAML
41 lines
1016 B
YAML
version: '3'
|
|
|
|
services:
|
|
db:
|
|
image: postgres:9.5
|
|
restart: always
|
|
environment:
|
|
POSTGRES_PASSWORD: f00d
|
|
POSTGRES_USER: ofn
|
|
POSTGRES_DB: open_food_network_dev
|
|
volumes:
|
|
- 'postgres:/var/lib/postgresql/data'
|
|
web:
|
|
tty: true
|
|
stdin_open: true
|
|
build: .
|
|
ports:
|
|
- 3000:3000
|
|
volumes:
|
|
- .:/usr/src/app
|
|
- gems:/bundles
|
|
- ./config/database.yml:/usr/src/app/config/database.yml
|
|
- ./config/application.yml.example:/usr/src/app/config/application.yml
|
|
depends_on:
|
|
- db
|
|
environment:
|
|
ADMIN_EMAIL: ofn@example.com
|
|
ADMIN_PASSWORD: ofn123
|
|
OFN_DB_HOST: db
|
|
command: >
|
|
bash -c "(bundle check || bundle install) &&
|
|
wait-for-it -t 30 db:5432 &&
|
|
bundle exec rake db:reset db:test:prepare &&
|
|
bundle exec rake ofn:sample_data || true &&
|
|
rm -f tmp/pids/server.pid &&
|
|
bundle exec rails s -p 3000 -b '0.0.0.0'"
|
|
|
|
volumes:
|
|
gems:
|
|
postgres:
|