* Add set -e to docker-setup script * Add error handling for db setup stage * Sometimes Elasticsearch takes time to boot up * Also delete docker_data * search:setup must come first * Revert "Sometimes Elasticsearch takes time to boot up" This reverts commit e975f6e5c3edad084d4f2c4d8718675bf5c8d07c. Reason for revert: Instead of using wait-on, we can use Docker’s health check instead See review comment: https://github.com/thepracticaldev/dev.to/pull/7378#discussion_r411839255 * Use wait-on without installing into package.json * Add /usr/src/app/node_modules to volumes Otherwise, webpacker will not run in docker-compose. See: https://stackoverflow.com/questions/30043872/docker-compose-node-modules-not-present-in-a-volume-after-npm-install-succeeds
26 lines
949 B
Bash
Executable file
26 lines
949 B
Bash
Executable file
#!/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 =="
|
|
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
|