Skip to content

Commit

Permalink
Updated migration logic
Browse files Browse the repository at this point in the history
Signed-off-by: sougata-progress <[email protected]>
  • Loading branch information
sougata-progress committed Oct 16, 2024
1 parent 0607b01 commit 3f64307
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 55 deletions.
70 changes: 16 additions & 54 deletions scripts/minio-migrate.sh
Original file line number Diff line number Diff line change
@@ -1,90 +1,52 @@
set -eou pipefail

CHANNEL="LTS-2024"
install_minio() {

sudo hab pkg install core/minio -c $CHANNEL
echo "MinIO installation completed."
}

check_and_install_minio() {
if ! hab pkg path core/minio >/dev/null 2>&1; then
echo "MinIO is not installed. Installing MinIO..."
install_minio
else
echo "MinIO is already installed."
fi
}
LATEST_MINIO_VERSION="2023-11-01T01-57-10Z"

get_installed_minio_version() {
installed_version=$(hab pkg path core/minio | cut -d '/' -f6)
echo "$installed_version"
}

get_latest_minio_version() {
latest_version=$(curl --silent "https://bldr.habitat.sh/v1/depot/channels/core/$CHANNEL/pkgs/minio/latest" | jq -r '.ident.version')
if [[ -z "$latest_version" ]]; then
echo "Failed to fetch the latest MinIO version."
exit 1
fi
echo "$latest_version"
}

compare_versions() {
local v1=$1
local v2=$2
echo "Comparing versions..."
echo "Installed version: $v1"
echo "Latest version: $v2"
echo "Latest version threshold: $v2"

if [ "$v1" = "$v2" ]; then
return 1
return 0
elif [[ "$v1" < "$v2" ]]; then
echo "Installed version is older."
return 0
echo "Installed version is older or equal."
return 0
else
echo "Installed version is newer or equal."
return 1
fi
}

trigger_migration() {
echo "Triggering MinIO data migration..."
y | bash ./minio-update.sh upgrade
}

detect_migration() {
installed_version=$(get_installed_minio_version)
latest_version=$(get_latest_minio_version)

compare_versions "$installed_version" "$latest_version"
compare_versions "$installed_version" "$LATEST_MINIO_VERSION"
compare_result=$?

if [[ $compare_result -eq 0 ]]; then
echo "Older version of MinIO detected. Migration required."
return 0
elif [[ $compare_result -eq 1 ]]; then
echo "MinIO is up to date. No migration required."
return 1
echo "Migration required for MinIO version < $LATEST_MINIO_VERSION."
trigger_migration
else
echo "Unexpected result from version comparison."
exit 1
echo "No migration needed. Exiting."
exit 0
fi
}

check_and_install_minio

installed_version=$(get_installed_minio_version)
echo "Installed MinIO version: $installed_version"

detect_migration
detect_migration_result=$?

case "$detect_migration_result" in
0)
echo "Migrating MinIO"
install_minio
;;
1)
echo "No migration needed."
;;
*)
echo "An unexpected error occurred during MinIO version check."
exit 1
;;
esac
detect_migration
2 changes: 1 addition & 1 deletion scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ start_datastore() {
}

start_minio() {
./minio-migrate.sh
sudo hab svc load "${BLDR_ORIGIN}/builder-minio" --channel "${BLDR_MINIO_CHANNEL:=$BLDR_CHANNEL}" --force
}

Expand Down Expand Up @@ -409,7 +410,6 @@ install_options()
install_postgresql
fi
if [ "${MINIO_INSTALL:-0}" = 1 ]; then
./minio-migrate.sh
install_minio
fi
fi
Expand Down

0 comments on commit 3f64307

Please sign in to comment.