diff --git a/scripts/build-poc-images-kaniko.sh b/scripts/build-poc-images-kaniko.sh index 16c0f05b..86dae230 100755 --- a/scripts/build-poc-images-kaniko.sh +++ b/scripts/build-poc-images-kaniko.sh @@ -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 <&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=()