release 9.2 KB

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