Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#7823] Update Docker scripts #7965

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Loading