diff --git a/clustertool/embed/generic/base/clusterenv.yaml b/clustertool/embed/generic/base/clusterenv.yaml index c5e138dfc1d..f48b615ae06 100644 --- a/clustertool/embed/generic/base/clusterenv.yaml +++ b/clustertool/embed/generic/base/clusterenv.yaml @@ -12,6 +12,10 @@ DASHBOARD_IP: 192.168.20.211 # Used to automatically generate a sshkey-pair for FluxCD # Has to start with ssh:// GITHUB_REPOSITORY: "" -# DO NOT ALTER +## Uncomment and adapt to automatically setup your dockerhub credentials +## This should prevent much of the potential ratelimits +# DOCKERHUB_USER: dockerhub-username +# DOCKERHUB_PASSWORD: dockerhub-password +## DO NOT ALTER PODNET: 172.16.0.0/16 SVCNET: 172.17.0.0/16 diff --git a/clustertool/pkg/initfiles/initfiles.go b/clustertool/pkg/initfiles/initfiles.go index 817ac478fb5..27250101a49 100644 --- a/clustertool/pkg/initfiles/initfiles.go +++ b/clustertool/pkg/initfiles/initfiles.go @@ -274,6 +274,50 @@ func GenPatches() error { log.Fatal().Err(err).Msg("Error: %s") } + // Assuming this is part of your function + if helper.TalEnv["DOCKERHUB_USER"] != "" && helper.TalEnv["DOCKERHUB_PASSWORD"] != "" { + // Prepare the content to append + configContent := fmt.Sprintf(`# Add Dockerhub Login +- operation: replace + path: /machine/registries/config/registry-1.docker.io + value: + auth: + username: %s + password: %s +- operation: replace + path: /machine/registries/config/docker.io + value: + auth: + username: %s + password: %s +`, helper.TalEnv["DOCKERHUB_USER"], helper.TalEnv["DOCKERHUB_PASSWORD"], helper.TalEnv["DOCKERHUB_USER"], helper.TalEnv["DOCKERHUB_PASSWORD"]) + + // Open the file in append mode or create it if it doesn't exist + file, err := os.OpenFile(filepath.Join(helper.ClusterPath+"/talos/patches", "all.yaml"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Fatal().Err(err).Msg("Error opening file: %s") + } + defer file.Close() + + // Write the content to the file + if _, err := file.Write([]byte(configContent)); err != nil { + log.Fatal().Err(err).Msg("Error writing to file: %s") + } + } else { + // Optional: Append a note if the environment variables are not set + emptyContent := `# No DockerHub credentials provided +` + file, err := os.OpenFile(filepath.Join(helper.ClusterPath+"/talos/patches", "all.yaml"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Fatal().Err(err).Msg("Error opening file: %s") + } + defer file.Close() + + if _, err := file.Write([]byte(emptyContent)); err != nil { + log.Fatal().Err(err).Msg("Error writing to file: %s") + } + } + // Read the content of the talenv.yaml file talenvContent, err := os.ReadFile(helper.ClusterPath + "/clusterenv.yaml") if err != nil {