working commit

This commit is contained in:
2026-03-17 14:56:35 +02:00
parent 97904e0529
commit 52789ef4d1
26 changed files with 1334 additions and 52 deletions
+1
View File
@@ -73,6 +73,7 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
Args: cobra.ExactArgs(2),
Run: util.PullImage,
}
pullImageCmd.Flags().BoolVarP(&util.pullImageParams.UseGoogleClient, "google", "G", false, "Use google client")
subCmd.AddCommand(pullImageCmd)
// DeleteImage
+9 -8
View File
@@ -43,24 +43,25 @@ func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageMan
Index: &ocispec.Index{},
Manifest: &ocispec.Manifest{},
}
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
if err != nil {
return res, err
}
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
ref, err := repocli.NewReferer(params.Imagepath)
if err != nil {
return res, err
}
ref.SetUserinfo(common.Username, common.Password)
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClient(nil, mw)
exists, mime, man, _, err := cli.GetRawManifest(ctx, ref.RawRepo())
if !exists {
err = fmt.Errorf("Manifest not found")
accepts := []string{
repocli.MediaTypeDDMLv2,
repocli.MediaTypeDDMv2,
repocli.MediaTypeOIMv1,
repocli.MediaTypeOIIv1,
}
_, mime, man, _, err := cli.GetRawManifest(ctx, ref.Raw(), accepts)
if err != nil {
return res, err
}
switch mime {
case repocli.MediaTypeDDMLv2, repocli.MediaTypeOIIv1:
+18 -8
View File
@@ -14,6 +14,7 @@ import (
"os"
"time"
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
"mstore/pkg/auxtool"
@@ -24,19 +25,26 @@ import (
// PullImage
type PullImageParams struct {
Imagepath string
Filepath string
Imagepath string
Filepath string
UseGoogleClient bool
}
type PullImageResult struct {
Filepath string `json:"filepath"`
Size int64 `json:"size"`
Size string `json:"size"`
}
func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
util.pullImageParams.Imagepath = args[0]
util.pullImageParams.Filepath = args[1]
res, err := util.pullImage(&util.commonImageParams, &util.pullImageParams)
res := &PullImageResult{}
var err error
if util.pullImageParams.UseGoogleClient {
res, err = util.gcrPullImage(&util.commonImageParams, &util.pullImageParams)
} else {
res, err = util.pullImage(&util.commonImageParams, &util.pullImageParams)
}
printResponse(res, err)
}
@@ -73,20 +81,21 @@ func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImagePar
if err != nil {
return res, err
}
res.Size = filestat.Size()
size := filestat.Size()
res.Size = humanize.Comma(size)
res.Filepath = params.Filepath
return res, err
}
func (util *ImageUtil) XXXpullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
func (util *ImageUtil) gcrPullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
var err error
ctx := context.Background()
res := &PullImageResult{}
cli := gcrcli.NewClient(common.SkipTLSVerify)
timeout := time.Duration(common.Timeout) * time.Second
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
if err != nil {
return res, err
@@ -100,7 +109,8 @@ func (util *ImageUtil) XXXpullImage(common *CommonImageParams, params *PullImage
if err != nil {
return res, err
}
res.Size = filestat.Size()
size := filestat.Size()
res.Size = humanize.Comma(size)
res.Filepath = params.Filepath
return res, err
}