You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

drone-wait-objectstore.sh 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. function get_swift_token() {
  5. KEYSTONE_OUT=$(curl -s 'http://dockswift:5000/v2.0/tokens' -H 'Content-Type: application/json' -d '{"auth":{"passwordCredentials":{"username":"swift","password":"swift"},"tenantName":"service"}}')
  6. if (echo "$KEYSTONE_OUT" | grep -q 'object-store')
  7. then
  8. SWIFT_ENDPOINT=$(echo "$KEYSTONE_OUT" | php -r "echo array_values(array_filter(json_decode(file_get_contents('php://stdin'),true)['access']['serviceCatalog'], function(\$endpoint){return \$endpoint['type']==='object-store';}))[0]['endpoints'][0]['publicURL'];")
  9. SWIFT_TOKEN=$(echo "$KEYSTONE_OUT" | php -r "echo json_decode(file_get_contents('php://stdin'),true)['access']['token']['id'];")
  10. return 0
  11. else
  12. return -1
  13. fi
  14. }
  15. if [ "$OBJECT_STORE" == "s3" ]; then
  16. echo "Waiting for minio to be ready"
  17. timeout 60 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://minio:9000)" != "403" ]]; do sleep 5; done' || (
  18. echo "Failed to wait for minio to be ready" && exit 1
  19. )
  20. fi
  21. if [ "$OBJECT_STORE" == "swift" ]; then
  22. echo "waiting for keystone"
  23. until get_swift_token
  24. do
  25. sleep 2
  26. done
  27. echo "waiting for object store at $SWIFT_ENDPOINT"
  28. until curl -s -H "X-Auth-Token: $SWIFT_TOKEN" "$SWIFT_ENDPOINT"
  29. do
  30. sleep 2
  31. done
  32. echo "creating container"
  33. sleep 2
  34. while [ 1 ]
  35. do
  36. sleep 2
  37. respCode=$(curl -s -o /dev/null -w "%{http_code}" -X PUT -H "X-Auth-Token: $SWIFT_TOKEN" "$SWIFT_ENDPOINT/nextcloud")
  38. if [ "$respCode" == "201" ]
  39. then
  40. break
  41. fi
  42. done
  43. echo "creating test file"
  44. i=0
  45. while [ 1 ]
  46. do
  47. sleep 2
  48. respCode=$(curl -s -o /dev/null -w "%{http_code}" -X PUT -H "X-Auth-Token: $SWIFT_TOKEN" -H "Content-Type: text/html; charset=UTF-8" -d "Hello world" "$SWIFT_ENDPOINT/nextcloud/helloworld.txt")
  49. if [ "$respCode" == "201" ]
  50. then
  51. break
  52. fi
  53. i=$((i + 1))
  54. if [ "$i" == "20" ]
  55. then
  56. exit -1
  57. fi
  58. done
  59. echo "deleting test file"
  60. curl -s -o /dev/null -w "%{http_code}\n" -X DELETE -H "X-Auth-Token: $SWIFT_TOKEN" "$SWIFT_ENDPOINT/nextcloud/helloworld.txt"
  61. fi