manual_nightly_deployment.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env bash
  2. #
  3. # This tool allows netdata team to manually deploy nightlies
  4. # It emulates the nightly operations required for a new version to be published for our users
  5. #
  6. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  7. #
  8. # Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud>
  9. #
  10. set -e
  11. # If we are not in netdata git repo, at the top level directory, fail
  12. TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
  13. CWD=$(git rev-parse --show-cdup || echo "")
  14. if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
  15. echo "Run as .travis/$(basename "$0") from top level directory of netdata git repository"
  16. echo "Changelog generation process aborted"
  17. exit 1
  18. fi
  19. if [ $# -lt 1 ] || [ $# -gt 2 ]; then
  20. echo "Run as ./$(basename "$0") [docker|gcs]|all] from the top level directory of netdata GIT repository"
  21. exit 1
  22. fi
  23. GSUTIL_BINARY=$(command -v gsutil 2> /dev/null)
  24. if [ -z "${GSUTIL_BINARY}" ]; then
  25. echo "No gsutil utility available, you need gsutil deployed to manually deploy to GCS"
  26. exit 1
  27. fi;
  28. # Function declarations
  29. publish_docker() {
  30. # Ensure REPOSITORY present
  31. if [ -z "${REPOSITORY}" ]; then
  32. echo "Please provide the repository to deploy the containers:"
  33. read -r REPOSITORY
  34. export REPOSITORY
  35. else
  36. echo "Docker publishing to ${REPOSITORY}"
  37. fi
  38. # Ensure DOCKER_USERNAME present
  39. if [ -z "${DOCKER_USERNAME}" ]; then
  40. echo "For repository ${REPOSITORY}, Please provide the docker USERNAME to use:"
  41. read -r DOCKER_USERNAME
  42. export DOCKER_USERNAME
  43. else
  44. echo "Using docker username ${DOCKER_USERNAME}"
  45. fi
  46. # Ensure DOCKER_PASS present
  47. if [ -z "${DOCKER_PASS}" ]; then
  48. echo "Username ${DOCKER_USERNAME} received, now give me the password:"
  49. read -r -s DOCKER_PASS
  50. export DOCKER_PASS
  51. else
  52. echo "Docker password has already been set to env, using that"
  53. fi
  54. echo "Building Docker images.."
  55. RELEASE_CHANNEL=nightly packaging/docker/build.sh
  56. echo "Publishing Docker images.."
  57. packaging/docker/publish.sh
  58. }
  59. publish_nightly_binaries() {
  60. echo "Publishing nightly binaries to GCS"
  61. echo "Please select the bucket to sync, from the ones available to you:"
  62. bucket_list=$(${GSUTIL_BINARY} list | tr '\n' ' ')
  63. declare -A buckets
  64. idx=0
  65. for abucket in ${bucket_list}; do
  66. echo "${idx}. ${abucket}"
  67. buckets["${idx}"]=${abucket}
  68. ((idx=idx+1))
  69. done
  70. read -p"Selection>" -r -n 1 selected_bucket
  71. echo "Ok!"
  72. echo "Syncing artifacts directory contents with GCS bucket: ${buckets[${selected_bucket}]}"
  73. if [ -d artifacts ]; then
  74. ${GSUTIL_BINARY} -m rsync -r artifacts "${buckets["${selected_bucket}"]}"
  75. echo "GCS Sync complete!"
  76. else
  77. echo "Directory artifacts does not exist, nothing to do on GCS"
  78. fi
  79. }
  80. prepare_and_publish_gcs() {
  81. # Prepare the artifacts directory
  82. echo "Preparing artifacts directory contents"
  83. .travis/create_artifacts.sh
  84. # Publish it to GCS
  85. publish_nightly_binaries
  86. # Clean up
  87. echo "Cleaning up repository"
  88. make clean || echo "Nothing to clean"
  89. make distclean || echo "Nothing to distclean"
  90. rm -rf artifacts
  91. }
  92. # Mandatory variable declarations
  93. export TRAVIS_REPO_SLUG="netdata/netdata"
  94. echo "Manual nightly deployment procedure started"
  95. case "$1" in
  96. "docker")
  97. publish_docker
  98. ;;
  99. "gcs")
  100. prepare_and_publish_gcs
  101. ;;
  102. "all")
  103. publish_docker
  104. prepare_and_publish_gcs
  105. ;;
  106. *)
  107. echo "ERROR: Invalid request parameter $1. Valid values are: docker, gcs, all"
  108. ;;
  109. esac
  110. echo "Manual nightly deployment completed!"