mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Merge pull request #21657 from baude/fixocipull
Fix small bug in ocipull
This commit is contained in:
@ -29,6 +29,7 @@ const (
|
|||||||
artifactRepo = "baude"
|
artifactRepo = "baude"
|
||||||
artifactImageName = "podman-machine-images-art"
|
artifactImageName = "podman-machine-images-art"
|
||||||
artifactOriginalName = "org.opencontainers.image.title"
|
artifactOriginalName = "org.opencontainers.image.title"
|
||||||
|
machineOS = "linux"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OCIArtifactDisk struct {
|
type OCIArtifactDisk struct {
|
||||||
@ -88,7 +89,7 @@ func NewOCIArtifactPull(ctx context.Context, dirs *define.MachineDirs, vmName st
|
|||||||
diskOpts := DiskArtifactOpts{
|
diskOpts := DiskArtifactOpts{
|
||||||
arch: arch,
|
arch: arch,
|
||||||
diskType: vmType.String(),
|
diskType: vmType.String(),
|
||||||
os: runtime.GOOS,
|
os: machineOS,
|
||||||
}
|
}
|
||||||
ociDisk := OCIArtifactDisk{
|
ociDisk := OCIArtifactDisk{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/containers/image/v5/transports/alltransports"
|
"github.com/containers/image/v5/transports/alltransports"
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/podman/v5/pkg/machine/define"
|
"github.com/containers/podman/v5/pkg/machine/define"
|
||||||
specV1 "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PullOptions includes data to alter certain knobs when pulling a source
|
// PullOptions includes data to alter certain knobs when pulling a source
|
||||||
@ -49,10 +48,6 @@ func Pull(ctx context.Context, imageInput types.ImageReference, localDestPath *d
|
|||||||
sysCtx.DockerAuthConfig = authConf
|
sysCtx.DockerAuthConfig = authConf
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSourceImageReference(ctx, imageInput, sysCtx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
policy, err := signature.DefaultPolicy(sysCtx)
|
policy, err := signature.DefaultPolicy(sysCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("obtaining default signature policy: %w", err)
|
return fmt.Errorf("obtaining default signature policy: %w", err)
|
||||||
@ -87,20 +82,3 @@ func stringToImageReference(imageInput string) (types.ImageReference, error) { /
|
|||||||
|
|
||||||
return ref, nil
|
return ref, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateSourceImageReference(ctx context.Context, ref types.ImageReference, sysCtx *types.SystemContext) error {
|
|
||||||
src, err := ref.NewImageSource(ctx, sysCtx)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("creating image source from reference: %w", err)
|
|
||||||
}
|
|
||||||
defer src.Close()
|
|
||||||
|
|
||||||
ociManifest, _, _, err := readManifestFromImageSource(ctx, src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if ociManifest.Config.MediaType != specV1.MediaTypeImageConfig {
|
|
||||||
return fmt.Errorf("invalid media type of image config %q (expected: %q)", ociManifest.Config.MediaType, specV1.MediaTypeImageConfig)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -5,9 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/containers/image/v5/docker"
|
|
||||||
"github.com/containers/image/v5/manifest"
|
"github.com/containers/image/v5/manifest"
|
||||||
"github.com/containers/image/v5/oci/layout"
|
"github.com/containers/image/v5/oci/layout"
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
@ -16,26 +14,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// readManifestFromImageSource reads the manifest from the specified image
|
|
||||||
// source. Note that the manifest is expected to be an OCI v1 manifest.
|
|
||||||
func readManifestFromImageSource(ctx context.Context, src types.ImageSource) (*specV1.Manifest, *digest.Digest, int64, error) {
|
|
||||||
rawData, mimeType, err := src.GetManifest(ctx, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, -1, err
|
|
||||||
}
|
|
||||||
if mimeType != specV1.MediaTypeImageManifest {
|
|
||||||
return nil, nil, -1, fmt.Errorf("image %q is of type %q (expected: %q)", strings.TrimPrefix(src.Reference().StringWithinTransport(), "//"), mimeType, specV1.MediaTypeImageManifest)
|
|
||||||
}
|
|
||||||
|
|
||||||
mannyFest := specV1.Manifest{}
|
|
||||||
if err := json.Unmarshal(rawData, &mannyFest); err != nil {
|
|
||||||
return nil, nil, -1, fmt.Errorf("reading manifest: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
manifestDigest := digest.FromBytes(rawData)
|
|
||||||
return &mannyFest, &manifestDigest, int64(len(rawData)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetLocalBlob(ctx context.Context, path string) (*types.BlobInfo, error) {
|
func GetLocalBlob(ctx context.Context, path string) (*types.BlobInfo, error) {
|
||||||
ociRef, err := layout.ParseReference(path)
|
ociRef, err := layout.ParseReference(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,27 +44,6 @@ func GetLocalBlob(ctx context.Context, path string) (*types.BlobInfo, error) {
|
|||||||
return &blobs[0], nil
|
return &blobs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRemoteManifest(ctx context.Context, dest string) (*specV1.Manifest, error) { //nolint:unused
|
|
||||||
ref, err := docker.ParseReference(fmt.Sprintf("//%s", dest))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
imgSrc, err := ref.NewImage(ctx, &types.SystemContext{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
b, _, err := imgSrc.Manifest(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteManifest := specV1.Manifest{}
|
|
||||||
err = json.Unmarshal(b, &remoteManifest)
|
|
||||||
return &remoteManifest, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDiskArtifactReference(ctx context.Context, imgSrc types.ImageSource, opts *DiskArtifactOpts) (digest.Digest, error) {
|
func GetDiskArtifactReference(ctx context.Context, imgSrc types.ImageSource, opts *DiskArtifactOpts) (digest.Digest, error) {
|
||||||
rawMannyFest, mannyType, err := imgSrc.GetManifest(ctx, nil)
|
rawMannyFest, mannyType, err := imgSrc.GetManifest(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user