release 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 acbuild >/dev/null; then
  32. echo "cannot find acbuild"
  33. exit 1
  34. fi
  35. if ! command -v docker >/dev/null; then
  36. echo "cannot find docker"
  37. exit 1
  38. fi
  39. KEYID=$(gpg --list-keys --with-colons| awk -F: '/^pub:/ { print $5 }')
  40. if [[ -z "${KEYID}" ]]; then
  41. echo "Failed to load gpg key. Is gpg set up correctly for etcd releases?"
  42. exit 1
  43. fi
  44. # Set up release directory.
  45. local reldir="/tmp/etcd-release-${VERSION}"
  46. if [ ! -d "${reldir}/etcd" ]; then
  47. mkdir -p "${reldir}"
  48. cd "${reldir}"
  49. git clone git@github.com:coreos/etcd.git --branch "${BRANCH}"
  50. fi
  51. cd "${reldir}/etcd"
  52. # If a release version tag already exists, use it.
  53. local remote_tag_exists=$(git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -q "${RELEASE_VERSION}")
  54. if ${remote_tag_exists}; then
  55. echo "Release version tag exists on remote. Checking out refs/tags/${RELEASE_VERSION}"
  56. git checkout -q "tags/${RELEASE_VERSION}"
  57. fi
  58. # Check go version.
  59. local go_version="go$(yq -r ".go[0]" .travis.yml)"
  60. local current_go_version=$(go version | awk '{ print $3 }')
  61. if [[ "${current_go_version}" != "${go_version}" ]]; then
  62. echo "Current go version is ${current_go_version}, but etcd ${RELEASE_VERSION} requires ${go_version} (see .travis.yml)."
  63. exit 1
  64. fi
  65. # If the release tag does not already exist remotely, create it.
  66. if ! ${remote_tag_exists}; then
  67. # Bump version/version.go to release version.
  68. local source_version=$(egrep "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
  69. if [[ "${source_version}" != "${VERSION}" ]]; then
  70. source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
  71. if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
  72. echo "Wrong etcd minor version in version/version.go. Expected ${MINOR_VERSION} but got ${source_minor_version}. Aborting."
  73. exit 1
  74. fi
  75. echo "Updating version from ${source_version} to ${VERSION} in version/version.go"
  76. sed -i "s/${source_version}/${VERSION}/g" version/version.go
  77. echo "Building etcd with updated version"
  78. ./build
  79. fi
  80. local etcd_version=$(bin/etcd --version | grep "etcd Version" | awk '{ print $3 }')
  81. if [[ "${etcd_version}" != "${VERSION}" ]]; then
  82. echo "Wrong etcd version in version/version.go. Expected ${etcd_version} but got ${VERSION}. Aborting."
  83. exit 1
  84. fi
  85. if [[ ! -z $(git status -s) ]]; then
  86. echo "Committing version/version.go update."
  87. git add version/version.go
  88. git commit -m "version: bump up to ${VERSION}"
  89. git diff --staged
  90. fi
  91. # Push the version change if it's not already been pushed.
  92. if [ $(git rev-list --count "origin/${BRANCH}..${BRANCH}") -gt 0 ]; then
  93. read -p "Push version bump up to ${VERSION} to github.com/coreos/etcd [y/N]? " confirm
  94. [[ "${confirm,,}" == "y" ]] || exit 1
  95. git push
  96. fi
  97. # Tag release.
  98. if $(git tag --list | grep -q "${RELEASE_VERSION}"); then
  99. echo "Skipping tag step. git tag ${RELEASE_VERSION} already exists."
  100. else
  101. echo "Tagging release..."
  102. git tag --local-user "${KEYID}" --sign "${RELEASE_VERSION}" --message "${RELEASE_VERSION}"
  103. fi
  104. # Push the tag change if it's not already been pushed.
  105. read -p "Push etcd ${RELEASE_VERSION} tag [y/N]? " confirm
  106. [[ "${confirm,,}" == "y" ]] || exit 1
  107. git push origin "tags/${RELEASE_VERSION}"
  108. fi
  109. # Build release.
  110. # TODO: check the release directory for all required build artifacts.
  111. if [ -d release ]; then
  112. echo "Skpping release build step. /release directory already exists."
  113. else
  114. echo "Building release..."
  115. # Check for old and new names of the release build script.
  116. # TODO: Move the release script into this on as a function?
  117. if [ -f ./scripts/release.sh ]; then
  118. ./scripts/release.sh "${RELEASE_VERSION}"
  119. else
  120. ./scripts/build-release.sh "${RELEASE_VERSION}"
  121. fi
  122. fi
  123. # Sanity checks.
  124. ./release/etcd-${RELEASE_VERSION}-linux-amd64/etcd --version | grep -q "etcd Version: ${VERSION}"
  125. ETCDCTL_API=3 ./release/etcd-${RELEASE_VERSION}-linux-amd64/etcdctl version | grep -q "etcdctl version: ${VERSION}"
  126. # Upload artifacts.
  127. if [ "${NO_UPLOAD}" == 1 ]; then
  128. echo "Skipping artifact upload to gs://etcd. --no-upload flat is set."
  129. else
  130. read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
  131. [[ "${confirm,,}" == "y" ]] || exit 1
  132. gsutil -m cp ./release/*.zip gs://etcd/${RELEASE_VERSION}/
  133. gsutil -m cp ./release/*.tar.gz gs://etcd/${RELEASE_VERSION}/
  134. gsutil -m cp ./release/*.aci gs://etcd/${RELEASE_VERSION}/
  135. gsutil -m acl ch -u allUsers:R -r gs://etcd/${RELEASE_VERSION}/
  136. fi
  137. # Push images.
  138. if [ "${NO_DOCKER_PUSH}" == 1 ]; then
  139. echo "Skipping docker push. --no-docker-push flat is set."
  140. else
  141. read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
  142. [[ "${confirm,,}" == "y" ]] || exit 1
  143. until $(docker login quay.io); do
  144. echo "Docker login failed, retrying."
  145. done
  146. gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
  147. for TARGET_ARCH in "-arm64" "-ppc64le" ""; do
  148. docker push quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}
  149. gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}
  150. done
  151. gsutil -m acl ch -u allUsers:R -r gs://artifacts.etcd-development.appspot.com
  152. docker tag quay.io/coreos/etcd:${RELEASE_VERSION} quay.io/coreos/etcd:v${MINOR_VERSION}
  153. docker push quay.io/coreos/etcd:v${MINOR_VERSION}
  154. gcloud docker -- tag gcr.io/etcd-development/etcd:${RELEASE_VERSION} gcr.io/etcd-development/etcd:v${MINOR_VERSION}
  155. gcloud docker -- push gcr.io/etcd-development/etcd:v${MINOR_VERSION}
  156. fi
  157. # TODO: test
  158. # docker run --rm --name etcd-gcr-${RELEASE_VERSION} gcr.io/etcd-development/etcd:${RELEASE_VERSION};
  159. # docker exec etcd-gcr-${RELEASE_VERSION} /bin/sh -c "/usr/local/bin/etcd --version"
  160. # docker exec etcd-gcr-${RELEASE_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl version"
  161. # docker exec etcd-gcr-${RELEASE_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put foo bar"
  162. # docker exec etcd-gcr-${RELEASE_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl get foo"
  163. # Bump version to next development version.
  164. git checkout -q "${BRANCH}" # Since we might be on a checkout of the remote version tag.
  165. local source_version=$(egrep "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
  166. if [[ "${source_version}" != "${VERSION}+git" ]]; then
  167. echo "Updating version from ${source_version} to ${VERSION}+git in version/version.go"
  168. sed -i "s/${source_version}/${VERSION}+git/g" version/version.go
  169. echo "Building etcd with ${VERSION}+git in version/version.go"
  170. git add version/version.go
  171. git commit -m "version: bump up to ${VERSION}+git"
  172. git diff --staged
  173. read -p "Push version bump up to ${VERSION}+git to github.com/coreos/etcd [y/N]? " confirm
  174. [[ "${confirm,,}" == "y" ]] || exit 1
  175. git push
  176. fi
  177. # TODO: signing process
  178. echo ""
  179. echo "WARNING: The release has not been signed and published to github. This must be done manually."
  180. echo "WARNING: version/version.go has not been updated to ${RELEASE_VERSION}+git. This must be done manually."
  181. echo ""
  182. echo "Success."
  183. exit 0
  184. }
  185. POSITIONAL=()
  186. NO_UPLOAD=0
  187. NO_DOCKER_PUSH=0
  188. while test $# -gt 0; do
  189. case "$1" in
  190. -h|--help)
  191. shift
  192. help
  193. exit 0
  194. ;;
  195. --no-upload)
  196. NO_UPLOAD=1
  197. shift
  198. ;;
  199. --no-docker-push)
  200. NO_DOCKER_PUSH=1
  201. shift
  202. ;;
  203. *)
  204. POSITIONAL+=("$1") # save it in an array for later
  205. shift # past argument
  206. ;;
  207. esac
  208. done
  209. set -- "${POSITIONAL[@]}" # restore positional parameters
  210. if [[ ! $# -eq 1 ]]; then
  211. help
  212. exit 1
  213. fi
  214. main $1