release.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. #!/usr/bin/env bash
  2. # Copyright 2016 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. # This file creates release artifacts (tar files, container images) that are
  16. # ready to distribute to install or distribute to end users.
  17. ###############################################################################
  18. # Most of the ::release:: namespace functions have been moved to
  19. # github.com/kubernetes/release. Have a look in that repo and specifically in
  20. # lib/releaselib.sh for ::release::-related functionality.
  21. ###############################################################################
  22. # This is where the final release artifacts are created locally
  23. readonly RELEASE_STAGE="${LOCAL_OUTPUT_ROOT}/release-stage"
  24. readonly RELEASE_TARS="${LOCAL_OUTPUT_ROOT}/release-tars"
  25. readonly RELEASE_IMAGES="${LOCAL_OUTPUT_ROOT}/release-images"
  26. KUBE_BUILD_HYPERKUBE=${KUBE_BUILD_HYPERKUBE:-y}
  27. KUBE_BUILD_CONFORMANCE=${KUBE_BUILD_CONFORMANCE:-y}
  28. KUBE_BUILD_PULL_LATEST_IMAGES=${KUBE_BUILD_PULL_LATEST_IMAGES:-y}
  29. # Validate a ci version
  30. #
  31. # Globals:
  32. # None
  33. # Arguments:
  34. # version
  35. # Returns:
  36. # If version is a valid ci version
  37. # Sets: (e.g. for '1.2.3-alpha.4.56+abcdef12345678')
  38. # VERSION_MAJOR (e.g. '1')
  39. # VERSION_MINOR (e.g. '2')
  40. # VERSION_PATCH (e.g. '3')
  41. # VERSION_PRERELEASE (e.g. 'alpha')
  42. # VERSION_PRERELEASE_REV (e.g. '4')
  43. # VERSION_BUILD_INFO (e.g. '.56+abcdef12345678')
  44. # VERSION_COMMITS (e.g. '56')
  45. function kube::release::parse_and_validate_ci_version() {
  46. # Accept things like "v1.2.3-alpha.4.56+abcdef12345678" or "v1.2.3-beta.4"
  47. local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-([a-zA-Z0-9]+)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)\\+[0-9a-f]{7,40})?$"
  48. local -r version="${1-}"
  49. [[ "${version}" =~ ${version_regex} ]] || {
  50. kube::log::error "Invalid ci version: '${version}', must match regex ${version_regex}"
  51. return 1
  52. }
  53. # The VERSION variables are used when this file is sourced, hence
  54. # the shellcheck SC2034 'appears unused' warning is to be ignored.
  55. # shellcheck disable=SC2034
  56. VERSION_MAJOR="${BASH_REMATCH[1]}"
  57. # shellcheck disable=SC2034
  58. VERSION_MINOR="${BASH_REMATCH[2]}"
  59. # shellcheck disable=SC2034
  60. VERSION_PATCH="${BASH_REMATCH[3]}"
  61. # shellcheck disable=SC2034
  62. VERSION_PRERELEASE="${BASH_REMATCH[4]}"
  63. # shellcheck disable=SC2034
  64. VERSION_PRERELEASE_REV="${BASH_REMATCH[5]}"
  65. # shellcheck disable=SC2034
  66. VERSION_BUILD_INFO="${BASH_REMATCH[6]}"
  67. # shellcheck disable=SC2034
  68. VERSION_COMMITS="${BASH_REMATCH[7]}"
  69. }
  70. # ---------------------------------------------------------------------------
  71. # Build final release artifacts
  72. function kube::release::clean_cruft() {
  73. # Clean out cruft
  74. find "${RELEASE_STAGE}" -name '*~' -exec rm {} \;
  75. find "${RELEASE_STAGE}" -name '#*#' -exec rm {} \;
  76. find "${RELEASE_STAGE}" -name '.DS*' -exec rm {} \;
  77. }
  78. function kube::release::package_tarballs() {
  79. # Clean out any old releases
  80. rm -rf "${RELEASE_STAGE}" "${RELEASE_TARS}" "${RELEASE_IMAGES}"
  81. mkdir -p "${RELEASE_TARS}"
  82. kube::release::package_src_tarball &
  83. kube::release::package_client_tarballs &
  84. kube::release::package_kube_manifests_tarball &
  85. kube::util::wait-for-jobs || { kube::log::error "previous tarball phase failed"; return 1; }
  86. # _node and _server tarballs depend on _src tarball
  87. kube::release::package_node_tarballs &
  88. kube::release::package_server_tarballs &
  89. kube::util::wait-for-jobs || { kube::log::error "previous tarball phase failed"; return 1; }
  90. kube::release::package_final_tarball & # _final depends on some of the previous phases
  91. kube::release::package_test_tarballs & # _test doesn't depend on anything
  92. kube::util::wait-for-jobs || { kube::log::error "previous tarball phase failed"; return 1; }
  93. }
  94. # Package the source code we built, for compliance/licensing/audit/yadda.
  95. function kube::release::package_src_tarball() {
  96. local -r src_tarball="${RELEASE_TARS}/kubernetes-src.tar.gz"
  97. kube::log::status "Building tarball: src"
  98. if [[ "${KUBE_GIT_TREE_STATE-}" = 'clean' ]]; then
  99. git archive -o "${src_tarball}" HEAD
  100. else
  101. find "${KUBE_ROOT}" -mindepth 1 -maxdepth 1 \
  102. ! \( \
  103. \( -path "${KUBE_ROOT}"/_\* -o \
  104. -path "${KUBE_ROOT}"/.git\* -o \
  105. -path "${KUBE_ROOT}"/.config\* -o \
  106. -path "${KUBE_ROOT}"/.gsutil\* \
  107. \) -prune \
  108. \) -print0 \
  109. | "${TAR}" czf "${src_tarball}" --transform "s|${KUBE_ROOT#/*}|kubernetes|" --null -T -
  110. fi
  111. }
  112. # Package up all of the cross compiled clients. Over time this should grow into
  113. # a full SDK
  114. function kube::release::package_client_tarballs() {
  115. # Find all of the built client binaries
  116. for platform_long in "${LOCAL_OUTPUT_BINPATH}"/*/*; do
  117. local platform
  118. local platform_tag
  119. platform=${platform_long##${LOCAL_OUTPUT_BINPATH}/} # Strip LOCAL_OUTPUT_BINPATH
  120. platform_tag=${platform/\//-} # Replace a "/" for a "-"
  121. kube::log::status "Starting tarball: client $platform_tag"
  122. (
  123. local release_stage="${RELEASE_STAGE}/client/${platform_tag}/kubernetes"
  124. rm -rf "${release_stage}"
  125. mkdir -p "${release_stage}/client/bin"
  126. local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
  127. if [[ "${platform%/*}" = 'windows' ]]; then
  128. client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
  129. fi
  130. # This fancy expression will expand to prepend a path
  131. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  132. # client_bins array.
  133. cp "${client_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  134. "${release_stage}/client/bin/"
  135. kube::release::clean_cruft
  136. local package_name="${RELEASE_TARS}/kubernetes-client-${platform_tag}.tar.gz"
  137. kube::release::create_tarball "${package_name}" "${release_stage}/.."
  138. ) &
  139. done
  140. kube::log::status "Waiting on tarballs"
  141. kube::util::wait-for-jobs || { kube::log::error "client tarball creation failed"; exit 1; }
  142. }
  143. # Package up all of the node binaries
  144. function kube::release::package_node_tarballs() {
  145. local platform
  146. for platform in "${KUBE_NODE_PLATFORMS[@]}"; do
  147. local platform_tag
  148. local arch
  149. platform_tag=${platform/\//-} # Replace a "/" for a "-"
  150. arch=$(basename "${platform}")
  151. kube::log::status "Building tarball: node $platform_tag"
  152. local release_stage="${RELEASE_STAGE}/node/${platform_tag}/kubernetes"
  153. rm -rf "${release_stage}"
  154. mkdir -p "${release_stage}/node/bin"
  155. local node_bins=("${KUBE_NODE_BINARIES[@]}")
  156. if [[ "${platform%/*}" = 'windows' ]]; then
  157. node_bins=("${KUBE_NODE_BINARIES_WIN[@]}")
  158. fi
  159. # This fancy expression will expand to prepend a path
  160. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  161. # node_bins array.
  162. cp "${node_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  163. "${release_stage}/node/bin/"
  164. # TODO: Docker images here
  165. # kube::release::create_docker_images_for_server "${release_stage}/server/bin" "${arch}"
  166. # Include the client binaries here too as they are useful debugging tools.
  167. local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
  168. if [[ "${platform%/*}" = 'windows' ]]; then
  169. client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
  170. fi
  171. # This fancy expression will expand to prepend a path
  172. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  173. # client_bins array.
  174. cp "${client_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  175. "${release_stage}/node/bin/"
  176. cp "${KUBE_ROOT}/Godeps/LICENSES" "${release_stage}/"
  177. cp "${RELEASE_TARS}/kubernetes-src.tar.gz" "${release_stage}/"
  178. kube::release::clean_cruft
  179. local package_name="${RELEASE_TARS}/kubernetes-node-${platform_tag}.tar.gz"
  180. kube::release::create_tarball "${package_name}" "${release_stage}/.."
  181. done
  182. }
  183. # Package up all of the server binaries in docker images
  184. function kube::release::build_server_images() {
  185. # Clean out any old images
  186. rm -rf "${RELEASE_IMAGES}"
  187. local platform
  188. for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
  189. local platform_tag
  190. local arch
  191. platform_tag=${platform/\//-} # Replace a "/" for a "-"
  192. arch=$(basename "${platform}")
  193. kube::log::status "Building images: $platform_tag"
  194. local release_stage
  195. release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
  196. rm -rf "${release_stage}"
  197. mkdir -p "${release_stage}/server/bin"
  198. # This fancy expression will expand to prepend a path
  199. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  200. # KUBE_SERVER_IMAGE_BINARIES array.
  201. cp "${KUBE_SERVER_IMAGE_BINARIES[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  202. "${release_stage}/server/bin/"
  203. kube::release::create_docker_images_for_server "${release_stage}/server/bin" "${arch}"
  204. done
  205. }
  206. # Package up all of the server binaries
  207. function kube::release::package_server_tarballs() {
  208. kube::release::build_server_images
  209. local platform
  210. for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
  211. local platform_tag
  212. local arch
  213. platform_tag=${platform/\//-} # Replace a "/" for a "-"
  214. arch=$(basename "${platform}")
  215. kube::log::status "Building tarball: server $platform_tag"
  216. # NOTE: this directory was setup in kube::release::build_server_images
  217. local release_stage
  218. release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
  219. mkdir -p "${release_stage}/addons"
  220. # This fancy expression will expand to prepend a path
  221. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  222. # KUBE_SERVER_BINARIES array.
  223. cp "${KUBE_SERVER_BINARIES[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  224. "${release_stage}/server/bin/"
  225. # Include the client binaries here too as they are useful debugging tools.
  226. local client_bins
  227. client_bins=("${KUBE_CLIENT_BINARIES[@]}")
  228. if [[ "${platform%/*}" = 'windows' ]]; then
  229. client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
  230. fi
  231. # This fancy expression will expand to prepend a path
  232. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  233. # client_bins array.
  234. cp "${client_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  235. "${release_stage}/server/bin/"
  236. cp "${KUBE_ROOT}/Godeps/LICENSES" "${release_stage}/"
  237. cp "${RELEASE_TARS}/kubernetes-src.tar.gz" "${release_stage}/"
  238. kube::release::clean_cruft
  239. local package_name
  240. package_name="${RELEASE_TARS}/kubernetes-server-${platform_tag}.tar.gz"
  241. kube::release::create_tarball "${package_name}" "${release_stage}/.."
  242. done
  243. }
  244. function kube::release::md5() {
  245. if which md5 >/dev/null 2>&1; then
  246. md5 -q "$1"
  247. else
  248. md5sum "$1" | awk '{ print $1 }'
  249. fi
  250. }
  251. function kube::release::sha1() {
  252. if which sha1sum >/dev/null 2>&1; then
  253. sha1sum "$1" | awk '{ print $1 }'
  254. else
  255. shasum -a1 "$1" | awk '{ print $1 }'
  256. fi
  257. }
  258. function kube::release::build_hyperkube_image() {
  259. local -r arch="$1"
  260. local -r registry="$2"
  261. local -r version="$3"
  262. local -r save_dir="${4-}"
  263. kube::log::status "Building hyperkube image for arch: ${arch}"
  264. ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
  265. make -C cluster/images/hyperkube/ build >/dev/null
  266. local hyperkube_tag
  267. hyperkube_tag="${registry}/hyperkube-${arch}:${version}"
  268. if [[ -n "${save_dir}" ]]; then
  269. "${DOCKER[@]}" save "${hyperkube_tag}" > "${save_dir}/hyperkube-${arch}.tar"
  270. fi
  271. kube::log::status "Deleting hyperkube image ${hyperkube_tag}"
  272. "${DOCKER[@]}" rmi "${hyperkube_tag}" &>/dev/null || true
  273. }
  274. function kube::release::build_conformance_image() {
  275. local -r arch="$1"
  276. local -r registry="$2"
  277. local -r version="$3"
  278. local -r save_dir="${4-}"
  279. kube::log::status "Building conformance image for arch: ${arch}"
  280. ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
  281. make -C cluster/images/conformance/ build >/dev/null
  282. local conformance_tag
  283. conformance_tag="${registry}/conformance-${arch}:${version}"
  284. if [[ -n "${save_dir}" ]]; then
  285. "${DOCKER[@]}" save "${conformance_tag}" > "${save_dir}/conformance-${arch}.tar"
  286. fi
  287. kube::log::status "Deleting conformance image ${conformance_tag}"
  288. "${DOCKER[@]}" rmi "${conformance_tag}" &>/dev/null || true
  289. }
  290. # This builds all the release docker images (One docker image per binary)
  291. # Args:
  292. # $1 - binary_dir, the directory to save the tared images to.
  293. # $2 - arch, architecture for which we are building docker images.
  294. function kube::release::create_docker_images_for_server() {
  295. # Create a sub-shell so that we don't pollute the outer environment
  296. (
  297. local binary_dir
  298. local arch
  299. local binaries
  300. local images_dir
  301. binary_dir="$1"
  302. arch="$2"
  303. binaries=$(kube::build::get_docker_wrapped_binaries "${arch}")
  304. images_dir="${RELEASE_IMAGES}/${arch}"
  305. mkdir -p "${images_dir}"
  306. # k8s.gcr.io is the constant tag in the docker archives, this is also the default for config scripts in GKE.
  307. # We can use KUBE_DOCKER_REGISTRY to include and extra registry in the docker archive.
  308. # If we use KUBE_DOCKER_REGISTRY="k8s.gcr.io", then the extra tag (same) is ignored, see release_docker_image_tag below.
  309. local -r docker_registry="k8s.gcr.io"
  310. # Docker tags cannot contain '+'
  311. local docker_tag="${KUBE_GIT_VERSION/+/_}"
  312. if [[ -z "${docker_tag}" ]]; then
  313. kube::log::error "git version information missing; cannot create Docker tag"
  314. return 1
  315. fi
  316. # provide `--pull` argument to `docker build` if `KUBE_BUILD_PULL_LATEST_IMAGES`
  317. # is set to y or Y; otherwise try to build the image without forcefully
  318. # pulling the latest base image.
  319. local docker_build_opts
  320. docker_build_opts=
  321. if [[ "${KUBE_BUILD_PULL_LATEST_IMAGES}" =~ [yY] ]]; then
  322. docker_build_opts='--pull'
  323. fi
  324. for wrappable in $binaries; do
  325. local binary_name=${wrappable%%,*}
  326. local base_image=${wrappable##*,}
  327. local binary_file_path="${binary_dir}/${binary_name}"
  328. local docker_build_path="${binary_file_path}.dockerbuild"
  329. local docker_file_path="${docker_build_path}/Dockerfile"
  330. local docker_image_tag="${docker_registry}/${binary_name}-${arch}:${docker_tag}"
  331. kube::log::status "Starting docker build for image: ${binary_name}-${arch}"
  332. (
  333. rm -rf "${docker_build_path}"
  334. mkdir -p "${docker_build_path}"
  335. ln "${binary_file_path}" "${docker_build_path}/${binary_name}"
  336. ln "${KUBE_ROOT}/build/nsswitch.conf" "${docker_build_path}/nsswitch.conf"
  337. chmod 0644 "${docker_build_path}/nsswitch.conf"
  338. cat <<EOF > "${docker_file_path}"
  339. FROM ${base_image}
  340. COPY ${binary_name} /usr/local/bin/${binary_name}
  341. EOF
  342. # ensure /etc/nsswitch.conf exists so go's resolver respects /etc/hosts
  343. if [[ "${base_image}" =~ busybox ]]; then
  344. echo "COPY nsswitch.conf /etc/" >> "${docker_file_path}"
  345. fi
  346. "${DOCKER[@]}" build ${docker_build_opts:+"${docker_build_opts}"} -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null
  347. # If we are building an official/alpha/beta release we want to keep
  348. # docker images and tag them appropriately.
  349. local -r release_docker_image_tag="${KUBE_DOCKER_REGISTRY-$docker_registry}/${binary_name}-${arch}:${KUBE_DOCKER_IMAGE_TAG-$docker_tag}"
  350. if [[ "${release_docker_image_tag}" != "${docker_image_tag}" ]]; then
  351. kube::log::status "Tagging docker image ${docker_image_tag} as ${release_docker_image_tag}"
  352. "${DOCKER[@]}" rmi "${release_docker_image_tag}" 2>/dev/null || true
  353. "${DOCKER[@]}" tag "${docker_image_tag}" "${release_docker_image_tag}" 2>/dev/null
  354. fi
  355. "${DOCKER[@]}" save -o "${binary_file_path}.tar" "${docker_image_tag}" "${release_docker_image_tag}"
  356. echo "${docker_tag}" > "${binary_file_path}.docker_tag"
  357. rm -rf "${docker_build_path}"
  358. ln "${binary_file_path}.tar" "${images_dir}/"
  359. kube::log::status "Deleting docker image ${docker_image_tag}"
  360. "${DOCKER[@]}" rmi "${docker_image_tag}" &>/dev/null || true
  361. ) &
  362. done
  363. if [[ "${KUBE_BUILD_HYPERKUBE}" =~ [yY] ]]; then
  364. kube::release::build_hyperkube_image "${arch}" "${docker_registry}" \
  365. "${docker_tag}" "${images_dir}" &
  366. fi
  367. if [[ "${KUBE_BUILD_CONFORMANCE}" =~ [yY] ]]; then
  368. kube::release::build_conformance_image "${arch}" "${docker_registry}" \
  369. "${docker_tag}" "${images_dir}" &
  370. fi
  371. kube::util::wait-for-jobs || { kube::log::error "previous Docker build failed"; return 1; }
  372. kube::log::status "Docker builds done"
  373. )
  374. }
  375. # This will pack kube-system manifests files for distros such as COS.
  376. function kube::release::package_kube_manifests_tarball() {
  377. kube::log::status "Building tarball: manifests"
  378. local src_dir="${KUBE_ROOT}/cluster/gce/manifests"
  379. local release_stage="${RELEASE_STAGE}/manifests/kubernetes"
  380. rm -rf "${release_stage}"
  381. local dst_dir="${release_stage}/gci-trusty"
  382. mkdir -p "${dst_dir}"
  383. cp "${src_dir}/kube-proxy.manifest" "${dst_dir}/"
  384. cp "${src_dir}/cluster-autoscaler.manifest" "${dst_dir}/"
  385. cp "${src_dir}/etcd.manifest" "${dst_dir}"
  386. cp "${src_dir}/kube-scheduler.manifest" "${dst_dir}"
  387. cp "${src_dir}/kube-apiserver.manifest" "${dst_dir}"
  388. cp "${src_dir}/konnectivity-server.yaml" "${dst_dir}"
  389. cp "${src_dir}/abac-authz-policy.jsonl" "${dst_dir}"
  390. cp "${src_dir}/kube-controller-manager.manifest" "${dst_dir}"
  391. cp "${src_dir}/kube-addon-manager.yaml" "${dst_dir}"
  392. cp "${src_dir}/glbc.manifest" "${dst_dir}"
  393. cp "${src_dir}/etcd-empty-dir-cleanup.yaml" "${dst_dir}/"
  394. find "${src_dir}" -name 'internal-*' -exec cp {} "${dst_dir}" \;
  395. cp "${KUBE_ROOT}/cluster/gce/gci/configure-helper.sh" "${dst_dir}/gci-configure-helper.sh"
  396. cp "${KUBE_ROOT}/cluster/gce/gci/configure-kubeapiserver.sh" "${dst_dir}/configure-kubeapiserver.sh"
  397. if [[ -e "${KUBE_ROOT}/cluster/gce/gci/gke-internal-configure-helper.sh" ]]; then
  398. cp "${KUBE_ROOT}/cluster/gce/gci/gke-internal-configure-helper.sh" "${dst_dir}/"
  399. fi
  400. cp "${KUBE_ROOT}/cluster/gce/gci/health-monitor.sh" "${dst_dir}/health-monitor.sh"
  401. # Merge GCE-specific addons with general purpose addons.
  402. for d in cluster/addons cluster/gce/addons; do
  403. find "${KUBE_ROOT}/${d}" \( \( -name \*.yaml -o -name \*.yaml.in -o -name \*.json \) -a ! \( -name \*demo\* \) \) -print0 | tar c --transform "s|${KUBE_ROOT#/*}/${d}||" --null -T - | "${TAR}" x -C "${dst_dir}"
  404. done
  405. kube::release::clean_cruft
  406. local package_name="${RELEASE_TARS}/kubernetes-manifests.tar.gz"
  407. kube::release::create_tarball "${package_name}" "${release_stage}/.."
  408. }
  409. # Builds tarballs for each test platform containing the appropriate binaries.
  410. function kube::release::package_test_platform_tarballs() {
  411. local platform
  412. rm -rf "${RELEASE_STAGE}/test"
  413. # KUBE_TEST_SERVER_PLATFORMS is a subset of KUBE_TEST_PLATFORMS,
  414. # so process it first.
  415. for platform in "${KUBE_TEST_SERVER_PLATFORMS[@]}"; do
  416. local platform_tag=${platform/\//-} # Replace a "/" for a "-"
  417. local release_stage="${RELEASE_STAGE}/test/${platform_tag}/kubernetes"
  418. mkdir -p "${release_stage}/test/bin"
  419. # This fancy expression will expand to prepend a path
  420. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  421. # KUBE_TEST_SERVER_BINARIES array.
  422. cp "${KUBE_TEST_SERVER_BINARIES[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  423. "${release_stage}/test/bin/"
  424. done
  425. for platform in "${KUBE_TEST_PLATFORMS[@]}"; do
  426. (
  427. local platform_tag=${platform/\//-} # Replace a "/" for a "-"
  428. kube::log::status "Starting tarball: test $platform_tag"
  429. local release_stage="${RELEASE_STAGE}/test/${platform_tag}/kubernetes"
  430. mkdir -p "${release_stage}/test/bin"
  431. local test_bins=("${KUBE_TEST_BINARIES[@]}")
  432. if [[ "${platform%/*}" = 'windows' ]]; then
  433. test_bins=("${KUBE_TEST_BINARIES_WIN[@]}")
  434. fi
  435. # This fancy expression will expand to prepend a path
  436. # (${LOCAL_OUTPUT_BINPATH}/${platform}/) to every item in the
  437. # test_bins array.
  438. cp "${test_bins[@]/#/${LOCAL_OUTPUT_BINPATH}/${platform}/}" \
  439. "${release_stage}/test/bin/"
  440. local package_name="${RELEASE_TARS}/kubernetes-test-${platform_tag}.tar.gz"
  441. kube::release::create_tarball "${package_name}" "${release_stage}/.."
  442. ) &
  443. done
  444. kube::log::status "Waiting on test tarballs"
  445. kube::util::wait-for-jobs || { kube::log::error "test tarball creation failed"; exit 1; }
  446. }
  447. # This is the stuff you need to run tests from the binary distribution.
  448. function kube::release::package_test_tarballs() {
  449. kube::release::package_test_platform_tarballs
  450. kube::log::status "Building tarball: test portable"
  451. local release_stage="${RELEASE_STAGE}/test/kubernetes"
  452. rm -rf "${release_stage}"
  453. mkdir -p "${release_stage}"
  454. # First add test image files and other portable sources so we can create
  455. # the portable test tarball.
  456. mkdir -p "${release_stage}/test/images"
  457. cp -fR "${KUBE_ROOT}/test/images" "${release_stage}/test/"
  458. tar c "${KUBE_TEST_PORTABLE[@]}" | tar x -C "${release_stage}"
  459. kube::release::clean_cruft
  460. local portable_tarball_name="${RELEASE_TARS}/kubernetes-test-portable.tar.gz"
  461. kube::release::create_tarball "${portable_tarball_name}" "${release_stage}/.."
  462. }
  463. # This is all the platform-independent stuff you need to run/install kubernetes.
  464. # Arch-specific binaries will need to be downloaded separately (possibly by
  465. # using the bundled cluster/get-kube-binaries.sh script).
  466. # Included in this tarball:
  467. # - Cluster spin up/down scripts and configs for various cloud providers
  468. # - Tarballs for manifest configs that are ready to be uploaded
  469. # - Examples (which may or may not still work)
  470. # - The remnants of the docs/ directory
  471. function kube::release::package_final_tarball() {
  472. kube::log::status "Building tarball: final"
  473. # This isn't a "full" tarball anymore, but the release lib still expects
  474. # artifacts under "full/kubernetes/"
  475. local release_stage="${RELEASE_STAGE}/full/kubernetes"
  476. rm -rf "${release_stage}"
  477. mkdir -p "${release_stage}"
  478. mkdir -p "${release_stage}/client"
  479. cat <<EOF > "${release_stage}/client/README"
  480. Client binaries are no longer included in the Kubernetes final tarball.
  481. Run cluster/get-kube-binaries.sh to download client and server binaries.
  482. EOF
  483. # We want everything in /cluster.
  484. cp -R "${KUBE_ROOT}/cluster" "${release_stage}/"
  485. mkdir -p "${release_stage}/server"
  486. cp "${RELEASE_TARS}/kubernetes-manifests.tar.gz" "${release_stage}/server/"
  487. cat <<EOF > "${release_stage}/server/README"
  488. Server binary tarballs are no longer included in the Kubernetes final tarball.
  489. Run cluster/get-kube-binaries.sh to download client and server binaries.
  490. EOF
  491. # Include hack/lib as a dependency for the cluster/ scripts
  492. mkdir -p "${release_stage}/hack"
  493. cp -R "${KUBE_ROOT}/hack/lib" "${release_stage}/hack/"
  494. cp -R "${KUBE_ROOT}/docs" "${release_stage}/"
  495. cp "${KUBE_ROOT}/README.md" "${release_stage}/"
  496. cp "${KUBE_ROOT}/Godeps/LICENSES" "${release_stage}/"
  497. echo "${KUBE_GIT_VERSION}" > "${release_stage}/version"
  498. kube::release::clean_cruft
  499. local package_name="${RELEASE_TARS}/kubernetes.tar.gz"
  500. kube::release::create_tarball "${package_name}" "${release_stage}/.."
  501. }
  502. # Build a release tarball. $1 is the output tar name. $2 is the base directory
  503. # of the files to be packaged. This assumes that ${2}/kubernetes is what is
  504. # being packaged.
  505. function kube::release::create_tarball() {
  506. kube::build::ensure_tar
  507. local tarfile=$1
  508. local stagingdir=$2
  509. "${TAR}" czf "${tarfile}" -C "${stagingdir}" kubernetes --owner=0 --group=0
  510. }