feat(clustertool): Add support for autoconfiguring DockerHub credentials

This commit is contained in:
Kjeld Schouten
2024-10-19 14:08:44 +02:00
parent d5bbc600ca
commit 0d1548d1bc
2 changed files with 49 additions and 1 deletions
@@ -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
+44
View File
@@ -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 {