From 2256b27f95663b7a31bc4ea0300504d443ce5d38 Mon Sep 17 00:00:00 2001 From: Ivan Shvedunov Date: Wed, 23 Nov 2016 05:40:39 +0300 Subject: [PATCH] Add options for build container rsync optimization KUBE_RSYNC_COMPRESS env var sets rsync compression level. KUBE_RSYNC_GENERATED_TO_BUILD_CONTAINER env var disables rsyncing generated files to build containers. --- build-tools/common.sh | 42 +++++++++++++++++++++++++----------------- hack/lib/init.sh | 4 ++++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/build-tools/common.sh b/build-tools/common.sh index 2774ea3911a3..70fd9de3f981 100755 --- a/build-tools/common.sh +++ b/build-tools/common.sh @@ -643,6 +643,22 @@ function kube::build::stop_rsyncd_container() { kube::build::destroy_container "${KUBE_RSYNC_CONTAINER_NAME}" } +function kube::build::rsync { + local -a rsync_opts=( + --archive + --prune-empty-dirs + --password-file="${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password" + ) + if (( ${KUBE_VERBOSE} >= 6 )); then + rsync_opts+=("-iv") + fi + if (( ${KUBE_RSYNC_COMPRESS} > 0 )); then + rsync_opts+=("--compress-level=${KUBE_RSYNC_COMPRESS}") + fi + V=3 kube::log::status "Running rsync" + rsync "${rsync_opts[@]}" "$@" +} + # This will launch rsyncd in a container and then sync the source tree to the # container over the local network. function kube::build::sync_to_container() { @@ -650,26 +666,22 @@ function kube::build::sync_to_container() { kube::build::start_rsyncd_container - local rsync_extra="" - if (( ${KUBE_VERBOSE} >= 6 )); then - rsync_extra="-iv" - fi - # rsync filters are a bit confusing. Here we are syncing everything except # output only directories and things that are not necessary like the git - # directory. The '- /' filter prevents rsync from trying to set the - # uid/gid/perms on the root of the sync tree. - V=3 kube::log::status "Running rsync" - rsync ${rsync_extra} \ - --archive \ + # directory and generated files. The '- /' filter prevents rsync + # from trying to set the uid/gid/perms on the root of the sync tree. + # As an exception, we need to sync generated files in staging/, because + # they will not be re-generated by 'make'. + kube::build::rsync \ --delete \ - --prune-empty-dirs \ - --password-file="${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password" \ + --filter='+ /staging/**' \ --filter='- /.git/' \ --filter='- /.make/' \ --filter='- /_tmp/' \ --filter='- /_output/' \ --filter='- /' \ + --filter='- zz_generated.*' \ + --filter='- generated.proto' \ "${KUBE_ROOT}/" "rsync://k8s@${KUBE_RSYNC_ADDR}/k8s/" kube::build::stop_rsyncd_container @@ -694,11 +706,7 @@ function kube::build::copy_output() { # # We are looking to copy out all of the built binaries along with various # generated files. - V=3 kube::log::status "Running rsync" - rsync ${rsync_extra} \ - --archive \ - --prune-empty-dirs \ - --password-file="${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password" \ + kube::build::rsync \ --filter='- /vendor/' \ --filter='- /_temp/' \ --filter='+ /_output/dockerized/bin/**' \ diff --git a/hack/lib/init.sh b/hack/lib/init.sh index ae50779e2786..64a8c1bf9573 100644 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -25,6 +25,10 @@ KUBE_OUTPUT_SUBPATH="${KUBE_OUTPUT_SUBPATH:-_output/local}" KUBE_OUTPUT="${KUBE_ROOT}/${KUBE_OUTPUT_SUBPATH}" KUBE_OUTPUT_BINPATH="${KUBE_OUTPUT}/bin" +# This controls rsync compression. Set to a value > 0 to enable rsync +# compression for build container +KUBE_RSYNC_COMPRESS="${KUBE_RSYNC_COMPRESS:-0}" + # Set no_proxy for localhost if behind a proxy, otherwise, # the connections to localhost in scripts will time out export no_proxy=127.0.0.1,localhost