cmd/mstorectl/imagecmd: added os/arch/variant option to repo client
This commit is contained in:
@@ -12,6 +12,7 @@ package imagecmd
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -74,6 +75,10 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
|||||||
Run: util.PullImage,
|
Run: util.PullImage,
|
||||||
}
|
}
|
||||||
pullImageCmd.Flags().BoolVarP(&util.pullImageParams.UseGoogleClient, "google", "G", false, "Use google client")
|
pullImageCmd.Flags().BoolVarP(&util.pullImageParams.UseGoogleClient, "google", "G", false, "Use google client")
|
||||||
|
pullImageCmd.Flags().StringVarP(&util.pullImageParams.OS, "os", "O", runtime.GOOS, "Get operation system type")
|
||||||
|
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Arch, "arch", "A", runtime.GOARCH, "Get CPU architerure")
|
||||||
|
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Variant, "variant", "V", "", "Get OS or CPU variant")
|
||||||
|
|
||||||
subCmd.AddCommand(pullImageCmd)
|
subCmd.AddCommand(pullImageCmd)
|
||||||
|
|
||||||
// DeleteImage
|
// DeleteImage
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ type PullImageParams struct {
|
|||||||
Imagepath string
|
Imagepath string
|
||||||
Filepath string
|
Filepath string
|
||||||
UseGoogleClient bool
|
UseGoogleClient bool
|
||||||
|
Arch string
|
||||||
|
OS string
|
||||||
|
Variant string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullImageResult struct {
|
type PullImageResult struct {
|
||||||
@@ -68,7 +71,7 @@ func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImagePar
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
imageDir := auxtool.MakeTmpFilename(params.Filepath)
|
imageDir := auxtool.MakeTmpFilename(params.Filepath)
|
||||||
err = load.Pull(ctx, ref.Raw(), imageDir, "", "")
|
err = load.Pull(ctx, ref.Raw(), imageDir, params.OS, params.Arch, params.Variant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,6 @@ import (
|
|||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
//MediaTypeOIIv1 = "application/vnd.oci.image.index.v1+json"
|
|
||||||
//MediaTypeDDMLv2 = "application/vnd.docker.distribution.manifest.list.v2+json"
|
|
||||||
|
|
||||||
// MediaTypeDDMv2 = "application/vnd.docker.distribution.manifest.v2+json"
|
|
||||||
// MediaTypeOIMv1 = "application/vnd.oci.image.manifest.v1+json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Loader struct {
|
type Loader struct {
|
||||||
cli *Client
|
cli *Client
|
||||||
}
|
}
|
||||||
@@ -38,7 +30,7 @@ func NewLoader(client *Client) *Loader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (down *Loader) Pull(ctx context.Context, rawref, dir, osname, arch string) error {
|
func (down *Loader) Pull(ctx context.Context, rawref, dir, osname, arch, variant string) error {
|
||||||
var err error
|
var err error
|
||||||
if osname == "" {
|
if osname == "" {
|
||||||
osname = runtime.GOOS
|
osname = runtime.GOOS
|
||||||
@@ -75,11 +67,16 @@ func (down *Loader) Pull(ctx context.Context, rawref, dir, osname, arch string)
|
|||||||
}
|
}
|
||||||
for _, descr := range index.Manifests {
|
for _, descr := range index.Manifests {
|
||||||
if descr.Platform != nil {
|
if descr.Platform != nil {
|
||||||
cond := descr.Platform.Architecture == arch
|
var cond bool
|
||||||
|
cond = descr.Platform.Architecture == arch
|
||||||
cond = cond && descr.Platform.OS == osname
|
cond = cond && descr.Platform.OS == osname
|
||||||
|
if variant != "" {
|
||||||
|
cond = cond && descr.Platform.Variant == variant
|
||||||
|
}
|
||||||
if cond {
|
if cond {
|
||||||
tag = descr.Digest.String()
|
tag = descr.Digest.String()
|
||||||
digstr = descr.Digest.String()
|
digstr = descr.Digest.String()
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user