-
Notifications
You must be signed in to change notification settings - Fork 2
/
fetch.go
92 lines (79 loc) · 2.15 KB
/
fetch.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
"github.com/k0kubun/go-ansi"
"github.com/schollz/progressbar/v3"
"github.com/urfave/cli/v2"
)
func doFetchTags(c *cli.Context) error {
registry := c.String("registry")
if registry == "" {
return nil // We are not required to fetch flags.
}
prefixes := c.String("prefixes")
out := getKnowLayersFilename()
makeCacheDir() // Ensure the cache directory exists.
reg := NewReg(registry, prefixes)
ctx := context.Background()
l, e := reg.GetRepoList(ctx)
if e != nil {
return e
}
entries := LayerNameHashEntries{}
repos := []*Repo{}
bar := progressbar.NewOptions(len(l.Repositories),
progressbar.OptionSetWriter(ansi.NewAnsiStdout()),
progressbar.OptionEnableColorCodes(true),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(15),
progressbar.OptionSetDescription("[cyan][1/2][reset] Fetching Repositories"),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "[green]=[reset]",
SaucerHead: "[green]>[reset]",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
repoChan := make(chan RepoError, 16)
go reg.FetchRepoInfos(l, repoChan)
for repo := range repoChan {
r, e := repo.Repo, repo.Err
if e != nil {
return e
}
if e := bar.Add(1); e != nil {
return e
}
repos = append(repos, r)
}
totalTags := 0
for _, r := range repos {
totalTags += len(r.Tags)
}
bar = progressbar.NewOptions(totalTags,
progressbar.OptionSetWriter(ansi.NewAnsiStdout()),
progressbar.OptionEnableColorCodes(true),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(15),
progressbar.OptionSetDescription("[cyan][2/2][reset] Fetching Image Tags"),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "[green]=[reset]",
SaucerHead: "[green]>[reset]",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
tagChan := make(chan LayerEntryError, 64)
go reg.FetchLayerEntries(repos, tagChan)
for entryErr := range tagChan {
entry, err := entryErr.Entry, entryErr.Err
if err != nil {
return err
}
if e := bar.Add(1); e != nil {
return e
}
entries = append(entries, entry)
}
return entries.Save(out)
}