working commit
This commit is contained in:
@@ -45,6 +45,7 @@ func (util *ImageUtil) catalogImages(common *CommonImageParams, params *CatalogI
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := repocli.NewClient(nil, mw)
|
||||
opres, err := cli.GetCatalog(ctx, ref.Raw())
|
||||
|
||||
@@ -43,6 +43,7 @@ func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImag
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := repocli.NewClient(nil, mw)
|
||||
_, err = cli.DeleteImage(ctx, ref.Raw())
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package imagecmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"mstore/pkg/gcrcli"
|
||||
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
// ImageConfig
|
||||
type ImageConfigParams struct {
|
||||
Imagepath string
|
||||
}
|
||||
|
||||
type ImageConfigResult struct {
|
||||
ImageConfig *ocispec.Image `json:"imageConfig"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) ImageConfig(cmd *cobra.Command, args []string) {
|
||||
util.imageConfigParams.Imagepath = args[0]
|
||||
res, err := util.imageConfig(&util.commonImageParams, &util.imageConfigParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageConfig(common *CommonImageParams, params *ImageConfigParams) (*ImageConfigResult, error) {
|
||||
var err error
|
||||
res := &ImageConfigResult{
|
||||
ImageConfig: &ocispec.Image{},
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
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
|
||||
}
|
||||
ctx, _ = context.WithTimeout(ctx, timeout)
|
||||
opres, err := cli.ImageConfig(ctx, params.Imagepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.ImageConfig = opres
|
||||
return res, err
|
||||
}
|
||||
@@ -102,14 +102,6 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
}
|
||||
subCmd.AddCommand(imageTagsCmd)
|
||||
|
||||
// ImageConfig
|
||||
var imageConfigCmd = &cobra.Command{
|
||||
Use: "config [user:pass@]hostname[:port]/path:tag",
|
||||
Short: "Show container image config info",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.ImageConfig,
|
||||
}
|
||||
subCmd.AddCommand(imageConfigCmd)
|
||||
// CatalogImages
|
||||
var catalogImagesCmd = &cobra.Command{
|
||||
Use: "catalog [user:pass@]hostname[:port]",
|
||||
@@ -125,7 +117,6 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
type ImageUtil struct {
|
||||
imageManifestParams ImageManifestParams
|
||||
imageTagsParams ImageTagsParams
|
||||
imageConfigParams ImageConfigParams
|
||||
catalogImagesParams CatalogImagesParams
|
||||
|
||||
pullImageParams PullImageParams
|
||||
|
||||
@@ -53,6 +53,7 @@ func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageMan
|
||||
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())
|
||||
|
||||
@@ -47,6 +47,7 @@ func (util *ImageUtil) imageTags(common *CommonImageParams, params *ImageTagsPar
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := repocli.NewClient(nil, mw)
|
||||
opres, err := cli.GetTags(ctx, ref.Raw())
|
||||
|
||||
@@ -16,7 +16,10 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxutar"
|
||||
"mstore/pkg/gcrcli"
|
||||
"mstore/pkg/repocli"
|
||||
)
|
||||
|
||||
// PullImage
|
||||
@@ -39,6 +42,45 @@ func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
|
||||
|
||||
func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
|
||||
var err error
|
||||
res := &PullImageResult{}
|
||||
|
||||
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)
|
||||
load := repocli.NewLoader(cli)
|
||||
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
imageDir := auxtool.MakeTmpFilename(params.Filepath)
|
||||
err = load.Pull(ctx, ref.Raw(), imageDir, "", "")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = auxutar.Archive(imageDir, params.Filepath)
|
||||
defer os.RemoveAll(imageDir)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
filestat, err := os.Stat(params.Filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Size = filestat.Size()
|
||||
res.Filepath = params.Filepath
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *ImageUtil) XXXpullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
res := &PullImageResult{}
|
||||
@@ -60,6 +102,5 @@ func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImagePar
|
||||
}
|
||||
res.Size = filestat.Size()
|
||||
res.Filepath = params.Filepath
|
||||
|
||||
return res, err
|
||||
}
|
||||
@@ -11,11 +11,15 @@ package imagecmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxutar"
|
||||
"mstore/pkg/gcrcli"
|
||||
"mstore/pkg/repocli"
|
||||
)
|
||||
|
||||
// PushImage
|
||||
@@ -35,6 +39,36 @@ func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) {
|
||||
var err error
|
||||
res := &PushImageResult{}
|
||||
|
||||
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)
|
||||
load := repocli.NewLoader(cli)
|
||||
|
||||
imageDir := auxtool.MakeTmpFilename(params.Filepath)
|
||||
err = auxutar.Unarchive(params.Filepath, imageDir)
|
||||
defer os.RemoveAll(imageDir)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = load.Push(ctx, imageDir, ref.Raw(), "", "")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *ImageUtil) XXXpushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
res := &PushImageResult{}
|
||||
Reference in New Issue
Block a user