Skip to content

Instantly share code, notes, and snippets.

@srabraham
Last active March 23, 2023 12:25
Show Gist options
  • Save srabraham/52e65ea37db5580a091334e3d065fed9 to your computer and use it in GitHub Desktop.
Save srabraham/52e65ea37db5580a091334e3d065fed9 to your computer and use it in GitHub Desktop.
2023-03-23 Docker auth config for testcontainers-go.go - for https://github.com/VideoAmp/central/pull/3743/files
// Before: construct RegistryCred as JSON+base64-encoded string,
// and supply that via GenericContainerRequest
authConfig := struct {
Username string `json:"username"`
Password string `json:"password"`
}{
"MyDockerHubUsername",
"MyDockerHubPassword",
}
encodedJSON, _ := json.Marshal(authConfig)
testcontainers.GenericContainerRequest{
...
RegistryCred: base64.URLEncoding.EncodeToString(encodedJSON),
}
// After: construct dockercfg.Config, then JSON-encode it,
// then set it as bytes as an env var prior to invoking
// your GenericContainerRequest
//
// import "github.com/cpuguy83/dockercfg"
dockerAuthConfig := dockercfg.Config{
AuthConfigs: map[string]dockercfg.AuthConfig{
"https://index.docker.io/v1/": {
Username: "MyDockerHubUsername",
Password: "MyDockerHubPassword",
},
},
}
b, _ := json.Marshal(o.dockerAuthConfig)
_ = os.Setenv("DOCKER_AUTH_CONFIG", string(b))
testcontainers.GenericContainerRequest{
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment