55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
/*
|
|
* 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"
|
|
)
|
|
|
|
// PushImage
|
|
type PushImageParams struct {
|
|
Imagepath string
|
|
Filepath string
|
|
}
|
|
|
|
type PushImageResult struct{}
|
|
|
|
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
|
util.pushImageParams.Filepath = args[0]
|
|
util.pushImageParams.Imagepath = args[1]
|
|
|
|
res, err := util.pushImage(&util.commonImageParams, &util.pushImageParams)
|
|
printResponse(res, err)
|
|
}
|
|
|
|
func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) {
|
|
var err error
|
|
ctx := context.Background()
|
|
res := &PushImageResult{}
|
|
|
|
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)
|
|
err = cli.PushImage(ctx, params.Filepath, params.Imagepath)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
return res, err
|
|
}
|