Skip to content

Commit 8d8cf0b

Browse files
committed
Refactor Kubeflow components to use reference instead of uri
Update component inputs, outputs, and scripts to use reference instead of uri for OCI alignment. Also remove redundant CI triggers and dependencies. Signed-off-by: Gorkem Ercan <gorkem.ercan@gmail.com>
1 parent 5e0e521 commit 8d8cf0b

10 files changed

Lines changed: 60 additions & 84 deletions

File tree

.github/workflows/kubeflow-components-test.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ on:
55
paths:
66
- 'build/dockerfiles/kubeflow-components/**'
77
- '.github/workflows/kubeflow-components-test.yaml'
8-
push:
9-
branches:
10-
- main
11-
paths:
12-
- 'build/dockerfiles/kubeflow-components/**'
13-
- '.github/workflows/kubeflow-components-test.yaml'
148

159
jobs:
1610
test-scripts:
@@ -25,10 +19,6 @@ jobs:
2519
sudo apt-get update
2620
sudo apt-get install -y bats
2721
28-
- name: Install jq
29-
run: |
30-
sudo apt-get install -y jq
31-
3222
- name: Run push-modelkit tests
3323
working-directory: build/dockerfiles/kubeflow-components
3424
run: bats tests/push-modelkit.bats

build/dockerfiles/kubeflow-components/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ If a `Kitfile` exists in `modelkit_dir`, it is used as-is. Otherwise, one is aut
3131

3232
**Outputs**
3333

34-
- `uri` – Tagged ModelKit URI (e.g., `registry.io/myorg/mymodel:v1`)
35-
- `digest` – Digest-based ModelKit URI (e.g., `registry.io/myorg/mymodel@sha256:abc…`)
34+
- `ref` – Tagged ModelKit reference (e.g., `registry.io/myorg/mymodel:v1`)
35+
- `digest` – Digest-based ModelKit reference (e.g., `registry.io/myorg/mymodel@sha256:abc…`)
3636

3737
### unpack-modelkit
3838

3939
Pulls a ModelKit from a registry and extracts it.
4040

4141
**Inputs**
4242

43-
- `modelkit_uri` – ModelKit reference (e.g., `registry.io/repo:tag` or `registry.io/repo@sha256:…`)
43+
- `modelkit_reference` – ModelKit reference (e.g., `registry.io/repo:tag` or `registry.io/repo@sha256:…`)
4444
- `extract_path` – Directory to extract contents (default: `/tmp/model`)
4545

4646
**Outputs**
@@ -89,7 +89,7 @@ def push_modelkit(
8989
repository: str,
9090
tag: str,
9191
input_modelkit_dir: dsl.Input[dsl.Artifact],
92-
output_uri: dsl.Output[dsl.Artifact],
92+
output_ref: dsl.Output[dsl.Artifact],
9393
output_digest: dsl.Output[dsl.Artifact],
9494
modelkit_name: str = '',
9595
modelkit_desc: str = '',
@@ -111,7 +111,7 @@ def push_modelkit(
111111
f'--dataset-uri "{dataset_uri}" '
112112
f'--code-repo "{code_repo}" '
113113
f'--code-commit "{code_commit}" '
114-
f'&& cp /tmp/outputs/uri "{output_uri.path}" '
114+
f'&& cp /tmp/outputs/reference "{output_ref.path}" '
115115
f'&& cp /tmp/outputs/digest "{output_digest.path}"'
116116
],
117117
)

build/dockerfiles/kubeflow-components/components/push-modelkit/component.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ inputs:
1717
- {name: code_commit, type: String, optional: true, description: 'Code commit hash'}
1818

1919
outputs:
20-
- {name: uri, type: String, description: 'Tagged ModelKit URI (e.g., registry.io/repo:tag)'}
21-
- {name: digest, type: String, description: 'Digest-based ModelKit URI (e.g., registry.io/repo@sha256:...)'}
20+
- {name: ref, type: String, description: 'Tagged ModelKit reference (e.g., registry.io/repo:tag)'}
21+
- {name: digest, type: String, description: 'Digest-based ModelKit reference(e.g., registry.io/repo@sha256:...)'}
2222

