release 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. help() {
  6. echo "$(basename $0) [version]"
  7. echo "Release etcd using the same approach as the etcd-release-runbook (https://goo.gl/Gxwysq)"
  8. echo ""
  9. echo "WARNING: This does not perform the 'Add API capabilities', 'Performance testing' "
  10. echo " or 'Documentation' steps. These steps must be performed manually BEFORE running this tool."
  11. echo ""
  12. echo "WARNING: This script does not sign releases, publish releases to github or sent announcement"
  13. echo " emails. These steps must be performed manually AFTER running this tool."
  14. echo ""
  15. echo " args:"
  16. echo " version: version of etcd to release, e.g. '3.2.18'"
  17. echo " flags:"
  18. echo " --no-upload: skip gs://etcd binary artifact uploads."
  19. echo " --no-docker-push: skip docker image pushes."
  20. echo ""
  21. }
  22. main() {
  23. VERSION=$1
  24. if [[ ! "${VERSION}" =~ [0-9]+.[0-9]+.[0-9]+ ]]; then
  25. echo "Expected 'version' param of the form '<major-version>.<minor-version>.<patch-version>' but got '${VERSION}'"
  26. exit 1
  27. fi
  28. RELEASE_VERSION="v${VERSION}"
  29. MINOR_VERSION=$(echo "${VERSION}" | cut -d. -f 1-2)
  30. BRANCH="release-${MINOR_VERSION}"
  31. if ! command -v docker >/dev/null; then
  32. echo "cannot find docker"
  33. exit 1
  34. fi
  35. KEYID=$(gpg --list-keys --with-colons| awk -F: '/^pub:/ { print $5 }')
  36. if [[ -z "${KEYID}" ]]; then
  37. echo "Failed to load gpg key. Is gpg set up correctly for etcd releases?"
  38. exit 1
  39. fi
  40. # Expected umask for etcd release artifacts
  41. umask 022
  42. # Set up release directory.
  43. local reldir="/tmp/etcd-release-${VERSION}"
  44. if [ ! -d "${reldir}/etcd" ]; then
  45. mkdir -p "${reldir}"
  46. cd "${reldir}"
  47. git clone git@github.com:etcd-io/etcd.git --branch "${BRANCH}"
  48. fi
  49. cd "${reldir}/etcd"
  50. # If a release version tag already exists, use it.
  51. local remote_tag_exists=$(git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}")
  52. if [ ${remote_tag_exists} -gt 0 ]; then
  53. echo "Release version tag exists on remote. Checking out refs/tags/${RELEASE_VERSION}"
  54. git checkout -q "tags/${RELEASE_VERSION}"
  55. fi
  56. # Check go version.
  57. # download "yq" from https://github.com/mikefarah/yq
  58. local go_version="go$(yq read .travis.yml "go[0]")"
  59. local current_go_version=$(go version | awk '{ print $3 }')
  60. if [[ "${current_go_version}" != "${go_version}" ]]; then
  61. echo "Current go version is ${current_go_version}, but etcd ${RELEASE_VERSION} requires ${go_version} (see .travis.yml)."
  62. exit 1
  63. fi
  64. # If the release tag does not already exist remotely, create it.
  65. if [ ${remote_tag_exists} -eq 0 ]; then
  66. # Bump version/version.go to release version.
  67. local source_version=$(egrep "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
  68. if [[ "${source_version}" != "${VERSION}" ]]; then
  69. source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
  70. if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
  71. echo "Wrong etcd minor version in version/version.go. Expected ${MINOR_VERSION} but got ${source_minor_version}. Aborting."
  72. exit 1
  73. fi
  74. echo "Updating version from ${source_version} to ${VERSION} in version/version.go"
  75. sed -i "s/${source_version}/${VERSION}/g" version/version.go
  76. fi
  77. echo "Building etcd and checking --version output"
  78. ./build
  79. local etcd_version=$(bin/etcd --version | grep "etcd Version" | awk '{ print $3 }')
  80. if [[ "${etcd_version}" != "${VERSION}" ]]; then
  81. echo "Wrong etcd version in version/version.go. Expected ${etcd_version} but got ${VERSION}. Aborting."
  82. exit 1
  83. fi
  84. if [[ ! -z $(git status -s) ]]; then
  85. echo "Committing version/version.go update."
  86. git add version/version.go
  87. git commit -m "version: bump up to ${VERSION}"
  88. git diff --staged
  89. fi
  90. # Push the version change if it's not already been pushed.
  91. if [ $(git rev-list --count "origin/${BRANCH}..${BRANCH}") -gt 0 ]; then
  92. read -p "Push version bump up to ${VERSION} to github.com/etcd-io/etcd [y/N]? " confirm
  93. [[ "${confirm,,}" == "y" ]] || exit 1
  94. git push
  95. fi
  96. # Tag release.
  97. if [ $(git tag --list | grep -c "${RELEASE_VERSION}") -gt 0 ]; then
  98. echo "Skipping tag step. git tag ${RELEASE_VERSION} already exists."
  99. else
  100. echo "Tagging release..."
  101. git tag --local-user "${KEYID}" --sign "${RELEASE_VERSION}" --message "${RELEASE_VERSION}"
  102. fi
  103. # Push the tag change if it's not already been pushed.
  104. read -p "Push etcd ${RELEASE_VERSION} tag [y/N]? " confirm
  105. [[ "${confirm,,}" == "y" ]] || exit 1
  106. git push origin "tags/${RELEASE_VERSION}"
  107. fi
  108. # Build release.
  109. # TODO: check the release directory for all required build artifacts.
  110. if [ -d release ]; then
  111. echo "Skpping release build step. /release directory already exists."
  112. else
  113. echo "Building release..."
  114. # Check for old and new names of the release build script.
  115. # TODO: Move the release script into this on as a function?
  116. if [ -f ./scripts/release.sh ]; then
  117. ./scripts/release.sh "${RELEASE_VERSION}"
  118. else
  119. ./scripts/build-release.sh "${RELEASE_VERSION}"
  120. fi
  121. fi
  122. # Sanity checks.
  123. ./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcd --version | grep -q "etcd Version: ${VERSION}" || true
  124. ./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcdctl version | grep -q "etcdctl version: ${VERSION}" || true
  125. # Upload artifacts.
  126. if [ "${NO_UPLOAD}" == 1 ]; then
  127. echo "Skipping artifact upload to gs://etcd. --no-upload flat is set."
  128. else
  129. read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
  130. [[ "${confirm,,}" == "y" ]] || exit 1
  131. gsutil -m cp ./release/*.zip gs://etcd/${RELEASE_VERSION}/
  132. gsutil -m cp ./release/*.tar.gz gs://etcd/${RELEASE_VERSION}/
  133. gsutil -m acl ch -u allUsers:R -r gs://etcd/${RELEASE_VERSION}/
  134. fi
  135. # Push images.
  136. if [ "${NO_DOCKER_PUSH}" == 1 ]; then
  137. echo "Skipping docker push. --no-docker-push flat is set."
  138. else
  139. read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
  140. [[ "${confirm,,}" == "y" ]] || exit 1
  141. for i in {1..5}; do
  142. docker login quay.io && break
  143. echo "login failed, retrying"
  144. done
  145. gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
  146. echo "Pushing container images to quay.io" ${RELEASE_VERSION}
  147. docker push quay.io/coreos/etcd:${RELEASE_VERSION}
  148. echo "Pushing container images to gcr.io" ${RELEASE_VERSION}
  149. gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}
  150. for TARGET_ARCH in "-arm64" "-ppc64le"; do
  151. echo "Pushing container images to quay.io" ${RELEASE_VERSION}${TARGET_ARCH}
  152. docker push quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}
  153. echo "Pushing container images to gcr.io" ${RELEASE_VERSION}${TARGET_ARCH}
  154. gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}
  155. done
  156. echo "Setting permissions using gsutil..."
  157. gsutil -m acl ch -u allUsers:R -r gs://artifacts.etcd-development.appspot.com
  158. fi
  159. # TODO: signing process
  160. echo ""
  161. echo "WARNING: The release has not been signed and published to github. This must be done manually."
  162. echo ""
  163. echo "Success."
  164. exit 0
  165. }
  166. POSITIONAL=()
  167. NO_UPLOAD=0
  168. NO_DOCKER_PUSH=0
  169. while test $# -gt 0; do
  170. case "$1" in
  171. -h|--help)
  172. shift
  173. help
  174. exit 0
  175. ;;
  176. --no-upload)
  177. NO_UPLOAD=1
  178. shift
  179. ;;
  180. --no-docker-push)
  181. NO_DOCKER_PUSH=1
  182. shift
  183. ;;
  184. *)
  185. POSITIONAL+=("$1") # save it in an array for later
  186. shift # past argument
  187. ;;
  188. esac
  189. done
  190. set -- "${POSITIONAL[@]}" # restore positional parameters
  191. if [[ ! $# -eq 1 ]]; then
  192. help
  193. exit 1
  194. fi
  195. main $1