Browse Source

improve dojo shell script

use-env-var-docker
kenshin-samourai 4 years ago
parent
commit
6f6a3df477
  1. 53
      docker/my-dojo/dojo.sh

53
docker/my-dojo/dojo.sh

@ -55,7 +55,7 @@ select_yaml_files() {
# Docker up # Docker up
docker_up() { docker_up() {
yamlFiles=$(select_yaml_files) yamlFiles=$(select_yaml_files)
eval "docker-compose $yamlFiles up $1 -d" eval "docker-compose $yamlFiles up $@ -d"
} }
# Start # Start
@ -200,10 +200,17 @@ install() {
init_config_files init_config_files
# Build and start Dojo # Build and start Dojo
docker_up --remove-orphans docker_up --remove-orphans
buildResult=$?
if [ $buildResult -eq 0 ]; then
# Display the logs # Display the logs
if [ $noLog -eq 1 ]; then if [ $noLog -eq 1 ]; then
logs "" 0 logs "" 0
fi fi
else
# Return an error
echo -e "\nInstallation of Dojo failed. See the above error message."
exit $buildResult
fi
fi fi
} }
@ -233,20 +240,8 @@ uninstall() {
fi fi
if [ $launchUninstall -eq 0 ]; then if [ $launchUninstall -eq 0 ]; then
docker-compose rm -f
yamlFiles=$(select_yaml_files) yamlFiles=$(select_yaml_files)
eval "docker-compose $yamlFiles down" eval "docker-compose $yamlFiles down --rmi all"
docker image rm -f samouraiwallet/dojo-db:"$DOJO_DB_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-bitcoind:"$DOJO_BITCOIND_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-explorer:"$DOJO_EXPLORER_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-nodejs:"$DOJO_NODEJS_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-nginx:"$DOJO_NGINX_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-tor:"$DOJO_TOR_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-indexer:"$DOJO_INDEXER_VERSION_TAG"
docker image rm -f samouraiwallet/dojo-whirlpool:"$DOJO_WHIRLPOOL_VERSION_TAG"
docker volume prune -f docker volume prune -f
return 0 return 0
else else
@ -260,13 +255,12 @@ del_images_for() {
# $2: most recent version of the image (do not delete this one) # $2: most recent version of the image (do not delete this one)
docker image ls | grep "$1" | sed "s/ \+/,/g" | cut -d"," -f2 | while read -r version ; do docker image ls | grep "$1" | sed "s/ \+/,/g" | cut -d"," -f2 | while read -r version ; do
if [ "$2" != "$version" ]; then if [ "$2" != "$version" ]; then
docker image rm "$1:$version" docker image rm -f "$1:$version"
fi fi
done done
} }
clean() { clean() {
docker image prune
del_images_for samouraiwallet/dojo-db "$DOJO_DB_VERSION_TAG" del_images_for samouraiwallet/dojo-db "$DOJO_DB_VERSION_TAG"
del_images_for samouraiwallet/dojo-bitcoind "$DOJO_BITCOIND_VERSION_TAG" del_images_for samouraiwallet/dojo-bitcoind "$DOJO_BITCOIND_VERSION_TAG"
del_images_for samouraiwallet/dojo-explorer "$DOJO_EXPLORER_VERSION_TAG" del_images_for samouraiwallet/dojo-explorer "$DOJO_EXPLORER_VERSION_TAG"
@ -275,6 +269,7 @@ clean() {
del_images_for samouraiwallet/dojo-tor "$DOJO_TOR_VERSION_TAG" del_images_for samouraiwallet/dojo-tor "$DOJO_TOR_VERSION_TAG"
del_images_for samouraiwallet/dojo-indexer "$DOJO_INDEXER_VERSION_TAG" del_images_for samouraiwallet/dojo-indexer "$DOJO_INDEXER_VERSION_TAG"
del_images_for samouraiwallet/dojo-whirlpool "$DOJO_WHIRLPOOL_VERSION_TAG" del_images_for samouraiwallet/dojo-whirlpool "$DOJO_WHIRLPOOL_VERSION_TAG"
docker image prune -f
} }
# Upgrade # Upgrade
@ -311,7 +306,16 @@ upgrade() {
if [ $launchUpgrade -eq 0 ]; then if [ $launchUpgrade -eq 0 ]; then
# Select yaml files # Select yaml files
yamlFiles=$(select_yaml_files) yamlFiles=$(select_yaml_files)
# Check if dojo is running (check the db container)
isRunning=$(docker inspect --format="{{.State.Running}}" db 2> /dev/null)
if [ $? -eq 1 ] || [ "$isRunning" == "false" ]; then
echo -e "\nChecked that Dojo isn't running."
else
echo " "
stop
fi
# Update config files # Update config files
echo -e "\nPreparing the upgrade of Dojo.\n"
update_config_files update_config_files
# Cleanup # Cleanup
cleanup cleanup
@ -320,13 +324,15 @@ upgrade() {
export BITCOIND_RPC_EXTERNAL_IP export BITCOIND_RPC_EXTERNAL_IP
# Rebuild the images (with or without cache) # Rebuild the images (with or without cache)
if [ $noCache -eq 0 ]; then if [ $noCache -eq 0 ]; then
eval "docker-compose $yamlFiles build --no-cache" echo -e "\nDeleting Dojo containers and images."
else eval "docker-compose $yamlFiles down --rmi all"
eval "docker-compose $yamlFiles build"
fi fi
# Start Dojo echo -e "\nStarting the upgrade of Dojo.\n"
docker_up --remove-orphans docker_up --build --force-recreate --remove-orphans
buildResult=$?
if [ $buildResult -eq 0 ]; then
# Post start clean-up # Post start clean-up
clean
post_start_cleanup post_start_cleanup
# Update the database # Update the database
update_dojo_db update_dojo_db
@ -334,6 +340,11 @@ upgrade() {
if [ $noLog -eq 1 ]; then if [ $noLog -eq 1 ]; then
logs "" 0 logs "" 0
fi fi
else
# Return an error
echo -e "\nUpgrade of Dojo failed. See the above error message."
exit $buildResult
fi
fi fi
} }

Loading…
Cancel
Save