build-binary 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. set -e
  3. VER=$1
  4. PROJ="etcd"
  5. if [ -z "$1" ]; then
  6. echo "Usage: ${0} VERSION" >> /dev/stderr
  7. exit 255
  8. fi
  9. set -u
  10. function setup_env {
  11. local proj=${1}
  12. local ver=${2}
  13. if [ ! -d ${proj} ]; then
  14. git clone https://github.com/coreos/${proj}
  15. fi
  16. pushd ${proj} >/dev/null
  17. git checkout master
  18. git fetch --all
  19. git reset --hard origin/master
  20. git checkout $ver
  21. popd >/dev/null
  22. }
  23. function package {
  24. local target=${1}
  25. local srcdir="${2}/bin"
  26. local ccdir="${srcdir}/${GOOS}_${GOARCH}"
  27. if [ -d ${ccdir} ]; then
  28. srcdir=${ccdir}
  29. fi
  30. local ext=""
  31. if [ ${GOOS} == "windows" ]; then
  32. ext=".exe"
  33. fi
  34. for bin in etcd etcdctl; do
  35. cp ${srcdir}/${bin} ${target}/${bin}${ext}
  36. done
  37. cp etcd/README.md ${target}/README.md
  38. cp etcd/etcdctl/README.md ${target}/README-etcdctl.md
  39. cp etcd/etcdctl/READMEv2.md ${target}/READMEv2-etcdctl.md
  40. cp -R etcd/Documentation ${target}/Documentation
  41. }
  42. function main {
  43. mkdir release
  44. cd release
  45. setup_env ${PROJ} ${VER}
  46. for os in darwin windows linux; do
  47. export GOOS=${os}
  48. TARGET_ARCHS=("amd64")
  49. if [ ${GOOS} == "linux" ]; then
  50. TARGET_ARCHS+=("arm64")
  51. TARGET_ARCHS+=("ppc64le")
  52. fi
  53. for TARGET_ARCH in "${TARGET_ARCHS[@]}"; do
  54. export GOARCH=${TARGET_ARCH}
  55. pushd etcd >/dev/null
  56. GO_LDFLAGS="-s" ./build
  57. popd >/dev/null
  58. TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
  59. mkdir ${TARGET}
  60. package ${TARGET} ${PROJ}
  61. if [ ${GOOS} == "linux" ]; then
  62. tar cfz ${TARGET}.tar.gz ${TARGET}
  63. echo "Wrote release/${TARGET}.tar.gz"
  64. else
  65. zip -qr ${TARGET}.zip ${TARGET}
  66. echo "Wrote release/${TARGET}.zip"
  67. fi
  68. done
  69. done
  70. }
  71. main