testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

[Feature]: RegistryCred multiple private registry credentials support

Open szaher opened this issue 3 years ago • 1 comments

Problem

At the moment testcontainers supports providing registry credentials via RegistryCred in ContainerRequest but this is problematic when using multiple private docker registries specially with multi-stage docker files.


FROM ACCOUNT1.dkr.ecr.us-east-1.amazonaws.com/myimages/app:v1.0
FROM ACCOUNT2.dkr.ecr.us-west-2.amazonaws.com/mirror/alpine:4.0.0 as curl

RUN apk add --no-cache --update curl

FROM curl as curl_container
ENV GRPC_HEALTH_PROBE_VERSION v0.2.2
RUN curl -fsSL https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 -o /grpc_health_probe \
  && chmod +x /grpc_health_probe


Solution

RegistryCred parameter's type in the container request can be map[string]map[string]string

var registryCreds map[string]map[string]string
registryCreds["ACCOUNT1.dkr.ecr.us-east-1.amazonaws.com"] = map[string]string{"username": "Saad", "password": "123"}

or

import types
func GetRegistryCreds() {
	var registryCreds map[string]types.AuthConfig

	auth1 := types.AuthConfig{
		Username: "Saad",
		Password: "2407",
	}
	registryCreds["ACCOUNT1.dkr.ecr.us-east-1.amazonaws.com"] = auth1
	
	auth2 := types.AuthConfig{
		Username:      "User2",
		Password:      "1808",
	}
	registryCreds["ACCOUNT2.dkr.ecr.us-west-2.amazonaws.com"] = auth2
}


Benefit

It enables support for multiple private registries

Alternatives

user must have all his/her images on private repo

Would you like to help contributing this feature?

Yes

szaher avatar Sep 16 '22 16:09 szaher

@szaher do you think that the work in https://github.com/testcontainers/testcontainers-go/pull/869 can close this issue? Now that the docker auth is transparently obtained from the credential helpers, it's totally possible to have multiple credentials. Wdyt?

mdelapenya avatar May 26 '23 07:05 mdelapenya

Given the docker auth credentials are now obtained from the helpers, I'd say it's fine to close this one.

Please reopen it if you consider it's not fixed. Thanks in advance 🙇

mdelapenya avatar Apr 22 '24 15:04 mdelapenya