Skip to content

Commit

Permalink
Improve echo messages in initialize script
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Aug 1, 2024
1 parent e0597cc commit 8d3fd47
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions initialize.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash

check_for_preseeds() {
echo Checking for preseeds
echo "💾 Checking for preseeds (in development env)"

# Database preseed
if [[ "${DB_SQL_PRESEED_URL}" ]]; then
echo "Found DB preseed at URL: $DB_SQL_PRESEED_URL"
echo "💾 Found DB preseed at URL: $DB_SQL_PRESEED_URL"
mkdir -pv db/backups/docker_development
wget --content-disposition --directory-prefix=db/backups/docker_development/ --timestamping $DB_SQL_PRESEED_URL
for file in db/backups/docker_development/*.sql; do
Expand All @@ -18,50 +18,49 @@ check_for_preseeds() {

# Files (uploads) preseed
if [[ "${UPLOADS_PRESEED_URL}" ]]; then
echo "Found upload preseed at URL: $UPLOAD_PRESEED_URL"
echo "💾 Found upload preseed at URL: $UPLOAD_PRESEED_URL"
wget --content-disposition --directory-prefix=public/ --timestamping --progress=dot:mega $UPLOADS_PRESEED_URL
mkdir -p public/uploads
bsdtar -xvf public/uploads.zip -s'|[^/]*/||' -C public/uploads
fi
}

if [ "$RAILS_ENV" = "production" ]; then
echo "This script is not intended for usage with RAILS_ENV=production. Aborting."
echo "This script is not intended for usage with RAILS_ENV=production. Aborting."
exit 1
fi

echo Waiting for redis to come online
wait-for-it redis:6379 -t 30 || exit 1

if ! [ -f /completed_initial_run ]; then
echo Initialising MaMpf
echo Waiting for the DB to come online
echo RAILS ENV: $RAILS_ENV
echo "▶ Initialising MaMpf in environment: $RAILS_ENV"

echo "🕖 Waiting for Redis to come online"
wait-for-it redis:6379 -t 30 || exit 1

# Wait for database to come online
echo "🕖 Waiting for database to come online"
if [ "$RAILS_ENV" = "docker_development" ]; then
wait-for-it ${DEVELOPMENT_DATABASE_HOST}:${DEVELOPMENT_DATABASE_PORT} -t 30 || exit 1
fi
if [ "$RAILS_ENV" = "test" ]; then
wait-for-it ${TEST_DATABASE_HOST}:${TEST_DATABASE_PORT} -t 30 || exit 1
fi

echo running: bundle exec rails db:create
echo "➕ Creating database (db:create)"
bundle exec rails db:create:interactions
bundle exec rails db:create

if [ "$RAILS_ENV" = "docker_development" ]; then
check_for_preseeds
fi
if [ "$RAILS_ENV" = "test" ]; then
echo Loading DB schema
echo "💾 Loading DB schema (in test env)"
bundle exec rails db:schema:load
fi

echo Waiting for SOLR to come online
echo "🕖 Waiting for SOLR to come online"
wait-for-it ${SOLR_HOST}:${SOLR_PORT} -t 30 || exit 1
bundle exec rake sunspot:solr:reindex

echo 'finished initialisation'
echo "✅ Finished initialization of MaMpf in environment: $RAILS_ENV"
touch /completed_initial_run
fi

0 comments on commit 8d3fd47

Please sign in to comment.