2323
implementation:
2424
container:
@@ -47,5 +47,5 @@ implementation:
4747
- {inputValue: code_repo}
4848
- {inputValue: code_commit}
4949
fileOutputs:
50-
uri: /tmp/outputs/uri
50+
ref: /tmp/outputs/reference
5151
digest: /tmp/outputs/digest

build/dockerfiles/kubeflow-components/components/unpack-modelkit/component.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: unpack-modelkit
22
description: Unpack ModelKit artifacts from a registry
33

44
inputs:
5-
- {name: modelkit_uri, type: String, description: 'ModelKit reference (e.g., registry.io/repo:tag or registry.io/repo@sha256:...)'}
5+
- {name: modelkit_reference, type: String, description: 'ModelKit reference (e.g., registry.io/repo:tag or registry.io/repo@sha256:...)'}
66
- {name: extract_path, type: String, default: '/tmp/model', description: 'Directory to extract ModelKit artifacts'}
77

88
outputs:
@@ -14,7 +14,7 @@ implementation:
1414
command:
1515
- /bin/bash
1616
- /scripts/unpack-modelkit.sh
17-
- {inputValue: modelkit_uri}
17+
- {inputValue: modelkit_reference}
1818
- {inputValue: extract_path}
1919
fileOutputs:
2020
model_path: /tmp/outputs/model_path

