working commit
This commit is contained in:
+78
-26
@@ -47,6 +47,23 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
Short: "Image operation",
|
||||
}
|
||||
|
||||
// PushImage
|
||||
var pushImageCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "Pull container image into local file",
|
||||
Run: util.PushImage,
|
||||
}
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Username, "user", "u", "", "Username")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Password, "pass", "p", "", "Password")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local file path")
|
||||
pushImageCmd.Flags().Uint64VarP(&util.pushImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
pushImageCmd.MarkFlagRequired("image")
|
||||
pushImageCmd.MarkFlagRequired("file")
|
||||
pushImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(pushImageCmd)
|
||||
|
||||
// ImageInfo
|
||||
var imageInfoCmd = &cobra.Command{
|
||||
Use: "info",
|
||||
@@ -79,30 +96,64 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
|
||||
subCmd.AddCommand(pullImageCmd)
|
||||
|
||||
// PushImage
|
||||
var pushImageCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "Pull container image into local file",
|
||||
Run: util.PushImage,
|
||||
// DeleteImage
|
||||
var deleteImageCmd = &cobra.Command{
|
||||
Use: "info",
|
||||
Short: "Show container image info",
|
||||
Run: util.DeleteImage,
|
||||
}
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Username, "user", "u", "", "Username")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Password, "pass", "p", "", "Password")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local file path")
|
||||
pushImageCmd.Flags().Uint64VarP(&util.pushImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
pushImageCmd.MarkFlagRequired("image")
|
||||
pushImageCmd.MarkFlagRequired("file")
|
||||
pushImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Username, "user", "u", "", "Username")
|
||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Password, "pass", "p", "", "Password")
|
||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
deleteImageCmd.Flags().Uint64VarP(&util.deleteImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
deleteImageCmd.MarkFlagRequired("image")
|
||||
deleteImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(pushImageCmd)
|
||||
subCmd.AddCommand(imageInfoCmd)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
|
||||
type ImageUtil struct {
|
||||
imageInfoParams ImageInfoParams
|
||||
pullImageParams PullImageParams
|
||||
pushImageParams PushImageParams
|
||||
imageInfoParams ImageInfoParams
|
||||
pullImageParams PullImageParams
|
||||
pushImageParams PushImageParams
|
||||
deleteImageParams DeleteImageParams
|
||||
}
|
||||
|
||||
// PushImage
|
||||
type PushImageParams struct {
|
||||
Imagepath string
|
||||
Filepath string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type PushImageResult struct{}
|
||||
|
||||
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
||||
res, err := util.pushImage(&util.pushImageParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, error) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
res := &PushImageResult{}
|
||||
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.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
|
||||
}
|
||||
|
||||
// ImageInfo
|
||||
@@ -179,35 +230,36 @@ func (util *ImageUtil) pullImage(params *PullImageParams) (*PullImageResult, err
|
||||
return res, err
|
||||
}
|
||||
|
||||
// PushImage
|
||||
type PushImageParams struct {
|
||||
// DeleteImage
|
||||
type DeleteImageParams struct {
|
||||
Imagepath string
|
||||
Filepath string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type PushImageResult struct{}
|
||||
type DeleteImageResult struct {
|
||||
}
|
||||
|
||||
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
||||
res, err := util.pushImage(&util.pushImageParams)
|
||||
func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) {
|
||||
res, err := util.deleteImage(&util.deleteImageParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, error) {
|
||||
func (util *ImageUtil) deleteImage(params *DeleteImageParams) (*DeleteImageResult, error) {
|
||||
var err error
|
||||
res := &DeleteImageResult{}
|
||||
ctx := context.Background()
|
||||
res := &PushImageResult{}
|
||||
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
ctx, _ = context.WithTimeout(ctx, timeout)
|
||||
err = cli.PushImage(ctx, params.Filepath, params.Imagepath)
|
||||
err = cli.DeleteImage(ctx, params.Imagepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user