release 9.1 KB

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