Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen-manifests: derrive seedArg from filename and env #4124

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"encoding/json"
"flag"
"fmt"
"hash/fnv"
"io"
"os"
"path/filepath"
"sort"
"strconv"
"strings"

"github.com/osbuild/images/pkg/blueprint"
Expand Down Expand Up @@ -127,6 +129,14 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
filename := fmt.Sprintf("%s-%s-%s-boot.json", u(distroName), u(archName), u(name))
cacheDir := filepath.Join(cacheRoot, archName+distribution.Name())

// ensure that each file has a unique seed based on filename
hash := func(s string) int64 {
h := fnv.New64()
h.Write([]byte(filename))
return int64(h.Sum64())
}
seedArg += hash(filename)

options := distro.ImageOptions{Size: 0}
if cr.OSTree != nil {
options.OSTree = &ostree.ImageOptions{
Expand Down Expand Up @@ -440,6 +450,18 @@ func mergeOverrides(base, overrides composeRequest) composeRequest {
return merged
}

func seedArgFromEnv() (int64, error) {
seedFromEnv := os.Getenv("OSBUILD_GEN_MANIFEST_RNG_SEED")
if seedFromEnv == "" {
return 0, nil
}
seedArg, err := strconv.ParseInt(seedFromEnv, 10, 64)
if err != nil {
return 0, fmt.Errorf("cannot parse env OSBUILD_GEN_MANIFEST_RNG_SEED: %w", err)
}
return seedArg, nil
}

func main() {
// common args
var outputDir, cacheRoot string
Expand All @@ -456,7 +478,10 @@ func main() {

flag.Parse()

seedArg := int64(0)
seedArg, err := seedArgFromEnv()
if err != nil {
panic(err)
}
darm := readRepos()
distroFac := distrofactory.NewDefault()
jobs := make([]manifestJob, 0)
Expand Down