Skip to content

Commit e36f787

Browse files
authored
Merge pull request #6054 from 7AC/master
bashbrew: account for namespaces when sorting repos
2 parents 52682c5 + c922da0 commit e36f787

File tree

11 files changed

+56
-42
lines changed

11 files changed

+56
-42
lines changed

go/src/bashbrew/cmd-build.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func cmdBuild(c *cli.Context) error {
1818
}
1919

2020
uniq := c.Bool("uniq")
21-
namespace := c.String("namespace")
2221
pull := c.String("pull")
2322
switch pull {
2423
case "always", "missing", "never":

go/src/bashbrew/cmd-cat.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func cmdCat(c *cli.Context) error {
5555
"arch": func() string {
5656
return arch
5757
},
58+
"namespace": func() string {
59+
return namespace
60+
},
5861
"archNamespace": func(arch string) string {
5962
return archNamespaces[arch]
6063
},

go/src/bashbrew/cmd-deps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
5050
continue
5151
}
5252

53-
for _, tag := range r.Tags("", false, entry) {
53+
for _, tag := range r.Tags(namespace, false, entry) {
5454
network.AddNode(tag, entry)
5555
}
5656
}
@@ -78,7 +78,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
7878
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
7979
}
8080
for _, from := range froms {
81-
for _, tag := range r.Tags("", false, entry) {
81+
for _, tag := range r.Tags(namespace, false, entry) {
8282
network.AddEdge(from, tag)
8383
}
8484
}
@@ -99,7 +99,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
9999
continue
100100
}
101101

