func createManifest()

in pkg/rbeconfigsgen/rbeconfigsgen.go [942:971]


func createManifest(o *Options) error {
	if len(o.OutputManifest) == 0 {
		return nil
	}
	m := Manifest{
		BazelVersion:       o.BazelVersion,
		ToolchainContainer: o.ToolchainContainer,
		ExecOS:             o.PlatformParams.OSFamily,
	}
	// Extract the sha256 digest from the image name to be included in the manifest.
	s := imageDigestRegexp.FindStringSubmatch(o.PlatformParams.ToolchainContainer)
	if len(s) != 2 {
		return fmt.Errorf("failed to extract sha256 digest using regex from image name %q, got %d substrings, want 2", o.PlatformParams.ToolchainContainer, len(s))
	}
	m.ImageDigest = s[1]
	// Include the sha256 digest of the configs tarball if output tarball generation was enabled by
	// actually hashing the contents of the output tarball.
	if len(o.OutputTarball) != 0 {
		d, err := digestFile(o.OutputTarball)
		if err != nil {
			return fmt.Errorf("unable to compute the sha256 digest of the output tarball file for the output manifest: %w", err)
		}
		m.ConfigsTarballDigest = d
	}
	if err := m.ToJSONFile(o.OutputManifest); err != nil {
		return fmt.Errorf("error writing manifest file: %w", err)
	}
	log.Printf("Wrote JSON manifest to %q.", o.OutputManifest)
	return nil
}