diff --git a/docker/bootstrap b/docker/bootstrap index 4d878accd3..637b5012ae 100755 --- a/docker/bootstrap +++ b/docker/bootstrap @@ -44,5 +44,5 @@ notice_msg "Getting latest alavetelitheme commits..." alaveteli=`pwd` alavetelitheme="$themes_dir/alavetelitheme" [ ! -d $alavetelitheme ] && git clone https://github.com/mysociety/alavetelitheme.git $alavetelitheme >/dev/null -cd $alavetelitheme && git pull && cd $alaveteli +cd $alavetelitheme && git pull --quiet && cd $alaveteli success_msg 'done' diff --git a/docker/reset b/docker/reset index 1d12dec910..c821ebba2c 100755 --- a/docker/reset +++ b/docker/reset @@ -1,23 +1,22 @@ #!/bin/sh -set -e - cd "$(dirname "$0")/.." . docker/env docker compose down -db_volume="$(basename $(pwd))_postgres" -if docker volume ls | grep $db_volume >/dev/null; then +ARGS=() +DB_VOLUME="$(basename $(pwd))_postgres" +if docker volume ls | grep $DB_VOLUME >/dev/null; then while true do read -r -p 'Do you also want to reset your development database? ' choice case "$choice" in n|N) break;; y|Y) - docker volume rm $db_volume >/dev/null - data_reset=true + docker volume rm $DB_VOLUME >/dev/null + ARGS+=("--reset_data") break;; *) echo 'Response not valid';; esac @@ -26,4 +25,4 @@ fi docker compose build --pull -./docker/setup $data_reset +./docker/setup "${ARGS[@]}" diff --git a/docker/setup b/docker/setup index a107e5032a..48846199ff 100755 --- a/docker/setup +++ b/docker/setup @@ -1,7 +1,5 @@ #!/bin/sh -set -e - cd "$(dirname "$0")/.." if [ -z "$DOCKER" ]; then @@ -15,33 +13,63 @@ error_msg() { printf "\033[31m%s\033[0m\n" "$*"; } notice_msg() { printf "\033[33m%s\033[0m " "$*"; } success_msg() { printf "\033[32m%s\033[0m\n" "$*"; } -data_reset="${1:-false}" - notice_msg 'Installing Ruby gems...' -bundle install +bundle check >/dev/null || bundle install success_msg 'done' 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 + 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/rails assets:clean >/dev/null success_msg 'done' fi -if $data_reset; then - notice_msg 'Migrating development and test databases...' +# check to see if the database has ever been seeded, if not then set the +# RESET_DATA_FLAG regardless of arguments passed to the script +bin/rails runner 'User.find(1)' 2>/dev/null +RESET_DATA_FLAG=$? +for arg in "$@"; do + case $arg in + --reset-data) + RESET_DATA_FLAG=1 + shift + ;; + *);; + esac +done + +notice_msg 'Migrating development and test databases...' +if [ $RESET_DATA_FLAG -eq 1 ]; then bin/rails db:migrate db:seed >/dev/null bin/rails db:migrate RAILS_ENV=test >/dev/null success_msg 'done' +else + error_msg 'skipped' +fi - notice_msg 'Loading sample data...' +notice_msg 'Loading sample data...' +if [ $RESET_DATA_FLAG -eq 1 ]; then bundle exec script/load-sample-data > /dev/null success_msg 'done' +else + error_msg 'skipped' +fi + +notice_msg 'Removing external requests...' +if [ $RESET_DATA_FLAG -eq 1 ]; then + bin/rails runner 'InfoRequest.external.destroy_all' + success_msg 'done' +else + error_msg 'skipped' +fi - notice_msg 'Rebuilding Xapian index...' +notice_msg 'Rebuilding Xapian index...' +if [ $RESET_DATA_FLAG -eq 1 ]; then bundle exec script/destroy-and-rebuild-xapian-index > /dev/null success_msg 'done' +else + error_msg 'skipped' fi success_msg 'Setup finished'