Skip to content
Open
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
22 changes: 21 additions & 1 deletion script/common/canvas/build_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,24 @@ This script will destroy ALL EXISTING DATA if it continues
If you want to migrate the existing database, cancel now
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
message 'About to run "bundle exec rake db:drop"'
start_spinner "Stopping app containers to release db connections..."
stop_running_canvas_app_services
stop_spinner
start_spinner "Deleting db....."
_canvas_lms_track_with_log run_command bundle exec rake db:drop
drop_failed=0
if ! _canvas_lms_track_with_log run_command_once bundle exec rake db:drop; then
drop_failed=1
fi
stop_spinner
start_spinner "Restarting web..."
_canvas_lms_track_with_log $DOCKER_COMMAND up -d web
stop_spinner
if [[ $drop_failed -ne 0 ]]; then
start_spinner "Restarting app containers..."
restart_stopped_canvas_app_services
stop_spinner
return 1
fi
fi
fi
stop_spinner
Expand All @@ -94,6 +109,11 @@ If you want to migrate the existing database, cancel now
_canvas_lms_track_with_log run_command bundle exec rake db:migrate RAILS_ENV=test
stop_spinner
[[ ${dropped:-DROP} == 'migrate' ]] || _canvas_lms_track run_command_tty bundle exec rake db:initial_setup
if [[ ${dropped:-DROP} == 'DROP' ]]; then
start_spinner "Restarting app containers..."
restart_stopped_canvas_app_services
stop_spinner
fi
}

function bundle_install {
Expand Down
55 changes: 55 additions & 0 deletions script/common/utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ function run_command {
"$@"
fi
}

function run_command_once {
if is_running_on_jenkins; then
docker compose run --rm -T web "$@"
elif is_docker; then
$DOCKER_COMMAND run --rm -T -e TELEMETRY_OPT_IN web "$@"
else
"$@"
fi
}

# remove once https://github.com/docker/compose/issues/9104 is fixed
function run_command_tty {
if is_running_on_jenkins; then
Expand Down Expand Up @@ -204,6 +215,50 @@ function docker_running {
fi
}

function check_for_running_containers {
running_containers=$($DOCKER_COMMAND ps -q 2>/dev/null)
if [[ -n "$running_containers" ]]; then
echo ""
echo "Warning: Canvas Docker containers are currently running."
echo "This may cause issues (e.g., database connections preventing db:drop)."
echo ""
$DOCKER_COMMAND ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null
echo ""
if ! is_running_on_jenkins; then
prompt "Stop running containers before continuing? [y/n]" stop_containers
if [[ ${stop_containers:-n} == 'y' ]]; then
start_spinner "Stopping running containers..."
_canvas_lms_track_with_log $DOCKER_COMMAND down
stop_spinner
message "Containers stopped."
else
echo "Continuing with containers running. This may cause errors."
fi
fi
fi
}

function running_canvas_app_services {
$DOCKER_COMMAND ps --services --status running 2>/dev/null | grep -vE '^(postgres|redis)$' || true
}

function stop_running_canvas_app_services {
STOPPED_CANVAS_APP_SERVICES=$(running_canvas_app_services)

if [[ -n "$STOPPED_CANVAS_APP_SERVICES" ]]; then
# shellcheck disable=SC2086
_canvas_lms_track_with_log $DOCKER_COMMAND stop $STOPPED_CANVAS_APP_SERVICES
fi
}

function restart_stopped_canvas_app_services {
if [[ -n "${STOPPED_CANVAS_APP_SERVICES:-}" ]]; then
# shellcheck disable=SC2086
_canvas_lms_track_with_log $DOCKER_COMMAND up -d $STOPPED_CANVAS_APP_SERVICES
STOPPED_CANVAS_APP_SERVICES=
fi
}

function os_setup {
if [[ $OS == 'Darwin' ]]; then
. script/common/os/mac/dev_setup.sh
Expand Down
1 change: 1 addition & 0 deletions script/docker_dev_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ init_log_file "Docker Dev Setup"
detect_local_canvas
os_setup
message 'Now we can set up Canvas!'
check_for_running_containers
copy_docker_config
setup_docker_compose_override
build_images
Expand Down