diff --git a/go/src/bashbrew/cmd-build.go b/go/src/bashbrew/cmd-build.go index b40d774..f2b9104 100644 --- a/go/src/bashbrew/cmd-build.go +++ b/go/src/bashbrew/cmd-build.go @@ -18,7 +18,6 @@ func cmdBuild(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := c.String("namespace") pull := c.String("pull") switch pull { case "always", "missing", "never": diff --git a/go/src/bashbrew/cmd-cat.go b/go/src/bashbrew/cmd-cat.go index 3c67bfc..befe411 100644 --- a/go/src/bashbrew/cmd-cat.go +++ b/go/src/bashbrew/cmd-cat.go @@ -55,6 +55,9 @@ func cmdCat(c *cli.Context) error { "arch": func() string { return arch }, + "namespace": func() string { + return namespace + }, "archNamespace": func(arch string) string { return archNamespaces[arch] }, diff --git a/go/src/bashbrew/cmd-deps.go b/go/src/bashbrew/cmd-deps.go index 91e477e..40745d2 100644 --- a/go/src/bashbrew/cmd-deps.go +++ b/go/src/bashbrew/cmd-deps.go @@ -50,7 +50,7 @@ func cmdFamily(parents bool, c *cli.Context) error { continue } - for _, tag := range r.Tags("", false, entry) { + for _, tag := range r.Tags(namespace, false, entry) { network.AddNode(tag, entry) } } @@ -78,7 +78,7 @@ func cmdFamily(parents bool, c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err) } for _, from := range froms { - for _, tag := range r.Tags("", false, entry) { + for _, tag := range r.Tags(namespace, false, entry) { network.AddEdge(from, tag) } } @@ -99,7 +99,7 @@ func cmdFamily(parents bool, c *cli.Context) error { continue } - for _, tag := range r.Tags("", uniq, entry) { + for _, tag := range r.Tags(namespace, uniq, entry) { nodes := []topsortDepthNodes{} if parents { nodes = append(nodes, topsortDepthNodes{ diff --git a/go/src/bashbrew/cmd-from.go b/go/src/bashbrew/cmd-from.go index f8db7e2..e734a6d 100644 --- a/go/src/bashbrew/cmd-from.go +++ b/go/src/bashbrew/cmd-from.go @@ -14,7 +14,6 @@ func cmdFrom(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := "" applyConstraints := c.Bool("apply-constraints") for _, repo := range repos { diff --git a/go/src/bashbrew/cmd-list.go b/go/src/bashbrew/cmd-list.go index 13cf2fd..8a73efa 100644 --- a/go/src/bashbrew/cmd-list.go +++ b/go/src/bashbrew/cmd-list.go @@ -14,7 +14,6 @@ func cmdList(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := "" applyConstraints := c.Bool("apply-constraints") onlyRepos := c.Bool("repos") diff --git a/go/src/bashbrew/cmd-push.go b/go/src/bashbrew/cmd-push.go index f118836..d6f7c64 100644 --- a/go/src/bashbrew/cmd-push.go +++ b/go/src/bashbrew/cmd-push.go @@ -16,12 +16,15 @@ func cmdPush(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := c.String("namespace") + targetNamespace := c.String("target-namespace") dryRun := c.Bool("dry-run") force := c.Bool("force") - if namespace == "" { - return fmt.Errorf(`"--namespace" is a required flag for "push"`) + if targetNamespace == "" { + targetNamespace = namespace + } + if targetNamespace == "" { + return fmt.Errorf(`either "--target-namespace" or "--namespace" is a required flag for "push"`) } for _, repo := range repos { @@ -30,7 +33,7 @@ func cmdPush(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err) } - tagRepo := path.Join(namespace, r.RepoName) + tagRepo := path.Join(targetNamespace, r.RepoName) for _, entry := range r.Entries() { if r.SkipConstraints(entry) { continue diff --git a/go/src/bashbrew/cmd-put-shared.go b/go/src/bashbrew/cmd-put-shared.go index 57aa6c2..edb3a65 100644 --- a/go/src/bashbrew/cmd-put-shared.go +++ b/go/src/bashbrew/cmd-put-shared.go @@ -83,13 +83,16 @@ func cmdPutShared(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err) } - namespace := c.String("namespace") dryRun := c.Bool("dry-run") + targetNamespace := c.String("target-namespace") force := c.Bool("force") singleArch := c.Bool("single-arch") - if namespace == "" { - return fmt.Errorf(`"--namespace" is a required flag for "put-shared"`) + if targetNamespace == "" { + targetNamespace = namespace + } + if targetNamespace == "" { + return fmt.Errorf(`either "--target-namespace" or "--namespace" is a required flag for "put-shared"`) } for _, repo := range repos { @@ -98,7 +101,7 @@ func cmdPutShared(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err) } - targetRepo := path.Join(namespace, r.RepoName) + targetRepo := path.Join(targetNamespace, r.RepoName) sharedTagGroups := []manifest.SharedTagGroup{} diff --git a/go/src/bashbrew/cmd-tag.go b/go/src/bashbrew/cmd-tag.go index f7d9ae7..87d408b 100644 --- a/go/src/bashbrew/cmd-tag.go +++ b/go/src/bashbrew/cmd-tag.go @@ -14,11 +14,11 @@ func cmdTag(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := c.String("namespace") + targetNamespace := c.String("target-namespace") dryRun := c.Bool("dry-run") - if namespace == "" { - return fmt.Errorf(`"--namespace" is a required flag for "tag"`) + if targetNamespace == "" { + return fmt.Errorf(`"--target-namespace" is a required flag for "tag"`) } for _, repo := range repos { @@ -33,12 +33,13 @@ func cmdTag(c *cli.Context) error { } for _, tag := range r.Tags("", uniq, entry) { - namespacedTag := path.Join(namespace, tag) - fmt.Printf("Tagging %s\n", namespacedTag) + sourceTag := path.Join(namespace, tag) + targetTag := path.Join(targetNamespace, tag) + fmt.Printf("Tagging %s\n", targetTag) if !dryRun { - err = dockerTag(tag, namespacedTag) + err = dockerTag(sourceTag, targetTag) if err != nil { - return cli.NewMultiError(fmt.Errorf(`failed tagging %q as %q`, tag, namespacedTag), err) + return cli.NewMultiError(fmt.Errorf(`failed tagging %q as %q`, sourceTag, targetTag), err) } } } diff --git a/go/src/bashbrew/config.go b/go/src/bashbrew/config.go index 87647ce..e75ac22 100644 --- a/go/src/bashbrew/config.go +++ b/go/src/bashbrew/config.go @@ -22,11 +22,11 @@ type FlagsConfigEntry struct { Cache string Debug string Unique string - Namespace string BuildOrder string Pull string Arch string + Namespace string Constraints []string `delim:"," strip:"\n\r\t "` ExclusiveConstraints string ApplyConstraints string @@ -50,9 +50,6 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) { if src.Unique != "" { dst.Unique = src.Unique } - if src.Namespace != "" { - dst.Namespace = src.Namespace - } if src.BuildOrder != "" { dst.BuildOrder = src.BuildOrder } @@ -62,6 +59,9 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) { if src.Arch != "" { dst.Arch = src.Arch } + if src.Namespace != "" { + dst.Namespace = src.Namespace + } if len(src.Constraints) > 0 { dst.Constraints = src.Constraints[:] } @@ -84,6 +84,7 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} { "debug": config.Debug, "arch": config.Arch, + "namespace": config.Namespace, "constraint": config.Constraints, "exclusive-constraints": config.ExclusiveConstraints, @@ -92,7 +93,6 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} { "local": { "uniq": config.Unique, - "namespace": config.Namespace, "build-order": config.BuildOrder, "pull": config.Pull, diff --git a/go/src/bashbrew/main.go b/go/src/bashbrew/main.go index 5382e51..27c65a1 100644 --- a/go/src/bashbrew/main.go +++ b/go/src/bashbrew/main.go @@ -22,6 +22,7 @@ var ( defaultCache string arch string + namespace string constraints []string exclusiveConstraints bool @@ -32,12 +33,13 @@ var ( // separated so that FlagsConfig.ApplyTo can access them flagEnvVars = map[string]string{ - "debug": "BASHBREW_DEBUG", - "arch": "BASHBREW_ARCH", - "config": "BASHBREW_CONFIG", - "library": "BASHBREW_LIBRARY", - "cache": "BASHBREW_CACHE", - "pull": "BASHBREW_PULL", + "debug": "BASHBREW_DEBUG", + "arch": "BASHBREW_ARCH", + "namespace": "BASHBREW_NAMESPACE", + "config": "BASHBREW_CONFIG", + "library": "BASHBREW_LIBRARY", + "cache": "BASHBREW_CACHE", + "pull": "BASHBREW_PULL", "constraint": "BASHBREW_CONSTRAINTS", "arch-namespace": "BASHBREW_ARCH_NAMESPACES", @@ -93,6 +95,11 @@ func main() { EnvVar: flagEnvVars["arch"], Usage: "the current platform architecture", }, + cli.StringFlag{ + Name: "namespace", + EnvVar: flagEnvVars["namespace"], + Usage: "a repo namespace to act upon/in", + }, cli.StringSliceFlag{ Name: "constraint", EnvVar: flagEnvVars["constraint"], @@ -156,6 +163,7 @@ func main() { noSortFlag = c.GlobalBool("no-sort") arch = c.GlobalString("arch") + namespace = c.GlobalString("namespace") constraints = c.GlobalStringSlice("constraint") exclusiveConstraints = c.GlobalBool("exclusive-constraints") @@ -189,10 +197,6 @@ func main() { Name: "uniq, unique", Usage: "only act upon the first tag of each entry", }, - "namespace": cli.StringFlag{ - Name: "namespace", - Usage: "a repo namespace to act upon/in", - }, "apply-constraints": cli.BoolFlag{ Name: "apply-constraints", Usage: "apply Constraints as if repos were building", @@ -210,6 +214,10 @@ func main() { Name: "force", Usage: "always push (skip the clever Hub API lookups that no-op things sooner if a push doesn't seem necessary)", }, + "target-namespace": cli.StringFlag{ + Name: "target-namespace", + Usage: `target namespace to act into ("docker tag namespace/repo:tag target-namespace/repo:tag", "docker push target-namespace/repo:tag")`, + }, } app.Commands = []cli.Command{ @@ -239,7 +247,6 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], cli.StringFlag{ Name: "pull", Value: "missing", @@ -257,8 +264,8 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], commonFlags["dry-run"], + commonFlags["target-namespace"], }, Before: subcommandBeforeFactory("tag"), Action: cmdTag, @@ -269,9 +276,9 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], commonFlags["dry-run"], commonFlags["force"], + commonFlags["target-namespace"], }, Before: subcommandBeforeFactory("push"), Action: cmdPush, @@ -281,9 +288,9 @@ func main() { Usage: `update shared tags in the registry (and multi-architecture tags)`, Flags: []cli.Flag{ commonFlags["all"], - commonFlags["namespace"], commonFlags["dry-run"], commonFlags["force"], + commonFlags["target-namespace"], cli.BoolFlag{ Name: "single-arch", Usage: `only act on the current architecture (for pushing "amd64/hello-world:latest", for example)`, diff --git a/go/src/bashbrew/sort.go b/go/src/bashbrew/sort.go index e58e361..006ade7 100644 --- a/go/src/bashbrew/sort.go +++ b/go/src/bashbrew/sort.go @@ -79,7 +79,7 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) { for _, r := range rs { node := r.Identifier() for _, entry := range r.Entries() { - for _, tag := range r.Tags("", false, entry) { + for _, tag := range r.Tags(namespace, false, entry) { if canonicalRepo, ok := canonicalRepos[tag]; ok && canonicalRepo.TagName != "" { // if we run into a duplicate, we want to prefer a specific tag over a full repo continue @@ -114,7 +114,7 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) { } // TODO somehow reconcile/avoid "a:a -> b:b, b:b -> a:c" (which will exhibit here as cyclic) - for _, tag := range r.Tags("", false, entry) { + for _, tag := range r.Tags(namespace, false, entry) { if tagNode, ok := canonicalNodes[tag]; ok { if tagNode == fromNode { // don't be cyclic