Skip to content

Commit 96c4e22

Browse files
committed
Improve Update behavior
1 parent 7a95a55 commit 96c4e22

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use-mutagen
33
mutagen.yml.lock
44
.env
55
!.gitkeep
6-
/tools/.update
6+
/tools/.*
7+
!/tools/.version
78

89
# Ignore custom cron jobs that you create yourself
910
/cron.d/*.cron

bin/tupdate

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
script_path="$( cd "$(dirname "$0")" ; pwd -P )"
4+
project_path="$( cd $script_path && cd ..; pwd -P )"
5+
set -a; source "$project_path/.env"; set +a
6+
7+
# Run the actual update script
8+
$project_path/tools/update.sh || echo -e "\n\x1B[31mThere was an error while updating docker-dev :(\x1B[0m"

tools/check_for_update.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ if [[ "$current_version_hash" == "$latest_version_hash" ]]; then
5757
return &> /dev/null || exit
5858
fi
5959

60-
read -p "There is a newer version of totara-docker-dev available. Updating will stop all running containers. Would you like to update? [Y/n] " confirm
60+
echo "\033[1;35mThere is a newer version of totara-docker-dev available!\033[0m"
61+
echo "Updating will stop all running containers, pulling new container images and then restart your services."
62+
read -p "Would you like to update? [Y/n] " confirm
6163
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
6264
source "$project_path/tools/update.sh"
6365
# Containers have been stopped, so should quit out and not continue running whatever the command was.

tools/post_update.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
if [[ -z $release_date ]]; then
4-
echo "post_update.sh can't be run directly - please run update.sh instead"
4+
echo "post_update.sh can't be run directly - please run tupdate instead"
55
exit 1
66
fi
77

@@ -13,14 +13,20 @@ if [[ "$release_date" -lt "20211112" ]]; then
1313
echo "" >> /dev/null
1414
fi
1515

16-
if [[ ! $? -eq 0 ]]; then
17-
# Something went wrong in the custom upgrade steps...
18-
echo "An error occurred in the docker-dev specific upgrade steps!"
19-
return &> /dev/null || exit
16+
echo -ne "\n\033[1;35mPulling the latest container images - this could take a few minutes...\033[0m\n\n"
17+
$project_path/bin/tpull
18+
19+
if [[ -f "$project_path/tools/.stopped_services" ]]; then
20+
echo -ne "\n\033[1;35mStarting your containers again...\033[0m\n"
21+
xargs $project_path/bin/tup < "$project_path/tools/.stopped_services"
22+
fi
23+
24+
echo -e "\n\033[1;35mSuccessfully updated to $new_tag!\x1B[0m"
25+
echo -e "\033[1;35mView the release notes here: https://github.com/totara/totara-docker-dev/releases\x1B[0m"
26+
27+
if [[ -f "$project_path/tools/.stopped_services" ]]; then
28+
rm -f "$project_path/tools/.stopped_services"
29+
else
30+
echo "Note: You will need to start your containers again with the tup command"
2031
fi
2132

22-
echo -ne "\nPulling the latest container images - this could take a few minutes" && \
23-
$project_path/bin/tpull &> /dev/null && \
24-
echo -e "...done\n\n\x1B[2mSuccessfully updated to $new_tag from $old_tag\x1B[0m" && \
25-
echo "View the latest changes here: https://github.com/totara/totara-docker-dev/releases/latest" && \
26-
echo "Note: You will need to start your containers again with the tup command"

tools/update.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
script_path=$( cd "$(dirname "$0")" || exit; pwd -P )
44
project_path=$( cd "$script_path" && cd ..; pwd -P )
55

6+
set -e
7+
68
old_tag=$(git describe --tags)
79

810
export $(grep -E -v '^#' "$project_path/tools/.version" | xargs)
911

10-
# Big chain of commands we only want to run if the previous one was successful
11-
echo -ne "Stopping all running containers" && \
12-
"$project_path"/bin/tdown &> /dev/null && \
13-
echo -e "...done\n\nPulling the latest code" && \
14-
git pull origin master --rebase && \
15-
source $project_path/tools/post_update.sh && \
16-
return &> /dev/null || exit
17-
18-
# Something failed...
19-
echo -e "\n\x1B[31mThere was an error while updating.\x1B[0m"
20-
echo "The update can be attempted again by running the $script_path/$(basename $0) script."
12+
13+
# Actual update steps
14+
echo -ne "\033[1;35mUpdating docker dev to the latest version!\033[0m\n\n"
15+
16+
# Store the list of running services so they can be restarted later
17+
echo -ne "\033[1;35mStopping all running containers...\033[0m\n"
18+
echo "$(tdocker ps --services --status running | xargs)" > "$project_path/tools/.stopped_services"
19+
"$project_path"/bin/tdown
20+
21+
# Rebase on the latest master in case there are any local commits
22+
echo -e "\033[1;35mPulling the latest code...\033[0m\n"
23+
git pull origin master --rebase
24+
25+
source $project_path/tools/post_update.sh

0 commit comments

Comments
 (0)