service: publish relative harbor artifact paths

This commit is contained in:
Brad Stein 2026-03-31 21:31:34 -03:00
parent 7d66baf91d
commit 678c68e294
2 changed files with 33 additions and 21 deletions

View File

@ -293,21 +293,30 @@ func orasLogin(registry, username, password string) error {
} }
func orasPush(ref, imagePath, metadataPath string) error { func orasPush(ref, imagePath, metadataPath string) error {
cmd := exec.Command("oras", orasPushArgs(ref, imagePath, metadataPath)...) dir, args, err := orasPushInvocation(ref, imagePath, metadataPath)
if err != nil {
return err
}
cmd := exec.Command("oras", args...)
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil { if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out))) return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out)))
} }
return nil return nil
} }
func orasPushArgs(ref, imagePath, metadataPath string) []string { func orasPushInvocation(ref, imagePath, metadataPath string) (string, []string, error) {
return []string{ imageDir := filepath.Dir(imagePath)
"push", metadataDir := filepath.Dir(metadataPath)
"--disable-path-validation", if imageDir != metadataDir {
ref, return "", nil, fmt.Errorf("oras push requires artifacts in one directory: %s vs %s", imageDir, metadataDir)
fmt.Sprintf("%s:application/x-raw-disk-image", imagePath),
fmt.Sprintf("%s:application/json", metadataPath),
} }
return imageDir, []string{
"push",
ref,
fmt.Sprintf("%s:application/x-raw-disk-image", filepath.Base(imagePath)),
fmt.Sprintf("%s:application/json", filepath.Base(metadataPath)),
}, nil
} }
func orasTag(ref string, tags ...string) error { func orasTag(ref string, tags ...string) error {

View File

@ -2,24 +2,27 @@ package main
import "testing" import "testing"
func TestOrasPushArgsAllowAbsoluteWorkspacePaths(t *testing.T) { func TestOrasPushInvocationUsesRelativeWorkspacePaths(t *testing.T) {
args := orasPushArgs("registry.bstein.dev/metis/titan-13:20260331t235724z", "/workspace/build/titan-13.img.xz", "/workspace/build/metadata.json") dir, args, err := orasPushInvocation("registry.bstein.dev/metis/titan-13:20260331t235724z", "/workspace/build/titan-13.img.xz", "/workspace/build/metadata.json")
if len(args) != 5 { if err != nil {
t.Fatalf("expected 5 args, got %d", len(args)) t.Fatalf("orasPushInvocation returned error: %v", err)
}
if dir != "/workspace/build" {
t.Fatalf("expected work dir /workspace/build, got %q", dir)
}
if len(args) != 4 {
t.Fatalf("expected 4 args, got %d", len(args))
} }
if args[0] != "push" { if args[0] != "push" {
t.Fatalf("expected push verb, got %q", args[0]) t.Fatalf("expected push verb, got %q", args[0])
} }
if args[1] != "--disable-path-validation" { if args[1] != "registry.bstein.dev/metis/titan-13:20260331t235724z" {
t.Fatalf("expected --disable-path-validation, got %q", args[1]) t.Fatalf("unexpected ref: %q", args[1])
} }
if args[2] != "registry.bstein.dev/metis/titan-13:20260331t235724z" { if args[2] != "titan-13.img.xz:application/x-raw-disk-image" {
t.Fatalf("unexpected ref: %q", args[2]) t.Fatalf("unexpected image arg: %q", args[2])
} }
if args[3] != "/workspace/build/titan-13.img.xz:application/x-raw-disk-image" { if args[3] != "metadata.json:application/json" {
t.Fatalf("unexpected image arg: %q", args[3]) t.Fatalf("unexpected metadata arg: %q", args[3])
}
if args[4] != "/workspace/build/metadata.json:application/json" {
t.Fatalf("unexpected metadata arg: %q", args[4])
} }
} }