浏览代码

Merge pull request #3442 from infosiftr/put-shared-single-arch

Add a "--single-arch" flag to "put-shared" for pushing SharedTags to architecture-specific namespaces
yosifkit 8 年之前
父节点
当前提交
37efc7aace
共有 2 个文件被更改,包括 29 次插入20 次删除
  1. 24 19
      bashbrew/go/src/bashbrew/cmd-put-shared.go
  2. 5 1
      bashbrew/go/src/bashbrew/main.go

+ 24 - 19
bashbrew/go/src/bashbrew/cmd-put-shared.go

@@ -12,25 +12,29 @@ import (
 	"github.com/docker-library/go-dockerlibrary/manifest"
 )
 
-func entriesToManifestToolYaml(r Repo, entries ...*manifest.Manifest2822Entry) (string, time.Time, error) {
+func entriesToManifestToolYaml(singleArch bool, r Repo, entries ...*manifest.Manifest2822Entry) (string, time.Time, error) {
 	yaml := ""
 	mru := time.Time{}
 	entryIdentifiers := []string{}
 	for _, entry := range entries {
 		entryIdentifiers = append(entryIdentifiers, r.EntryIdentifier(*entry))
 
-		for _, arch := range entry.Architectures {
+		for _, entryArch := range entry.Architectures {
+			if singleArch && entryArch != arch {
+				continue
+			}
+
 			var ok bool
 
 			var ociArch architecture.OCIPlatform
-			if ociArch, ok = architecture.SupportedArches[arch]; !ok {
+			if ociArch, ok = architecture.SupportedArches[entryArch]; !ok {
 				// this should never happen -- the parser validates Architectures
-				panic("somehow, an unsupported architecture slipped past the parser validation: " + arch)
+				panic("somehow, an unsupported architecture slipped past the parser validation: " + entryArch)
 			}
 
 			var archNamespace string
-			if archNamespace, ok = archNamespaces[arch]; !ok || archNamespace == "" {
-				fmt.Fprintf(os.Stderr, "warning: no arch-namespace specified for %q; skipping (%q)\n", arch, r.EntryIdentifier(*entry))
+			if archNamespace, ok = archNamespaces[entryArch]; !ok || archNamespace == "" {
+				fmt.Fprintf(os.Stderr, "warning: no arch-namespace specified for %q; skipping (%q)\n", entryArch, r.EntryIdentifier(*entry))
 				continue
 			}
 
@@ -48,9 +52,6 @@ func entriesToManifestToolYaml(r Repo, entries ...*manifest.Manifest2822Entry) (
 			}
 		}
 	}
-	if yaml == "" {
-		return "", time.Time{}, fmt.Errorf("failed gathering images for creating %q", entryIdentifiers)
-	}
 
 	return "manifests:\n" + yaml, mru, nil
 }
@@ -74,6 +75,7 @@ func cmdPutShared(c *cli.Context) error {
 
 	namespace := c.String("namespace")
 	dryRun := c.Bool("dry-run")
+	singleArch := c.Bool("single-arch")
 
 	if namespace == "" {
 		return fmt.Errorf(`"--namespace" is a required flag for "put-shared"`)
@@ -87,15 +89,18 @@ func cmdPutShared(c *cli.Context) error {
 
 		targetRepo := path.Join(namespace, r.RepoName)
 
-		// handle all multi-architecture tags first (regardless of whether they have SharedTags)
-		// turn them into SharedTagGroup objects so all manifest-tool invocations can be handled by a single process/loop
 		sharedTagGroups := []manifest.SharedTagGroup{}
-		for _, entry := range r.Entries() {
-			entryCopy := entry
-			sharedTagGroups = append(sharedTagGroups, manifest.SharedTagGroup{
-				SharedTags: entry.Tags,
-				Entries:    []*manifest.Manifest2822Entry{&entryCopy},
-			})
+
+		if !singleArch {
+			// handle all multi-architecture tags first (regardless of whether they have SharedTags)
+			// turn them into SharedTagGroup objects so all manifest-tool invocations can be handled by a single process/loop
+			for _, entry := range r.Entries() {
+				entryCopy := entry
+				sharedTagGroups = append(sharedTagGroups, manifest.SharedTagGroup{
+					SharedTags: entry.Tags,
+					Entries:    []*manifest.Manifest2822Entry{&entryCopy},
+				})
+			}
 		}
 
 		// TODO do something smarter with r.TagName (ie, the user has done something crazy like "bashbrew put-shared single-repo:single-tag")
@@ -110,7 +115,7 @@ func cmdPutShared(c *cli.Context) error {
 		}
 
 		for _, group := range sharedTagGroups {
-			yaml, mostRecentPush, err := entriesToManifestToolYaml(*r, group.Entries...)
+			yaml, mostRecentPush, err := entriesToManifestToolYaml(singleArch, *r, group.Entries...)
 			if err != nil {
 				return err
 			}
@@ -121,7 +126,7 @@ func cmdPutShared(c *cli.Context) error {
 				hubMeta := fetchDockerHubTagMeta(image)
 				tagUpdated := hubMeta.lastUpdatedTime()
 				if mostRecentPush.After(tagUpdated) ||
-					(len(hubMeta.Images) <= 1 &&
+					(!singleArch && len(hubMeta.Images) <= 1 &&
 						(len(group.Entries) > 1 || len(group.Entries[0].Architectures) > 1)) {
 					tagsToPush = append(tagsToPush, tag)
 				} else {

+ 5 - 1
bashbrew/go/src/bashbrew/main.go

@@ -269,11 +269,15 @@ func main() {
 		},
 		{
 			Name:  "put-shared",
-			Usage: `updated shared tags in the registry`,
+			Usage: `update shared tags in the registry (and multi-architecture tags)`,
 			Flags: []cli.Flag{
 				commonFlags["all"],
 				commonFlags["namespace"],
 				commonFlags["dry-run"],
+				cli.BoolFlag{
+					Name:  "single-arch",
+					Usage: `only act on the current architecture (for pushing "amd64/hello-world:latest", for example)`,
+				},
 			},
 			Before: subcommandBeforeFactory("put-shared"),
 			Action: cmdPutShared,