102-
for _, tag := range r.Tags("", uniq, entry) {
102+
for _, tag := range r.Tags(namespace, uniq, entry) {
103103
nodes := []topsortDepthNodes{}
104104
if parents {
105105
nodes = append(nodes, topsortDepthNodes{

go/src/bashbrew/cmd-from.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func cmdFrom(c *cli.Context) error {
1414
}
1515

1616
uniq := c.Bool("uniq")
17-
namespace := ""
1817
applyConstraints := c.Bool("apply-constraints")
1918

2019
for _, repo := range repos {

go/src/bashbrew/cmd-list.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func cmdList(c *cli.Context) error {
1414
}
1515

1616
uniq := c.Bool("uniq")
17-
namespace := ""
1817
applyConstraints := c.Bool("apply-constraints")
1918
onlyRepos := c.Bool("repos")
2019

go/src/bashbrew/cmd-push.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ func cmdPush(c *cli.Context) error {
1616
}
1717

1818
uniq := c.Bool("uniq")
19-
namespace := c.String("namespace")
19+
targetNamespace := c.String("target-namespace")
2020
dryRun := c.Bool("dry-run")
2121
force := c.Bool("force")
2222

23-
if namespace == "" {
24-
return fmt.Errorf(`"--namespace" is a required flag for "push"`)
23+
if targetNamespace == "" {
24+
targetNamespace = namespace
25+
}
26+
if targetNamespace == "" {
27+
return fmt.Errorf(`either "--target-namespace" or "--namespace" is a required flag for "push"`)
2528
}
2629

2730
for _, repo := range repos {
@@ -30,7 +33,7 @@ func cmdPush(c *cli.Context) error {
3033
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
3134
}
3235

33-
tagRepo := path.Join(namespace, r.RepoName)
36+
tagRepo := path.Join(targetNamespace, r.RepoName)
3437
for _, entry := range r.Entries() {
3538
if r.SkipConstraints(entry) {
3639
continue

go/src/bashbrew/cmd-put-shared.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ func cmdPutShared(c *cli.Context) error {
8383
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
8484
}
8585

86-
namespace := c.String("namespace")
8786
dryRun := c.Bool("dry-run")
87+
targetNamespace := c.String("target-namespace")
8888
force := c.Bool("force")
8989
singleArch := c.Bool("single-arch")
9090

91-
if namespace == "" {
92-
return fmt.Errorf(`"--namespace" is a required flag for "put-shared"`)
91+
if targetNamespace == "" {
92+
targetNamespace = namespace
93+
}
94+
if targetNamespace == "" {
95+
return fmt.Errorf(`either "--target-namespace" or "--namespace" is a required flag for "put-shared"`)
9396
}
9497

9598
for _, repo := range repos {
@@ -98,7 +101,7 @@ func cmdPutShared(c *cli.Context) error {
98101
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
99102
}
100103

101-
targetRepo := path.Join(namespace, r.RepoName)
104+
targetRepo := path.Join(targetNamespace, r.RepoName)
102105

103106
sharedTagGroups := []manifest.SharedTagGroup{}
104107

go/src/bashbrew/cmd-tag.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ func cmdTag(c *cli.Context) error {
1414
}
1515

1616
uniq := c.Bool("uniq")
17-
namespace := c.String("namespace")
17+
targetNamespace := c.String("target-namespace")
1818
dryRun := c.Bool("dry-run")
1919

20-
if namespace == "" {
21-
return fmt.Errorf(`"--namespace" is a required flag for "tag"`)
20+
if targetNamespace == "" {
21+
return fmt.Errorf(`"--target-namespace" is a required flag for "tag"`)
2222
}
2323

2424
for _, repo := range repos {
@@ -33,12 +33,13 @@ func cmdTag(c *cli.Context) error {
3333
}
3434

3535
for _, tag := range r.Tags("", uniq, entry) {
36-
namespacedTag := path.Join(namespace, tag)
37-
fmt.Printf("Tagging %s\n", namespacedTag)
36+
sourceTag := path.Join(namespace, tag)
37+
targetTag := path.Join(targetNamespace, tag)
38+
fmt.Printf("Tagging %s\n", targetTag)
3839
if !dryRun {
39-
err = dockerTag(tag, namespacedTag)
40+
err = dockerTag(sourceTag, targetTag)
4041
if err != nil {
41-
return cli.NewMultiError(fmt.Errorf(`failed tagging %q as %q`, tag, namespacedTag), err)
42+
return cli.NewMultiError(fmt.Errorf(`failed tagging %q as %q`, sourceTag, targetTag), err)
4243
}
4344
}
4445
}

go/src/bashbrew/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ type FlagsConfigEntry struct {
2222
Cache string
2323
Debug string
2424
Unique string
25-
Namespace string
2625
BuildOrder string
2726
Pull string
2827

2928
Arch string
29+
Namespace string
3030
Constraints []string `delim:"," strip:"\n\r\t "`
3131
ExclusiveConstraints string
3232
ApplyConstraints string
@@ -50,9 +50,6 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) {
5050
if src.Unique != "" {
5151
dst.Unique = src.Unique
5252
}
53-
if src.Namespace != "" {
54-
dst.Namespace = src.Namespace
55-
}
5653
if src.BuildOrder != "" {
5754
dst.BuildOrder = src.BuildOrder
5855
}
@@ -62,6 +59,9 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) {
6259
if src.Arch != "" {
6360
dst.Arch = src.Arch
6461
}
62+
if src.Namespace != "" {
63+
dst.Namespace = src.Namespace
64+
}
6565
if len(src.Constraints) > 0 {
6666
dst.Constraints = src.Constraints[:]
6767
}
@@ -84,6 +84,7 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} {
8484
"debug": config.Debug,
8585

8686
"arch": config.Arch,
87+
"namespace": config.Namespace,
8788
"constraint": config.Constraints,
8889
"exclusive-constraints": config.ExclusiveConstraints,
8990

@@ -92,7 +93,6 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} {
9293

9394
"local": {
9495
"uniq": config.Unique,
95-
"namespace": config.Namespace,
9696
"build-order": config.BuildOrder,
9797
"pull": config.Pull,
9898

go/src/bashbrew/main.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
defaultCache string
2323

2424
arch string
25+
namespace string
2526
constraints []string
2627
exclusiveConstraints bool
2728

@@ -32,12 +33,13 @@ var (
3233

3334
// separated so that FlagsConfig.ApplyTo can access them
3435
flagEnvVars = map[string]string{
35-
"debug": "BASHBREW_DEBUG",
36-
"arch": "BASHBREW_ARCH",
37-
"config": "BASHBREW_CONFIG",
38-
"library": "BASHBREW_LIBRARY",
39-
"cache": "BASHBREW_CACHE",
40-
"pull": "BASHBREW_PULL",
36+
"debug": "BASHBREW_DEBUG",
37+
"arch": "BASHBREW_ARCH",
38+
"namespace": "BASHBREW_NAMESPACE",
39+
"config": "BASHBREW_CONFIG",
40+
"library": "BASHBREW_LIBRARY",
41+
"cache": "BASHBREW_CACHE",
42+
"pull": "BASHBREW_PULL",
4143

4244
"constraint": "BASHBREW_CONSTRAINTS",
4345
"arch-namespace": "BASHBREW_ARCH_NAMESPACES",
@@ -93,6 +95,11 @@ func main() {
9395
EnvVar: flagEnvVars["arch"],
9496
Usage: "the current platform architecture",
9597
},
98+
cli.StringFlag{
99+
Name: "namespace",
100+
EnvVar: flagEnvVars["namespace"],
101+
Usage: "a repo namespace to act upon/in",
102+
},
96103
cli.StringSliceFlag{
97104
Name: "constraint",
98105
EnvVar: flagEnvVars["constraint"],
@@ -156,6 +163,7 @@ func main() {
156163
noSortFlag = c.GlobalBool("no-sort")
157164

158165
arch = c.GlobalString("arch")
166+
namespace = c.GlobalString("namespace")
159167
constraints = c.GlobalStringSlice("constraint")
160168
exclusiveConstraints = c.GlobalBool("exclusive-constraints")
161169

@@ -189,10 +197,6 @@ func main() {
189197
Name: "uniq, unique",
190198
Usage: "only act upon the first tag of each entry",
191199
},
192-
"namespace": cli.StringFlag{
193-
Name: "namespace",
194-
Usage: "a repo namespace to act upon/in",
195-
},
196200
"apply-constraints": cli.BoolFlag{
197201
Name: "apply-constraints",
198202
Usage: "apply Constraints as if repos were building",
@@ -210,6 +214,10 @@ func main() {
210214
Name: "force",
211215
Usage: "always push (skip the clever Hub API lookups that no-op things sooner if a push doesn't seem necessary)",
212216
},
217+
"target-namespace": cli.StringFlag{
218+
Name: "target-namespace",
219+
Usage: `target namespace to act into ("docker tag namespace/repo:tag target-namespace/repo:tag", "docker push target-namespace/repo:tag")`,
220+
},
213221
}
214222

215223
app.Commands = []cli.Command{
@@ -239,7 +247,6 @@ func main() {
239247
Flags: []cli.Flag{
240248
commonFlags["all"],
241249
commonFlags["uniq"],
242-
commonFlags["namespace"],
243250
cli.StringFlag{
244251
Name: "pull",
245252
Value: "missing",
@@ -257,8 +264,8 @@ func main() {
257264
Flags: []cli.Flag{
258265
commonFlags["all"],
259266
commonFlags["uniq"],
260-
commonFlags["namespace"],
261267
commonFlags["dry-run"],
268+
commonFlags["target-namespace"],
262269
},
263270
Before: subcommandBeforeFactory("tag"),
264271
Action: cmdTag,
@@ -269,9 +276,9 @@ func main() {
269276
Flags: []cli.Flag{
270277
commonFlags["all"],
271278
commonFlags["uniq"],
272-
commonFlags["namespace"],
273279
commonFlags["dry-run"],
274280
commonFlags["force"],
281+
commonFlags["target-namespace"],
275282
},
276283
Before: subcommandBeforeFactory("push"),
277284
Action: cmdPush,
@@ -281,9 +288,9 @@ func main() {
281288
Usage: `update shared tags in the registry (and multi-architecture tags)`,
282289
Flags: []cli.Flag{
283290
commonFlags["all"],
284-
commonFlags["namespace"],
285291
commonFlags["dry-run"],
286292
commonFlags["force"],
293+
commonFlags["target-namespace"],
287294
cli.BoolFlag{
288295
Name: "single-arch",
289296
Usage: `only act on the current architecture (for pushing "amd64/hello-world:latest", for example)`,

0 commit comments

Comments
 (0)