build/dockerfiles/kubeflow-components/examples/house-prices-pipeline.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def push_modelkit(
114114
registry: str,
115115
repository: str,
116116
tag: str,
117-
output_uri: dsl.Output[dsl.Artifact],
117+
output_ref: dsl.Output[dsl.Artifact],
118118
output_digest: dsl.Output[dsl.Artifact],
119119
input_modelkit_dir: dsl.Input[dsl.Artifact],
120120
modelkit_name: str = '',
@@ -127,8 +127,8 @@ def push_modelkit(
127127
"""Package and push model as ModelKit with attestation.
128128
129129
Outputs:
130-
output_uri: Tagged URI (e.g., jozu.ml/repo:tag)
131-
output_digest: Digest URI (e.g., jozu.ml/repo@sha256:...)
130+
output_ref: Tagged reference (e.g., jozu.ml/repo:tag)
131+
output_digest: Digest reference (e.g., jozu.ml/repo@sha256:...)
132132
"""
133133
# Build command using safe argument passing
134134
return dsl.ContainerSpec(
@@ -146,7 +146,7 @@ def push_modelkit(
146146
${7:+--dataset-uri "$7"} \
147147
${8:+--code-repo "$8"} \
148148
${9:+--code-commit "$9"} \
149-
&& cp /tmp/outputs/uri "${10}" \
149+
&& cp /tmp/outputs/reference "${10}" \
150150
&& cp /tmp/outputs/digest "${11}"
151151
''',
152152
registry,
@@ -159,7 +159,7 @@ def push_modelkit(
159159
dataset_uri,
160160
code_repo,
161161
code_commit,
162-
output_uri.path,
162+
output_ref.path,
163163
output_digest.path
164164
]
165165
)

build/dockerfiles/kubeflow-components/scripts/lib/common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ die() {
6969

7070
# Retry logic
7171
retry() {
72-
local max_attempts=${1:-3}
73-
local delay=${2:-2}
72+
local max_attempts=$1
73+
local delay=$2
7474
shift 2
7575
local attempt=1
7676

build/dockerfiles/kubeflow-components/scripts/push-modelkit.sh

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ if [ ! -d "$MODELKIT_DIR" ]; then
9191
die "ModelKit directory not found: $MODELKIT_DIR"
9292
fi
9393

94-
# Construct ModelKit URI
95-
MODELKIT_URI="${REGISTRY}/${REPOSITORY}:${TAG}"
94+
# Construct ModelKit reference
95+
MODELKIT_REF="${REGISTRY}/${REPOSITORY}:${TAG}"
9696

97-
log_info "Starting ModelKit push" "{\"uri\":\"$MODELKIT_URI\"}"
97+
log_info "Starting ModelKit push" "{\"reference\":\"$MODELKIT_REF\"}"
9898

9999
require_cmd kit cosign jq
100-
require_env DOCKER_CONFIG
101100

102101
# Disable kit update notifications
103102
kit version --show-update-notifications=false >/dev/null 2>&1 || true
@@ -126,47 +125,41 @@ fi
126125

127126
# Pack the ModelKit
128127
log_info "Packing ModelKit artifacts"
129-
kit pack "$WORK_DIR" -t "$MODELKIT_URI" || die "Failed to pack ModelKit"
128+
kit pack "$WORK_DIR" -t "$MODELKIT_REF" || die "Failed to pack ModelKit"
130129

131130
# Push to registry with retry
132131
log_info "Pushing to registry"
133-
retry 3 2 kit push "$MODELKIT_URI" || die "Failed to push ModelKit"
132+
retry 3 2 kit push "$MODELKIT_REF" || die "Failed to push ModelKit"
134133

135-
# Extract digest from kit inspect
136-
log_debug "Extracting digest"
137-
MODELKIT_DIGEST=$(echo "$MODELKIT_URI" | grep -oE '@sha256:[a-f0-9]+' | sed 's/@sha256://' || echo "")
134+
# Fetch digest from registry
135+
log_debug "Fetching digest from registry"
138136

139-
if [ -z "$MODELKIT_DIGEST" ]; then
140-
log_debug "No digest in URI, fetching from registry"
141-
142-
set +e
143-
INSPECT_OUTPUT=$(kit inspect "$MODELKIT_URI" --remote 2>&1)
144-
INSPECT_EXIT_CODE=$?
145-
set -e
137+
set +e
138+
INSPECT_OUTPUT=$(kit inspect "$MODELKIT_REF" --remote 2>&1)
139+
INSPECT_EXIT_CODE=$?
140+
set -e
146141

147-
log_debug "Kit inspect completed" "{\"exit_code\":$INSPECT_EXIT_CODE}"
142+
log_debug "Kit inspect completed" "{\"exit_code\":$INSPECT_EXIT_CODE}"
148143

149-
if [ $INSPECT_EXIT_CODE -eq 0 ]; then
150-
# Extract digest from JSON output, filtering out any log lines
151-
MODELKIT_DIGEST=$(echo "$INSPECT_OUTPUT" | grep -v '^{"timestamp"' | jq -r '.digest' 2>/dev/null | sed 's/sha256://' || echo "")
152-
fi
144+
if [ $INSPECT_EXIT_CODE -eq 0 ]; then
145+
MODELKIT_DIGEST=$(echo "$INSPECT_OUTPUT" | jq -r '.digest' 2>/dev/null || echo "")
146+
fi
153147

154-
if [ -z "$MODELKIT_DIGEST" ]; then
155-
die "Could not determine ModelKit digest" "{\"reference\":\"$MODELKIT_URI\",\"exit_code\":$INSPECT_EXIT_CODE}"
156-
fi
148+
if [ -z "$MODELKIT_DIGEST" ]; then
149+
die "Could not determine ModelKit digest" "{\"reference\":\"$MODELKIT_REF\",\"exit_code\":$INSPECT_EXIT_CODE}"
157150
fi
158151

159152
log_debug "ModelKit digest: $MODELKIT_DIGEST"
160153

161-
# Construct full URI with digest
162-
FULL_URI="${REGISTRY}/${REPOSITORY}@sha256:${MODELKIT_DIGEST}"
154+
# Construct full reference with digest
155+
FULL_REF="${REGISTRY}/${REPOSITORY}@${MODELKIT_DIGEST}"
163156

164-
log_info "Push completed" "{\"uri\":\"$FULL_URI\"}"
157+
log_info "Push completed" "{\"reference\":\"$FULL_REF\"}"
165158

166159
# Create in-toto attestation predicate
167160
ATTESTATION_PREDICATE=$(jq -nc \
168-
--arg uri "$FULL_URI" \
169-
--arg digest "sha256:$MODELKIT_DIGEST" \
161+
--arg reference "$FULL_REF" \
162+
--arg digest "$MODELKIT_DIGEST" \
170163
--arg dataset_uri "$DATASET_URI" \
171164
--arg code_repo "$CODE_REPO" \
172165
--arg code_commit "$CODE_COMMIT" \
@@ -175,7 +168,7 @@ ATTESTATION_PREDICATE=$(jq -nc \
175168
predicateType: "https://kitops.ml/attestation/v1",
176169
predicate: {
177170
modelkit: {
178-
uri: $uri,
171+
reference: $reference,
179172
digest: $digest
180173
},
181174
metadata: {
@@ -201,7 +194,7 @@ if [ -f "/etc/cosign/cosign.key" ]; then
201194
--predicate "$PREDICATE_FILE" \
202195
--tlog-upload=false \
203196
--yes \
204-
"$FULL_URI" 2>&1; then
197+
"$FULL_REF" 2>&1; then
205198
log_info "Signed with cosign"
206199
else
207200
log_warn "Failed to sign with cosign, continuing"
@@ -214,16 +207,16 @@ fi
214207

215208
# Output results
216209
# Write to KFP output files
217-
echo -n "$MODELKIT_URI" > /tmp/outputs/uri # Tagged URI (e.g., jozu.ml/repo:tag)
218-
echo -n "$FULL_URI" > /tmp/outputs/digest # Digest URI (e.g., jozu.ml/repo@sha256:...)
210+
echo -n "$MODELKIT_REF" > /tmp/outputs/reference # Tagged reference (e.g., jozu.ml/repo:tag)
211+
echo -n "$FULL_REF" > /tmp/outputs/digest # Digest reference (e.g., jozu.ml/repo@sha256:...)
219212

220213
# Output JSON to stdout
221214
jq -n \
222-
--arg uri "$FULL_URI" \
223-
--arg digest "sha256:$MODELKIT_DIGEST" \
215+
--arg reference "$FULL_REF" \
216+
--arg digest "$MODELKIT_DIGEST" \
224217
--arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
225218
'{
226-
"uri": $uri,
219+
"reference": $reference,
227220
"digest": $digest,
228221
"timestamp": $timestamp,
229222
"status": "success"

build/dockerfiles/kubeflow-components/scripts/unpack-modelkit.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
# Usage: /scripts/unpack-modelkit.sh <modelkit_uri> [extract_path]
4+
# Usage: /scripts/unpack-modelkit.sh <modelkit_reference> [extract_path]
55
# Environment variables: `DOCKER_CONFIG` (path to .docker directory containing config.json)
66
# Unpacks ModelKit artifacts to a directory
77

@@ -10,13 +10,13 @@ source "${SCRIPT_DIR}/lib/common.sh"
1010

1111
# Validate arguments
1212
if [ $# -lt 1 ]; then
13-
die "Usage: $0 <modelkit_uri> [extract_path]"
13+
die "Usage: $0 <modelkit_reference> [extract_path]"
1414
fi
1515

16-
MODELKIT_URI="$1"
16+
MODELKIT_REF="$1"
1717
EXTRACT_PATH="${2:-/tmp/model}"
1818

19-
log_info "Starting unpack" "{\"modelkit_uri\":\"$MODELKIT_URI\",\"extract_path\":\"$EXTRACT_PATH\"}"
19+
log_info "Starting unpack" "{\"modelkit_reference\":\"$MODELKIT_REF\",\"extract_path\":\"$EXTRACT_PATH\"}"
2020

2121
require_cmd kit jq
2222
require_env DOCKER_CONFIG
@@ -30,7 +30,7 @@ mkdir -p "$EXTRACT_PATH"
3030

3131
# Step 1: Unpack ModelKit with retry
3232
log_info "Unpacking"
33-
retry 3 2 kit unpack "$MODELKIT_URI" -d "$EXTRACT_PATH" || die "Failed to unpack ModelKit"
33+
retry 3 2 kit unpack "$MODELKIT_REF" -d "$EXTRACT_PATH" || die "Failed to unpack ModelKit"
3434

3535
log_info "Unpacked successfully" "{\"path\":\"$EXTRACT_PATH\"}"
3636

@@ -41,11 +41,11 @@ echo -n "$EXTRACT_PATH" > /tmp/outputs/model_path
4141
# Output JSON to stdout
4242
jq -n \
4343
--arg path "$EXTRACT_PATH" \
44-
--arg uri "$MODELKIT_URI" \
44+
--arg reference "$MODELKIT_REF" \
4545
--arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
4646
'{
4747
"model_path": $path,
48-
"modelkit_uri": $uri,
48+
"modelkit_reference": $reference,
4949
"timestamp": $timestamp,
5050
"status": "success"
5151
}'

build/dockerfiles/kubeflow-components/tests/push-modelkit.bats

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,18 @@ EOF
239239
@test "creates output files in /tmp/outputs" {
240240
run bash "$SCRIPT_PATH" "registry.io" "myorg/mymodel" "v1" --modelkit-dir "$MODEL_DIR"
241241
[ "$status" -eq 0 ]
242-
[ -f "$OUTPUT_DIR/uri" ]
242+
[ -f "$OUTPUT_DIR/reference" ]
243243
[ -f "$OUTPUT_DIR/digest" ]
244244
}
245245

246246
@test "output files contain correct values" {
247247
run bash "$SCRIPT_PATH" "registry.io" "myorg/mymodel" "v1" --modelkit-dir "$MODEL_DIR"
248248
[ "$status" -eq 0 ]
249249

250-
uri_content=$(cat "$OUTPUT_DIR/uri")
250+
ref_content=$(cat "$OUTPUT_DIR/reference")
251251
digest_content=$(cat "$OUTPUT_DIR/digest")
252252

253-
[[ "$uri_content" == "registry.io/myorg/mymodel:v1" ]]
253+
[[ "$ref_content" == "registry.io/myorg/mymodel:v1" ]]
254254
[[ "$digest_content" =~ registry.io/myorg/mymodel@sha256:abc123def456 ]]
255255
}
256256

@@ -260,7 +260,7 @@ EOF
260260

261261
# Extract final JSON output
262262
json_output=$(echo "$output" | awk '/^{$/,/^}$/' | jq -s '.[] | select(.status != null)')
263-
echo "$json_output" | jq -e '.uri'
263+
echo "$json_output" | jq -e '.reference'
264264
echo "$json_output" | jq -e '.digest'
265265
echo "$json_output" | jq -e '.status == "success"'
266266
}
@@ -303,13 +303,6 @@ EOF
303303
[[ "$output" =~ "Required command not found: kit" ]]
304304
}
305305

306-
@test "fails when DOCKER_CONFIG not set" {
307-
unset DOCKER_CONFIG
308-
run bash "$SCRIPT_PATH" "registry.io" "myorg/mymodel" "v1" --modelkit-dir "$MODEL_DIR"
309-
[ "$status" -eq 1 ]
310-
[[ "$output" =~ "Required environment variable not set: DOCKER_CONFIG" ]]
311-
}
312-
313306
@test "retries on push failure and eventually fails" {
314307
# Replace kit with failing version
315308
mv "$TEST_DIR/bin/kit" "$TEST_DIR/bin/kit.bak"

build/dockerfiles/kubeflow-components/tests/unpack-modelkit.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ teardown() {
9696
run bash "$SCRIPT_PATH"
9797
[ "$status" -eq 1 ]
9898
[[ "$output" =~ "Usage:" ]]
99-
[[ "$output" =~ "modelkit_uri" ]]
99+
[[ "$output" =~ "modelkit_reference" ]]
100100
}
101101

102-
@test "succeeds with only modelkit_uri (uses default extract path)" {
102+
@test "succeeds with only modelkit_reference (uses default extract path)" {
103103
run bash "$SCRIPT_PATH" "registry.io/myorg/mymodel:v1"
104104
[ "$status" -eq 0 ]
105105
[[ "$output" =~ "Unpack workflow completed" ]]
@@ -136,7 +136,7 @@ teardown() {
136136
# Extract final JSON output (the one with "status" field)
137137
json_output=$(echo "$output" | awk '/^{$/,/^}$/' | jq -s '.[] | select(.status != null)')
138138
echo "$json_output" | jq -e '.model_path'
139-
echo "$json_output" | jq -e '.modelkit_uri'
139+
echo "$json_output" | jq -e '.modelkit_reference'
140140
echo "$json_output" | jq -e '.status == "success"'
141141
}
142142

0 commit comments

Comments
 (0)