release 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. # Generate SHA256SUM
  126. echo -e "Generating sha256sum of release artifacts.\n"
  127. pushd ./release
  128. ls . | grep -E '\.tar.gz$|\.zip$' | xargs shasum -a 256 > ./SHA256SUM
  129. popd
  130. if [ -s ./release/SHA256SUM ]; then
  131. cat ./release/SHA256SUM
  132. else
  133. echo "sha256sum is not valid. Aborting."
  134. exit 1
  135. fi
  136. # Upload artifacts.
  137. if [ "${NO_UPLOAD}" == 1 ]; then
  138. echo "Skipping artifact upload to gs://etcd. --no-upload flat is set."
  139. else
  140. read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
  141. [[ "${confirm,,}" == "y" ]] || exit 1
  142. gsutil -m cp ./release/SHA256SUM gs://etcd/${RELEASE_VERSION}/
  143. gsutil -m cp ./release/*.zip gs://etcd/${RELEASE_VERSION}/
  144. gsutil -m cp ./release/*.tar.gz gs://etcd/${RELEASE_VERSION}/
  145. gsutil -m acl ch -u allUsers:R -r gs://etcd/${RELEASE_VERSION}/
  146. fi
  147. # Push images.
  148. if [ "${NO_DOCKER_PUSH}" == 1 ]; then
  149. echo "Skipping docker push. --no-docker-push flat is set."
  150. else
  151. read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
  152. [[ "${confirm,,}" == "y" ]] || exit 1
  153. for i in {1..5}; do
  154. docker login quay.io && break
  155. echo "login failed, retrying"
  156. done
  157. gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
  158. echo "Pushing container images to quay.io" ${RELEASE_VERSION}
  159. docker push quay.io/coreos/etcd:${RELEASE_VERSION}
  160. echo "Pushing container images to gcr.io" ${RELEASE_VERSION}
  161. gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}
  162. for TARGET_ARCH in "-arm64" "-ppc64le"; do
  163. echo "Pushing container images to quay.io" ${RELEASE_VERSION}${TARGET_ARCH}
  164. docker push quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}
  165. echo "Pushing container images to gcr.io" ${RELEASE_VERSION}${TARGET_ARCH}
  166. gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}
  167. done
  168. echo "Setting permissions using gsutil..."
  169. gsutil -m acl ch -u allUsers:R -r gs://artifacts.etcd-development.appspot.com
  170. fi
  171. # TODO: signing process
  172. echo ""
  173. echo "WARNING: The release has not been signed and published to github. This must be done manually."
  174. echo ""
  175. echo "Success."
  176. exit 0
  177. }
  178. POSITIONAL=()
  179. NO_UPLOAD=0
  180. NO_DOCKER_PUSH=0
  181. while test $# -gt 0; do
  182. case "$1" in
  183. -h|--help)
  184. shift
  185. help
  186. exit 0
  187. ;;
  188. --no-upload)
  189. NO_UPLOAD=1
  190. shift
  191. ;;
  192. --no-docker-push)
  193. NO_DOCKER_PUSH=1
  194. shift
  195. ;;
  196. *)
  197. POSITIONAL+=("$1") # save it in an array for later
  198. shift # past argument
  199. ;;
  200. esac
  201. done
  202. set -- "${POSITIONAL[@]}" # restore positional parameters
  203. if [[ ! $# -eq 1 ]]; then
  204. help
  205. exit 1
  206. fi
  207. main $1