release.sh 26 KB

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