build.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Download the flannel, etcd, docker, bridge-utils and K8s binaries automatically
  16. # and store into binaries directory.
  17. # Run as sudoers only
  18. # author @kevin-wangzefeng
  19. set -o errexit
  20. set -o nounset
  21. set -o pipefail
  22. readonly ROOT=$(dirname "${BASH_SOURCE}")
  23. source ${ROOT}/config-build.sh
  24. # ensure $RELEASES_DIR is an absolute file path
  25. mkdir -p ${RELEASES_DIR}
  26. RELEASES_DIR=$(cd ${RELEASES_DIR}; pwd)
  27. # get absolute file path of binaries
  28. BINARY_DIR=$(cd ${ROOT}; pwd)/binaries
  29. function clean-up() {
  30. rm -rf ${RELEASES_DIR}
  31. rm -rf ${BINARY_DIR}
  32. }
  33. function download-releases() {
  34. rm -rf ${RELEASES_DIR}
  35. mkdir -p ${RELEASES_DIR}
  36. echo "Download flannel release v${FLANNEL_VERSION} ..."
  37. curl -L ${FLANNEL_DOWNLOAD_URL} -o ${RELEASES_DIR}/flannel.tar.gz
  38. echo "Download etcd release v${ETCD_VERSION} ..."
  39. curl -L ${ETCD_DOWNLOAD_URL} -o ${RELEASES_DIR}/etcd.tar.gz
  40. echo "Download kubernetes release v${K8S_VERSION} ..."
  41. curl -L ${K8S_DOWNLOAD_URL} -o ${RELEASES_DIR}/kubernetes.tar.gz
  42. echo "Download docker-latest ..."
  43. curl -L https://get.docker.com/builds/Linux/x86_64/docker-latest -o ${RELEASES_DIR}/docker
  44. }
  45. function unpack-releases() {
  46. rm -rf ${BINARY_DIR}
  47. mkdir -p ${BINARY_DIR}/master/bin
  48. mkdir -p ${BINARY_DIR}/node/bin
  49. # flannel
  50. if [[ -f ${RELEASES_DIR}/flannel.tar.gz ]] ; then
  51. tar xzf ${RELEASES_DIR}/flannel.tar.gz -C ${RELEASES_DIR}
  52. cp ${RELEASES_DIR}/flannel-${FLANNEL_VERSION}/flanneld ${BINARY_DIR}/master/bin
  53. cp ${RELEASES_DIR}/flannel-${FLANNEL_VERSION}/flanneld ${BINARY_DIR}/node/bin
  54. fi
  55. # ectd
  56. if [[ -f ${RELEASES_DIR}/etcd.tar.gz ]] ; then
  57. tar xzf ${RELEASES_DIR}/etcd.tar.gz -C ${RELEASES_DIR}
  58. ETCD="etcd-v${ETCD_VERSION}-linux-amd64"
  59. cp ${RELEASES_DIR}/$ETCD/etcd \
  60. ${RELEASES_DIR}/$ETCD/etcdctl ${BINARY_DIR}/master/bin
  61. cp ${RELEASES_DIR}/$ETCD/etcd \
  62. ${RELEASES_DIR}/$ETCD/etcdctl ${BINARY_DIR}/node/bin
  63. fi
  64. # k8s
  65. if [[ -f ${RELEASES_DIR}/kubernetes.tar.gz ]] ; then
  66. tar xzf ${RELEASES_DIR}/kubernetes.tar.gz -C ${RELEASES_DIR}
  67. pushd ${RELEASES_DIR}/kubernetes/server
  68. tar xzf kubernetes-server-linux-amd64.tar.gz
  69. popd
  70. cp ${RELEASES_DIR}/kubernetes/server/kubernetes/server/bin/kube-apiserver \
  71. ${RELEASES_DIR}/kubernetes/server/kubernetes/server/bin/kube-controller-manager \
  72. ${RELEASES_DIR}/kubernetes/server/kubernetes/server/bin/kube-scheduler ${BINARY_DIR}/master/bin
  73. cp ${RELEASES_DIR}/kubernetes/server/kubernetes/server/bin/kubelet \
  74. ${RELEASES_DIR}/kubernetes/server/kubernetes/server/bin/kube-proxy ${BINARY_DIR}/node/bin
  75. cp ${RELEASES_DIR}/kubernetes/server/kubernetes/server/bin/kubectl ${BINARY_DIR}
  76. fi
  77. if [[ -f ${RELEASES_DIR}/docker ]]; then
  78. cp ${RELEASES_DIR}/docker ${BINARY_DIR}/node/bin
  79. fi
  80. chmod -R +x ${BINARY_DIR}
  81. echo "Done! All binaries are stored in ${BINARY_DIR}"
  82. }
  83. function parse-opt() {
  84. local opt=${1-}
  85. case $opt in
  86. download)
  87. download-releases
  88. ;;
  89. unpack)
  90. unpack-releases
  91. ;;
  92. clean)
  93. clean-up
  94. ;;
  95. all)
  96. download-releases
  97. unpack-releases
  98. ;;
  99. *)
  100. echo "Usage: "
  101. echo " build.sh <command>"
  102. echo "Commands:"
  103. echo " clean Clean up downloaded releases and unpacked binaries."
  104. echo " download Download releases to \"${RELEASES_DIR}\"."
  105. echo " unpack Unpack releases downloaded in \"${RELEASES_DIR}\", and copy binaries to \"${BINARY_DIR}\"."
  106. echo " all Download releases and unpack them."
  107. ;;
  108. esac
  109. }
  110. parse-opt $@