[feat] add pull argument

This commit is contained in:
jay
2022-06-14 13:15:10 +08:00
parent b351de0f64
commit 1988ed6762
3 changed files with 14 additions and 4 deletions
+5 -3
View File
@@ -12,7 +12,7 @@ import (
"github.com/docker/docker/client"
)
func SaveImageTar(ctx context.Context, image, path, name string) error {
func SaveImageTar(ctx context.Context, image, path, name string, doPull bool) error {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
@@ -20,8 +20,10 @@ func SaveImageTar(ctx context.Context, image, path, name string) error {
}
defer cli.Close()
if err := pullImage(ctx, cli, image); err != nil {
return fmt.Errorf("pull image %s failed: %v", image, err)
if doPull {
if err := pullImage(ctx, cli, image); err != nil {
return fmt.Errorf("pull image %s failed: %v", image, err)
}
}
if err := saveToTar(ctx, cli, image, path, name); err != nil {