Skip to content

Commit c7d3d0d

Browse files
committed
Add "bashbrew fetch" command
In many, many, many scripts I have encoded the horrible assumption that `ArchDockerFroms` will ensure our Git repository is fetched (which is a side-effect of that function). With the implementation of `Builder: oci-import`, that side effect is not necessary for returning an accurate result in these new images. Instead of working around this in bad ways, I've decided to finally bite the bullet and add an explicit `bashbrew fetch` command that can make sure all the underlying Git commits are fully fetched into the local cache.
1 parent 5990ace commit c7d3d0d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

cmd/bashbrew/cmd-fetch.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/urfave/cli"
8+
)
9+
10+
func cmdFetch(c *cli.Context) error {
11+
repos, err := repos(c.Bool("all"), c.Args()...)
12+
if err != nil {
13+
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
14+
}
15+
16+
applyConstraints := c.Bool("apply-constraints")
17+
archFilter := c.Bool("arch-filter")
18+
19+
for _, repo := range repos {
20+
r, err := fetch(repo)
21+
if err != nil {
22+
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
23+
}
24+
25+
for _, entry := range r.Entries() {
26+
if applyConstraints && r.SkipConstraints(entry) {
27+
continue
28+
}
29+
if archFilter && !entry.HasArchitecture(arch) {
30+
continue
31+
}
32+
33+
arches := entry.Architectures
34+
if applyConstraints || archFilter {
35+
arches = []string{arch}
36+
}
37+
38+
for _, entryArch := range arches {
39+
commit, err := r.fetchGitRepo(entryArch, entry)
40+
if err != nil {
41+
return cli.NewMultiError(fmt.Errorf(`failed fetching git repo for %q (tags %q on arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
42+
}
43+
if debugFlag {
44+
fmt.Fprintf(os.Stderr, "DEBUG: fetched %s (%q, %q)\n", commit, r.EntryIdentifier(entry), entryArch)
45+
}
46+
}
47+
}
48+
}
49+
50+
return nil
51+
}

cmd/bashbrew/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,19 @@ func main() {
402402

403403
Category: "plumbing",
404404
},
405+
{
406+
Name: "fetch",
407+
Usage: "ensure Git contents are local",
408+
Flags: []cli.Flag{
409+
commonFlags["all"],
410+
commonFlags["apply-constraints"],
411+
commonFlags["arch-filter"],
412+
},
413+
Before: subcommandBeforeFactory("fetch"),
414+
Action: cmdFetch,
415+
416+
Category: "plumbing",
417+
},
405418
{
406419
Name: "remote",
407420
Usage: "query registries for bashbrew-related data",

0 commit comments

Comments
 (0)