github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/buildscripts/minio-upgrade.sh (about)

     1  #!/bin/bash
     2  
     3  trap 'cleanup $LINENO' ERR
     4  
     5  # shellcheck disable=SC2120
     6  cleanup() {
     7  	MINIO_VERSION=dev docker-compose \
     8  		-f "buildscripts/upgrade-tests/compose.yml" \
     9  		rm -s -f
    10  	docker volume prune -f
    11  }
    12  
    13  verify_checksum_after_heal() {
    14  	local sum1
    15  	sum1=$(curl -s "$2" | sha256sum)
    16  	mc admin heal --json -r "$1" >/dev/null # test after healing
    17  	local sum1_heal
    18  	sum1_heal=$(curl -s "$2" | sha256sum)
    19  
    20  	if [ "${sum1_heal}" != "${sum1}" ]; then
    21  		echo "mismatch expected ${sum1_heal}, got ${sum1}"
    22  		exit 1
    23  	fi
    24  }
    25  
    26  verify_checksum_mc() {
    27  	local expected
    28  	expected=$(mc cat "$1" | sha256sum)
    29  	local got
    30  	got=$(mc cat "$2" | sha256sum)
    31  
    32  	if [ "${expected}" != "${got}" ]; then
    33  		echo "mismatch - expected ${expected}, got ${got}"
    34  		exit 1
    35  	fi
    36  	echo "matches - ${expected}, got ${got}"
    37  }
    38  
    39  add_alias() {
    40  	for i in $(seq 1 4); do
    41  		echo "... attempting to add alias $i"
    42  		until (mc alias set minio http://127.0.0.1:9000 minioadmin minioadmin); do
    43  			echo "...waiting... for 5secs" && sleep 5
    44  		done
    45  	done
    46  
    47  	echo "Sleeping for nginx"
    48  	sleep 20
    49  }
    50  
    51  __init__() {
    52  	sudo apt install curl -y
    53  	export GOPATH=/tmp/gopath
    54  	export PATH=${PATH}:${GOPATH}/bin
    55  
    56  	go install github.com/minio/mc@latest
    57  
    58  	TAG=minio/minio:dev make docker
    59  
    60  	MINIO_VERSION=RELEASE.2019-12-19T22-52-26Z docker-compose \
    61  		-f "buildscripts/upgrade-tests/compose.yml" \
    62  		up -d --build
    63  
    64  	add_alias
    65  
    66  	mc mb minio/minio-test/
    67  	mc cp ./minio minio/minio-test/to-read/
    68  	mc cp /etc/hosts minio/minio-test/to-read/hosts
    69  	mc anonymous set download minio/minio-test
    70  
    71  	verify_checksum_mc ./minio minio/minio-test/to-read/minio
    72  
    73  	curl -s http://127.0.0.1:9000/minio-test/to-read/hosts | sha256sum
    74  
    75  	MINIO_VERSION=dev docker-compose -f "buildscripts/upgrade-tests/compose.yml" stop
    76  }
    77  
    78  main() {
    79  	MINIO_VERSION=dev docker-compose -f "buildscripts/upgrade-tests/compose.yml" up -d --build
    80  
    81  	add_alias
    82  
    83  	verify_checksum_after_heal minio/minio-test http://127.0.0.1:9000/minio-test/to-read/hosts
    84  
    85  	verify_checksum_mc ./minio minio/minio-test/to-read/minio
    86  
    87  	verify_checksum_mc /etc/hosts minio/minio-test/to-read/hosts
    88  
    89  	cleanup
    90  }
    91  
    92  (__init__ "$@" && main "$@")