From bc4037dd683282f8538df225b2f06737a34fafd6 Mon Sep 17 00:00:00 2001 From: Giuseppe Valente Date: Fri, 7 Jun 2019 15:14:22 -0700 Subject: [PATCH 1/3] bashbrew: account for namespaces when sorting repos --- go/src/bashbrew/cmd-build.go | 6 +++--- go/src/bashbrew/cmd-list.go | 6 +++--- go/src/bashbrew/main.go | 1 + go/src/bashbrew/sort.go | 22 ++++++++++++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/go/src/bashbrew/cmd-build.go b/go/src/bashbrew/cmd-build.go index b40d774..35fd186 100644 --- a/go/src/bashbrew/cmd-build.go +++ b/go/src/bashbrew/cmd-build.go @@ -12,13 +12,13 @@ func cmdBuild(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err) } - repos, err = sortRepos(repos, true) + namespace := c.String("namespace") + repos, err = sortRepos(repos, true, namespace) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err) } uniq := c.Bool("uniq") - namespace := c.String("namespace") pull := c.String("pull") switch pull { case "always", "missing", "never": @@ -34,7 +34,7 @@ func cmdBuild(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err) } - entries, err := r.SortedEntries(true) + entries, err := r.SortedEntries(true, namespace) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err) } diff --git a/go/src/bashbrew/cmd-list.go b/go/src/bashbrew/cmd-list.go index 13cf2fd..2598c6b 100644 --- a/go/src/bashbrew/cmd-list.go +++ b/go/src/bashbrew/cmd-list.go @@ -14,13 +14,13 @@ func cmdList(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := "" + namespace := c.String("namespace") applyConstraints := c.Bool("apply-constraints") onlyRepos := c.Bool("repos") buildOrder := c.Bool("build-order") if buildOrder { - repos, err = sortRepos(repos, applyConstraints) + repos, err = sortRepos(repos, applyConstraints, namespace) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err) } @@ -45,7 +45,7 @@ func cmdList(c *cli.Context) error { var entries []*manifest.Manifest2822Entry if buildOrder { - entries, err = r.SortedEntries(applyConstraints) + entries, err = r.SortedEntries(applyConstraints, namespace) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err) } diff --git a/go/src/bashbrew/main.go b/go/src/bashbrew/main.go index 5382e51..d3b3549 100644 --- a/go/src/bashbrew/main.go +++ b/go/src/bashbrew/main.go @@ -220,6 +220,7 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], + commonFlags["namespace"], commonFlags["apply-constraints"], cli.BoolFlag{ Name: "build-order", diff --git a/go/src/bashbrew/sort.go b/go/src/bashbrew/sort.go index e58e361..9be4719 100644 --- a/go/src/bashbrew/sort.go +++ b/go/src/bashbrew/sort.go @@ -5,7 +5,7 @@ import ( "pault.ag/go/topsort" ) -func sortRepos(repos []string, applyConstraints bool) ([]string, error) { +func sortRepos(repos []string, applyConstraints bool, namespace string) ([]string, error) { rs := []*Repo{} rsMap := map[*Repo]string{} for _, repo := range repos { @@ -26,7 +26,7 @@ func sortRepos(repos []string, applyConstraints bool) ([]string, error) { return repos, nil } - rs, err := sortRepoObjects(rs, applyConstraints) + rs, err := sortRepoObjects(rs, applyConstraints, namespace) if err != nil { return nil, err } @@ -38,7 +38,7 @@ func sortRepos(repos []string, applyConstraints bool) ([]string, error) { return ret, nil } -func (r Repo) SortedEntries(applyConstraints bool) ([]*manifest.Manifest2822Entry, error) { +func (r Repo) SortedEntries(applyConstraints bool, namespace string) ([]*manifest.Manifest2822Entry, error) { entries := r.Entries() // short circuit if we don't have to go further @@ -52,7 +52,7 @@ func (r Repo) SortedEntries(applyConstraints bool) ([]*manifest.Manifest2822Entr rs = append(rs, r.EntryRepo(entries[i])) } - rs, err := sortRepoObjects(rs, applyConstraints) + rs, err := sortRepoObjects(rs, applyConstraints, namespace) if err != nil { return nil, err } @@ -64,7 +64,14 @@ func (r Repo) SortedEntries(applyConstraints bool) ([]*manifest.Manifest2822Entr return ret, nil } -func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) { +func addNamespace(namespace, tag string) string { + if namespace != "" { + tag = namespace + "/" + tag + } + return tag +} + +func sortRepoObjects(rs []*Repo, applyConstraints bool, namespace string) ([]*Repo, error) { // short circuit if we don't have to go further if noSortFlag || len(rs) <= 1 { return rs, nil @@ -79,12 +86,13 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) { for _, r := range rs { node := r.Identifier() for _, entry := range r.Entries() { + node = addNamespace(namespace, node) for _, tag := range r.Tags("", false, entry) { + tag = addNamespace(namespace, tag) 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 } - canonicalNodes[tag] = node canonicalRepos[tag] = r } @@ -115,6 +123,8 @@ 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) { + tag = addNamespace(namespace, tag) + if tagNode, ok := canonicalNodes[tag]; ok { if tagNode == fromNode { // don't be cyclic From 40295572447baac7e095058c0996c171b349f881 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 13 Jun 2019 16:54:00 -0700 Subject: [PATCH 2/3] Make "--namespace" a global parameter that affects every command (and add "--target-namespace" to "bashbrew tag") --- go/src/bashbrew/cmd-build.go | 5 ++--- go/src/bashbrew/cmd-cat.go | 3 +++ go/src/bashbrew/cmd-deps.go | 6 +++--- go/src/bashbrew/cmd-from.go | 1 - go/src/bashbrew/cmd-list.go | 5 ++--- go/src/bashbrew/cmd-push.go | 1 - go/src/bashbrew/cmd-put-shared.go | 1 - go/src/bashbrew/cmd-tag.go | 14 ++++++++----- go/src/bashbrew/config.go | 10 +++++----- go/src/bashbrew/main.go | 33 +++++++++++++++++-------------- go/src/bashbrew/sort.go | 26 ++++++++---------------- 11 files changed, 50 insertions(+), 55 deletions(-) diff --git a/go/src/bashbrew/cmd-build.go b/go/src/bashbrew/cmd-build.go index 35fd186..f2b9104 100644 --- a/go/src/bashbrew/cmd-build.go +++ b/go/src/bashbrew/cmd-build.go @@ -12,8 +12,7 @@ func cmdBuild(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err) } - namespace := c.String("namespace") - repos, err = sortRepos(repos, true, namespace) + repos, err = sortRepos(repos, true) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err) } @@ -34,7 +33,7 @@ func cmdBuild(c *cli.Context) error { return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err) } - entries, err := r.SortedEntries(true, namespace) + entries, err := r.SortedEntries(true) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err) } 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 2598c6b..8a73efa 100644 --- a/go/src/bashbrew/cmd-list.go +++ b/go/src/bashbrew/cmd-list.go @@ -14,13 +14,12 @@ func cmdList(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := c.String("namespace") applyConstraints := c.Bool("apply-constraints") onlyRepos := c.Bool("repos") buildOrder := c.Bool("build-order") if buildOrder { - repos, err = sortRepos(repos, applyConstraints, namespace) + repos, err = sortRepos(repos, applyConstraints) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err) } @@ -45,7 +44,7 @@ func cmdList(c *cli.Context) error { var entries []*manifest.Manifest2822Entry if buildOrder { - entries, err = r.SortedEntries(applyConstraints, namespace) + entries, err = r.SortedEntries(applyConstraints) if err != nil { return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err) } diff --git a/go/src/bashbrew/cmd-push.go b/go/src/bashbrew/cmd-push.go index f118836..87948bf 100644 --- a/go/src/bashbrew/cmd-push.go +++ b/go/src/bashbrew/cmd-push.go @@ -16,7 +16,6 @@ func cmdPush(c *cli.Context) error { } uniq := c.Bool("uniq") - namespace := c.String("namespace") dryRun := c.Bool("dry-run") force := c.Bool("force") diff --git a/go/src/bashbrew/cmd-put-shared.go b/go/src/bashbrew/cmd-put-shared.go index 57aa6c2..51b2631 100644 --- a/go/src/bashbrew/cmd-put-shared.go +++ b/go/src/bashbrew/cmd-put-shared.go @@ -83,7 +83,6 @@ 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") force := c.Bool("force") singleArch := c.Bool("single-arch") diff --git a/go/src/bashbrew/cmd-tag.go b/go/src/bashbrew/cmd-tag.go index f7d9ae7..05f16a7 100644 --- a/go/src/bashbrew/cmd-tag.go +++ b/go/src/bashbrew/cmd-tag.go @@ -14,12 +14,15 @@ 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 { r, err := fetch(repo) @@ -33,12 +36,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 d3b3549..86cf181 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", @@ -220,7 +224,6 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], commonFlags["apply-constraints"], cli.BoolFlag{ Name: "build-order", @@ -240,7 +243,6 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], cli.StringFlag{ Name: "pull", Value: "missing", @@ -258,8 +260,11 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], commonFlags["dry-run"], + cli.StringFlag{ + Name: "target-namespace", + Usage: `target namespace to tag into ("docker tag namespace/repo:tag target-namespace/repo:tag")`, + }, }, Before: subcommandBeforeFactory("tag"), Action: cmdTag, @@ -270,7 +275,6 @@ func main() { Flags: []cli.Flag{ commonFlags["all"], commonFlags["uniq"], - commonFlags["namespace"], commonFlags["dry-run"], commonFlags["force"], }, @@ -282,7 +286,6 @@ 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"], cli.BoolFlag{ diff --git a/go/src/bashbrew/sort.go b/go/src/bashbrew/sort.go index 9be4719..006ade7 100644 --- a/go/src/bashbrew/sort.go +++ b/go/src/bashbrew/sort.go @@ -5,7 +5,7 @@ import ( "pault.ag/go/topsort" ) -func sortRepos(repos []string, applyConstraints bool, namespace string) ([]string, error) { +func sortRepos(repos []string, applyConstraints bool) ([]string, error) { rs := []*Repo{} rsMap := map[*Repo]string{} for _, repo := range repos { @@ -26,7 +26,7 @@ func sortRepos(repos []string, applyConstraints bool, namespace string) ([]strin return repos, nil } - rs, err := sortRepoObjects(rs, applyConstraints, namespace) + rs, err := sortRepoObjects(rs, applyConstraints) if err != nil { return nil, err } @@ -38,7 +38,7 @@ func sortRepos(repos []string, applyConstraints bool, namespace string) ([]strin return ret, nil } -func (r Repo) SortedEntries(applyConstraints bool, namespace string) ([]*manifest.Manifest2822Entry, error) { +func (r Repo) SortedEntries(applyConstraints bool) ([]*manifest.Manifest2822Entry, error) { entries := r.Entries() // short circuit if we don't have to go further @@ -52,7 +52,7 @@ func (r Repo) SortedEntries(applyConstraints bool, namespace string) ([]*manifes rs = append(rs, r.EntryRepo(entries[i])) } - rs, err := sortRepoObjects(rs, applyConstraints, namespace) + rs, err := sortRepoObjects(rs, applyConstraints) if err != nil { return nil, err } @@ -64,14 +64,7 @@ func (r Repo) SortedEntries(applyConstraints bool, namespace string) ([]*manifes return ret, nil } -func addNamespace(namespace, tag string) string { - if namespace != "" { - tag = namespace + "/" + tag - } - return tag -} - -func sortRepoObjects(rs []*Repo, applyConstraints bool, namespace string) ([]*Repo, error) { +func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) { // short circuit if we don't have to go further if noSortFlag || len(rs) <= 1 { return rs, nil @@ -86,13 +79,12 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool, namespace string) ([]*Re for _, r := range rs { node := r.Identifier() for _, entry := range r.Entries() { - node = addNamespace(namespace, node) - for _, tag := range r.Tags("", false, entry) { - tag = addNamespace(namespace, tag) + 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 } + canonicalNodes[tag] = node canonicalRepos[tag] = r } @@ -122,9 +114,7 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool, namespace string) ([]*Re } // 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) { - tag = addNamespace(namespace, tag) - + for _, tag := range r.Tags(namespace, false, entry) { if tagNode, ok := canonicalNodes[tag]; ok { if tagNode == fromNode { // don't be cyclic From c922da004c7a4f1673d907e6de46aab8247df754 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 14 Jun 2019 16:35:27 -0700 Subject: [PATCH 3/3] Add "--target-namespace" to both "push" and "put-shared" and make "tag" more intuitive --- go/src/bashbrew/cmd-push.go | 10 +++++++--- go/src/bashbrew/cmd-put-shared.go | 10 +++++++--- go/src/bashbrew/cmd-tag.go | 3 --- go/src/bashbrew/main.go | 11 +++++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/go/src/bashbrew/cmd-push.go b/go/src/bashbrew/cmd-push.go index 87948bf..d6f7c64 100644 --- a/go/src/bashbrew/cmd-push.go +++ b/go/src/bashbrew/cmd-push.go @@ -16,11 +16,15 @@ func cmdPush(c *cli.Context) error { } uniq := c.Bool("uniq") + 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 { @@ -29,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 51b2631..edb3a65 100644 --- a/go/src/bashbrew/cmd-put-shared.go +++ b/go/src/bashbrew/cmd-put-shared.go @@ -84,11 +84,15 @@ func cmdPutShared(c *cli.Context) error { } 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 { @@ -97,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 05f16a7..87d408b 100644 --- a/go/src/bashbrew/cmd-tag.go +++ b/go/src/bashbrew/cmd-tag.go @@ -17,9 +17,6 @@ func cmdTag(c *cli.Context) error { 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"`) } diff --git a/go/src/bashbrew/main.go b/go/src/bashbrew/main.go index 86cf181..27c65a1 100644 --- a/go/src/bashbrew/main.go +++ b/go/src/bashbrew/main.go @@ -214,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{ @@ -261,10 +265,7 @@ func main() { commonFlags["all"], commonFlags["uniq"], commonFlags["dry-run"], - cli.StringFlag{ - Name: "target-namespace", - Usage: `target namespace to tag into ("docker tag namespace/repo:tag target-namespace/repo:tag")`, - }, + commonFlags["target-namespace"], }, Before: subcommandBeforeFactory("tag"), Action: cmdTag, @@ -277,6 +278,7 @@ func main() { commonFlags["uniq"], commonFlags["dry-run"], commonFlags["force"], + commonFlags["target-namespace"], }, Before: subcommandBeforeFactory("push"), Action: cmdPush, @@ -288,6 +290,7 @@ func main() { commonFlags["all"], 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)`,