An example of copying docker image, with simple username password, between two registries with crane
.
Use multiple keychain and implement KeyChain
interface
func (obj MyOjbect) Resolve(target authn.Resource) (authn.Authenticator, error) {
reg := target.RegistryStr()
if strings.Contains(src url, reg) {
return &authn.Basic{
Username: src username,
Password: src password,
}, nil
} else {
return &authn.Basic{
Username: dest username,
Password: dest password,
}, nil
}
}
func main() {
_ = crane.Copy(src url, dest url, crane.WithAuthFromKeychain(obj))
}
authn
readme: google/go-containerregistry/pkg/authn- Exmaple of copying to AWS ECR with helper: ekirmayer/aws-lambda-copy-container-image-to-ecr