func main()

in scripts/pusher/main.go [38:117]


func main() {
	flag.BoolVar(&dry, "dry-run", false, "dry-run")
	flag.Parse()

	if flag.NArg() < 3 {
		fmt.Println("usage: <manifest> <repo> [tag...]")
		os.Exit(1)
	}

	manifest := flag.Arg(0)
	repo := flag.Arg(1)
	tags := flag.Args()[2:]

	fmt.Println(manifest, repo, tags)

	var m Manifest
	buf, err := os.ReadFile(manifest)
	if err != nil {
		fmt.Printf("error reading manifest: %v", err)
		os.Exit(1)
	}
	if err := json.Unmarshal(buf, &m); err != nil {
		fmt.Printf("error unmarshaling: %v", err)
		os.Exit(1)
	}

	var exports []Export
	images := map[string][]string{}
	for _, tag := range tags {
		tag = strings.TrimSpace(tag)
		if tag == "" {
			continue
		}

		for archive, names := range match(m, tag) {
			// rewrite names
			var taggedNames []string
			for _, name := range names {
				taggedName := strings.ReplaceAll(name, "%", tag)
				taggedNames = append(taggedNames, taggedName)
				exports = append(exports, Export{Type: "Docker image", Value: repo + ":" + taggedName})
			}

			archive = filepath.Join(m.Dir, archive+".tar")
			images[archive] = append(images[archive], taggedNames...)
		}
	}

	// export before we do the work
	pathname := filepath.Join(m.Export, strings.NewReplacer("/", "_", "\\", "_", ".", "_").Replace(manifest+"-"+repo+"-"+strings.Join(tags, "-"))+".json")
	{
		exported, err := json.Marshal(exports)
		if err != nil {
			panic(err)
		}
		os.MkdirAll(m.Export, 0o777)
		if err := os.WriteFile(pathname, exported, 0o600); err != nil {
			fmt.Printf("error writing export: %v", err)
			os.Exit(1)
		}
	}

	now := time.Now()

	wg, ctx := errgroup.WithContext(context.Background())
	wg.SetLimit(8)

	for archive, names := range images {
		wg.Go(func() error {
			return push(ctx, archive, repo, names)
		})
	}

	if err := wg.Wait(); err != nil {
		fmt.Printf("error pushing: %v", err)
		os.Exit(1)
	}

	fmt.Printf("done in %v, export %v\n", time.Since(now), pathname)
}