mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-02-14 09:59:50 +00:00
allow loading of docker tarballs (#452)
Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> Co-authored-by: Adam Martin <adam.martin@ranchergovernment.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -15,6 +16,8 @@ import (
|
|||||||
"hauler.dev/go/hauler/pkg/getter"
|
"hauler.dev/go/hauler/pkg/getter"
|
||||||
"hauler.dev/go/hauler/pkg/log"
|
"hauler.dev/go/hauler/pkg/log"
|
||||||
"hauler.dev/go/hauler/pkg/store"
|
"hauler.dev/go/hauler/pkg/store"
|
||||||
|
|
||||||
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// extracts the contents of an archived oci layout to an existing oci layout
|
// extracts the contents of an archived oci layout to an existing oci layout
|
||||||
@@ -85,6 +88,42 @@ func unarchiveLayoutTo(ctx context.Context, haulPath string, dest string, tempDi
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure the incoming index.json has the correct annotations.
|
||||||
|
data, err := os.ReadFile(tempDir + "/index.json")
|
||||||
|
if err != nil {
|
||||||
|
return (err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var idx ocispec.Index
|
||||||
|
if err := json.Unmarshal(data, &idx); err != nil {
|
||||||
|
return (err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range idx.Manifests {
|
||||||
|
if idx.Manifests[i].Annotations == nil {
|
||||||
|
idx.Manifests[i].Annotations = make(map[string]string)
|
||||||
|
}
|
||||||
|
if _, exists := idx.Manifests[i].Annotations[consts.KindAnnotationName]; !exists {
|
||||||
|
idx.Manifests[i].Annotations[consts.KindAnnotationName] = consts.KindAnnotationImage
|
||||||
|
}
|
||||||
|
if ref, ok := idx.Manifests[i].Annotations[consts.ContainerdImageNameKey]; ok {
|
||||||
|
if slash := strings.Index(ref, "/"); slash != -1 {
|
||||||
|
ref = ref[slash+1:]
|
||||||
|
}
|
||||||
|
if idx.Manifests[i].Annotations[consts.ImageRefKey] != ref {
|
||||||
|
idx.Manifests[i].Annotations[consts.ImageRefKey] = ref
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := json.MarshalIndent(idx, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(tempDir+"/index.json", out, 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
s, err := store.NewLayout(tempDir)
|
s, err := store.NewLayout(tempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ const (
|
|||||||
HaulerVendorPrefix = "vnd.hauler"
|
HaulerVendorPrefix = "vnd.hauler"
|
||||||
|
|
||||||
// annotation keys
|
// annotation keys
|
||||||
|
ContainerdImageNameKey = "io.containerd.image.name"
|
||||||
KindAnnotationName = "kind"
|
KindAnnotationName = "kind"
|
||||||
KindAnnotationImage = "dev.cosignproject.cosign/image"
|
KindAnnotationImage = "dev.cosignproject.cosign/image"
|
||||||
KindAnnotationIndex = "dev.cosignproject.cosign/imageIndex"
|
KindAnnotationIndex = "dev.cosignproject.cosign/imageIndex"
|
||||||
@@ -49,6 +50,7 @@ const (
|
|||||||
ImageAnnotationPlatform = "hauler.dev/platform"
|
ImageAnnotationPlatform = "hauler.dev/platform"
|
||||||
ImageAnnotationRegistry = "hauler.dev/registry"
|
ImageAnnotationRegistry = "hauler.dev/registry"
|
||||||
ImageAnnotationTlog = "hauler.dev/use-tlog-verify"
|
ImageAnnotationTlog = "hauler.dev/use-tlog-verify"
|
||||||
|
ImageRefKey = "org.opencontainers.image.ref.name"
|
||||||
|
|
||||||
// cosign keyless validation options
|
// cosign keyless validation options
|
||||||
ImageAnnotationCertIdentity = "hauler.dev/certificate-identity"
|
ImageAnnotationCertIdentity = "hauler.dev/certificate-identity"
|
||||||
|
|||||||
Reference in New Issue
Block a user