drone-wait-objectstore.sh 2.2 KB

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