/
pull.go
66 lines (52 loc) · 1.26 KB
/
pull.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package cli
import (
"context"
"sync"
"github.com/spf13/cobra"
"github.com/czankel/cne/runtime"
)
func pullImage(ctx context.Context, run runtime.Runtime, imgName string) (runtime.Image, error) {
imgName, err := conf.FullImageName(imgName)
if err != nil {
return nil, err
}
progress := make(chan []runtime.ProgressStatus)
var wg sync.WaitGroup
defer wg.Wait()
defer close(progress)
go func() {
defer wg.Done()
wg.Add(1)
showProgress(progress)
}()
return run.PullImage(ctx, imgName, progress)
}
var pullCmd = &cobra.Command{
Use: "pull [registry]package[:tag|@digest]",
Short: "Pull an image from a registry",
Long: `
Pull an image from a registry to the local system.
REGISTRY can be one of the configured registries or directly
specify the domain and repository. If omitted, the default
registry is used.`,
Args: cobra.ExactArgs(1),
RunE: pullImageRunE,
}
func pullImageRunE(cmd *cobra.Command, args []string) error {
runCfg, err := conf.GetRuntime()
if err != nil {
return err
}
ctx := context.Background()
run, err := runtime.Open(ctx, runCfg)
if err != nil {
return err
}
defer run.Close()
ctx = run.WithNamespace(ctx, runCfg.Namespace)
_, err = pullImage(ctx, run, args[0])
return err
}
func init() {
rootCmd.AddCommand(pullCmd)
}