Skip to content

Commit

Permalink
Merge branch '7823-update-docker-scripts' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Oct 19, 2023
2 parents 1244050 + 1eba108 commit 634e562
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docker/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -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'
13 changes: 6 additions & 7 deletions docker/reset
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,4 +25,4 @@ fi

docker compose build --pull

./docker/setup $data_reset
./docker/setup "${ARGS[@]}"
52 changes: 40 additions & 12 deletions docker/setup
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

set -e

cd "$(dirname "$0")/.."

if [ -z "$DOCKER" ]; then
Expand All @@ -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'

0 comments on commit 634e562

Please sign in to comment.