diff --git a/bin/docker-setup b/bin/docker-setup index 82c55293d..67e217ef9 100755 --- a/bin/docker-setup +++ b/bin/docker-setup @@ -1,10 +1,26 @@ #!/usr/bin/env sh +set -e + echo "== Building Docker image (this may take a while) ==" docker-compose build +echo "== Ensuring Elasticsearch data directory is owned by the correct uid ==" +docker-compose run elasticsearch chown elasticsearch:elasticsearch /usr/share/elasticsearch/data + echo "== Setting up database ==" -docker-compose run web rails db:setup db:migrate search:setup data_updates:run +on_db_setup_failed() { + echo "Database setup failed with exit code $1." >&2 + echo "" >&2 + echo "Check the Docker logs using:" >&2 + echo " docker-compose logs" >&2 + echo "" >&2 + echo "Once you fixed the error, try running the script again." >&2 + echo "To also delete all data, run this before retrying:" >&2 + echo " docker-compose down -v && sudo rm -rf docker_data" >&2 + exit $1 +} +docker-compose run web sh -c 'yarn global add wait-on && wait-on -t 30000 http-get://elasticsearch:9200/ && rails search:setup db:setup db:migrate data_updates:run' || on_db_setup_failed $? echo "== Starting app ==" docker-compose up diff --git a/docker-compose.yml b/docker-compose.yml index ed0835c1f..7d5d7de78 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,7 @@ services: REDIS_SESSIONS_URL: redis://redis:6379 volumes: - .:/usr/src/app + - /usr/src/app/node_modules command: bundle exec rails server -b 0.0.0.0 -p 3000 webpacker: build: .