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

Added minio migration script #277

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions scripts/minio-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function preflight_checks () {
echo ""
}

function downloand_bucket_objects () {
function download_bucket_objects () {
aws ${opts[*]} s3 sync $s3_url $waypoint
}

Expand Down Expand Up @@ -264,7 +264,7 @@ case "${1}" in
usage ) usage ;;
print_env ) print_env ;;
preflight_checks ) preflight_checks ;;
download ) downloand_bucket_objects ;;
download ) download_bucket_objects ;;
upgrade ) upgrade_minio ;;
downgrade ) downgrade_minio ;;
upload ) upload_bucket_objects ;;
Expand Down
51 changes: 50 additions & 1 deletion scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ umask 0022

# Defaults
BLDR_ORIGIN=${BLDR_ORIGIN:="habitat"}
BREAKING_MINIO_VERSION="2023-11-01T01-57-10Z"

sudo () {
[[ $EUID = 0 ]] || set -- command sudo -E "$@"
Expand Down Expand Up @@ -200,7 +201,41 @@ start_datastore() {
}

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

set +e
is_minio_migration_needed
migration_needed=$?
set -e
sougata-progress marked this conversation as resolved.
Show resolved Hide resolved

if [ "$migration_needed" -eq 1 ]; then
bash ./minio-update.sh preflight_checks
sougata-progress marked this conversation as resolved.
Show resolved Hide resolved
sudo hab svc load "${BLDR_ORIGIN}/builder-minio" --channel "stable" --force
echo MinIO migration required
backup_minio_data
echo starting minio download

bash ./minio-update.sh download
sudo hab svc unload "${BLDR_ORIGIN}/builder-minio"
sudo sh -c "find /hab/svc/builder-minio/data/ -maxdepth 1 -mindepth 1 -type d | xargs rm -rf"
sougata-progress marked this conversation as resolved.
Show resolved Hide resolved
fi

sudo rm -rf /hab/pkgs/habitat/builder-minio
sudo hab svc load "${BLDR_ORIGIN}/builder-minio" --channel $BLDR_CHANNEL --force

sougata-progress marked this conversation as resolved.
Show resolved Hide resolved
if [ "$migration_needed" -eq 1 ]; then
bash ./minio-update.sh upload
fi
}

backup_minio_data() {
echo "Starting MinIO data backup"

sudo mkdir -p /hab/svc/builder-minio/data-bkp/

sudo cp -r /hab/svc/builder-minio/data/* /hab/svc/builder-minio/data-bkp/

echo "Old MinIO data has been backed up to /hab/svc/builder-minio/data-bkp/"

}

start_memcached() {
Expand All @@ -222,6 +257,20 @@ generate_bldr_keys() {
hab file upload "builder-api.default" "$(date +%s)" "/hab/cache/keys/${KEY_NAME}.box.key"
}

is_minio_migration_needed() {
installed_version=$(hab pkg path core/minio | cut -d '/' -f6)

response=$(curl -s "https://bldr.habitat.sh/v1/depot/channels/$BLDR_ORIGIN/$BLDR_CHANNEL/pkgs/builder-minio/latest")
minio_version_lookup=$(echo "$response" | jq -r '.deps[] | select(.origin == "core" and .name == "minio") | .version')

echo minio_version_lookup $minio_version_lookup
if [[ "${installed_version}" < "${BREAKING_MINIO_VERSION}" && ! "${BREAKING_MINIO_VERSION}" > "${minio_version_lookup}" ]]; then
return 1
else
return 0
fi
sougata-progress marked this conversation as resolved.
Show resolved Hide resolved
}

upload_ssl_certificate() {
if [ "${APP_SSL_ENABLED}" = "true" ]; then
echo "SSL enabled - uploading certificate files"
Expand Down