🚀 Support Git-backed Kaniko build contexts

This commit is contained in:
eust-w 2026-08-18 22:03:23 +08:00
parent e16f061f72
commit cdd8be0678

View File

@ -30,6 +30,7 @@ POC_KANIKO_WAIT_TIMEOUT="${POC_KANIKO_WAIT_TIMEOUT:-1200s}"
POC_KANIKO_GOPROXY="${POC_KANIKO_GOPROXY:-}"
POC_KANIKO_CONTEXT_SOURCE="${POC_KANIKO_CONTEXT_SOURCE:-worktree}"
POC_KANIKO_CONTEXT_POD="${POC_KANIKO_CONTEXT_POD:-}"
POC_KANIKO_GIT_CONTEXT="${POC_KANIKO_GIT_CONTEXT:-}"
POC_KANIKO_NODE_NAME="${POC_KANIKO_NODE_NAME:-}"
POC_KANIKO_BUILD_OPERATORS="${POC_KANIKO_BUILD_OPERATORS:-false}"
POC_KANIKO_BUILD_OPERATOR_BASES="${POC_KANIKO_BUILD_OPERATOR_BASES:-true}"
@ -86,13 +87,19 @@ validate_boolean POC_KANIKO_CLEAN_CONTEXT "$POC_KANIKO_CLEAN_CONTEXT"
validate_boolean POC_KANIKO_BUILD_OPERATORS "$POC_KANIKO_BUILD_OPERATORS"
validate_boolean POC_KANIKO_BUILD_OPERATOR_BASES "$POC_KANIKO_BUILD_OPERATOR_BASES"
case "$POC_KANIKO_CONTEXT_SOURCE" in
worktree|head)
worktree|head|git)
;;
*)
echo "ERROR: POC_KANIKO_CONTEXT_SOURCE must be worktree or head." >&2
echo "ERROR: POC_KANIKO_CONTEXT_SOURCE must be worktree, head, or git." >&2
exit 1
;;
esac
if [[ "$POC_KANIKO_CONTEXT_SOURCE" == "git" ]]; then
if [[ -z "$POC_KANIKO_GIT_CONTEXT" || "$POC_KANIKO_GIT_CONTEXT" != git://* || "$POC_KANIKO_GIT_CONTEXT" =~ [[:space:]] ]]; then
echo "ERROR: POC_KANIKO_GIT_CONTEXT must be a whitespace-free git:// context when POC_KANIKO_CONTEXT_SOURCE=git." >&2
exit 1
fi
fi
if [[ "$POC_KANIKO_GOPROXY" =~ [[:space:]] ]]; then
echo "ERROR: POC_KANIKO_GOPROXY must not contain whitespace." >&2
exit 1
@ -174,9 +181,15 @@ kaniko_args_yaml() {
local destination="$1"
local dockerfile="$2"
local mirror
local context_value="dir://${CONTEXT_DIR}"
local dockerfile_value="${CONTEXT_DIR}/${dockerfile}"
if [[ "$POC_KANIKO_CONTEXT_SOURCE" == "git" ]]; then
context_value="$POC_KANIKO_GIT_CONTEXT"
dockerfile_value="$dockerfile"
fi
cat <<YAML
- --context=dir://${CONTEXT_DIR}
- --dockerfile=${CONTEXT_DIR}/${dockerfile}
- --context=${context_value}
- --dockerfile=${dockerfile_value}
- --destination=${destination}
YAML
if [[ -n "$POC_KANIKO_GOPROXY" ]]; then
@ -443,23 +456,25 @@ cleanup_context() {
}
trap cleanup_context EXIT
api_pod="$POC_KANIKO_CONTEXT_POD"
if [[ -z "$api_pod" ]]; then
api_pod="$(kubectl -n "$K8S_NAMESPACE" get pod -l app=droboticflow-api --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')"
fi
if [[ -z "$api_pod" ]]; then
echo "ERROR: no droboticflow-api pod is available for uploading the build context." >&2
exit 1
fi
if ! kubectl -n "$K8S_NAMESPACE" get pod "$api_pod" >/dev/null 2>&1; then
echo "ERROR: POC_KANIKO_CONTEXT_POD does not reference an available pod: $api_pod" >&2
exit 1
fi
if [[ "$POC_KANIKO_CONTEXT_SOURCE" != "git" ]]; then
api_pod="$POC_KANIKO_CONTEXT_POD"
if [[ -z "$api_pod" ]]; then
api_pod="$(kubectl -n "$K8S_NAMESPACE" get pod -l app=droboticflow-api --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')"
fi
if [[ -z "$api_pod" ]]; then
echo "ERROR: no droboticflow-api pod is available for uploading the build context." >&2
exit 1
fi
if ! kubectl -n "$K8S_NAMESPACE" get pod "$api_pod" >/dev/null 2>&1; then
echo "ERROR: POC_KANIKO_CONTEXT_POD does not reference an available pod: $api_pod" >&2
exit 1
fi
context_json="$(json_string "$CONTEXT_DIR")"
kubectl -n "$K8S_NAMESPACE" exec "$api_pod" -- sh -lc "rm -rf $context_json && mkdir -p $context_json"
context_uploaded=true
upload_build_context | kubectl -n "$K8S_NAMESPACE" exec -i "$api_pod" -- tar -xf - -C "$CONTEXT_DIR"
context_json="$(json_string "$CONTEXT_DIR")"
kubectl -n "$K8S_NAMESPACE" exec "$api_pod" -- sh -lc "rm -rf $context_json && mkdir -p $context_json"
context_uploaded=true
upload_build_context | kubectl -n "$K8S_NAMESPACE" exec -i "$api_pod" -- tar -xf - -C "$CONTEXT_DIR"
fi
operator_components=()
operator_specs=()