build by running kube-cross directly

eliminate rsync dance, data container, and building a build image every time
This commit is contained in:
Benjamin Elder committed 2025-10-13 09:47:21 -07:00
1 parent 095b9d6045
commit 581012fe06
2 files changed
+33 -15

No files matched your search

+28 -3
View File
@@ -425,6 +425,8 @@ function kube::build::clean() {
# Set up the context directory for the kube-build image and build it.
function kube::build::build_image() {
# TODO: eliminate this entirely in favor of just docker run kube-cross
return
mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}"
# Make sure the context directory owned by the right user for syncing sources to container.
chown -R "${USER_ID}":"${GROUP_ID}" "${LOCAL_OUTPUT_BUILD_CONTEXT}"
@@ -483,6 +485,8 @@ EOF
}
function kube::build::ensure_data_container() {
# TODO: eliminate this, we mount to the build container instead now
return
# If the data container exists AND exited successfully, we can use it.
# Otherwise nuke it and start over.
local ret=0
@@ -510,7 +514,8 @@ function kube::build::ensure_data_container() {
# libraries for true static building.
local -ra docker_cmd=(
"${DOCKER[@]}" run
--volume "${REMOTE_ROOT}" # white-out the whole output dir
--volume "${KUBE_ROOT}/:/k8s/"
#--volume "${REMOTE_ROOT}" # white-out the whole output dir
--volume /usr/local/go/pkg/linux_386_cgo
--volume /usr/local/go/pkg/linux_amd64_cgo
--volume /usr/local/go/pkg/linux_arm_cgo
@@ -553,7 +558,7 @@ function kube::build::run_build_command_ex() {
"--user=$(id -u):$(id -g)"
"--hostname=${HOSTNAME}"
"-e=GOPROXY=${GOPROXY}"
"${DOCKER_MOUNT_ARGS[@]}"
#"${DOCKER_MOUNT_ARGS[@]}"
)
local detach=false
@@ -595,8 +600,22 @@ function kube::build::run_build_command_ex() {
--env "GOFLAGS=${GOFLAGS:-}"
--env "GOGCFLAGS=${GOGCFLAGS:-}"
--env "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-}"
# mount source code / output dir
--volume "${KUBE_ROOT}:/go/src/k8s.io/kubernetes"
# env migrated from build-image, we could consider setting this in kube-cross
--env 'KUBE_OUTPUT_SUBPATH=_output/dockerized'
--workdir /go/src/k8s.io/kubernetes
--env 'GIT_AUTHOR_EMAIL=nobody@k8s.io'
--env 'GIT_AUTHOR_NAME=kube-build-image'
)
# if host has localtime, mount it so we log in local time
if [ -f /etc/localtime ]; then
docker_run_opts+=(
--mount 'type=bind,source=/etc/localtime,target=/etc/localtime'
)
fi
# use GOLDFLAGS only if it is set explicitly.
if [[ -v GOLDFLAGS ]]; then
docker_run_opts+=(
@@ -620,7 +639,7 @@ function kube::build::run_build_command_ex() {
fi
local -ra docker_cmd=(
"${DOCKER[@]}" run "${docker_run_opts[@]}" "${KUBE_BUILD_IMAGE}")
"${DOCKER[@]}" run "${docker_run_opts[@]}" "${KUBE_CROSS_IMAGE}:${KUBE_CROSS_VERSION}")
# Clean up container from any previous run
kube::build::destroy_container "${container_name}"
@@ -713,6 +732,9 @@ function kube::build::rsync {
# 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() {
# TODO: eliminate calls to this
# for now making sure it doesn't run, so we can just use the volume mount
return
kube::log::status "Syncing sources to container"
kube::build::start_rsyncd_container
@@ -740,6 +762,9 @@ function kube::build::sync_to_container() {
# Copy all build results back out.
function kube::build::copy_output() {
# TODO eliminate calls to this
# For now just returning early
return
kube::log::status "Syncing out of container"
kube::build::start_rsyncd_container
+5 -12
View File
@@ -25,19 +25,12 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "$KUBE_ROOT/build/common.sh"
# This is no longer supported, warn if set to non-default value
KUBE_RUN_COPY_OUTPUT="${KUBE_RUN_COPY_OUTPUT:-y}"
# we previously accepted an explicit both y and Y
if [[ ! "${KUBE_RUN_COPY_OUTPUT}" =~ ^[yY]$ ]]; then
kube::log::error "KUBE_RUN_COPY_OUTPUT no longer means anything as we bind-mount instead of rsyncing, so output is always persisted"
fi
kube::build::verify_prereqs
kube::build::build_image
if [[ ${KUBE_RUN_COPY_OUTPUT} =~ ^[yY]$ ]]; then
kube::log::status "Output from this container will be rsynced out upon completion. Set KUBE_RUN_COPY_OUTPUT=n to disable."
else
kube::log::status "Output from this container will NOT be rsynced out upon completion. Set KUBE_RUN_COPY_OUTPUT=y to enable."
fi
kube::build::run_build_command "$@"
if [[ ${KUBE_RUN_COPY_OUTPUT} =~ ^[yY]$ ]]; then
kube::build::copy_output
fi