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 {
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 {
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out)))
}
return nil
}
func orasPushArgs(ref, imagePath, metadataPath string) []string {
return []string{
"push",
"--disable-path-validation",
ref,
fmt.Sprintf("%s:application/x-raw-disk-image", imagePath),
fmt.Sprintf("%s:application/json", metadataPath),
func orasPushInvocation(ref, imagePath, metadataPath string) (string, []string, error) {
imageDir := filepath.Dir(imagePath)
metadataDir := filepath.Dir(metadataPath)
if imageDir != metadataDir {
return "", nil, fmt.Errorf("oras push requires artifacts in one directory: %s vs %s", imageDir, metadataDir)
}
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 {

View File

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