Skip to content

Commit

Permalink
add support for docker complaint registries for base image (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
raghavharness authored Feb 23, 2023
1 parent 447ee28 commit 4893b5b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/kaniko-ecr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func main() {
Value: "Dockerfile",
EnvVar: "PLUGIN_DOCKERFILE",
},
cli.StringFlag{
Name: "docker-registry",
Usage: "docker registry",
EnvVar: "PLUGIN_DOCKER_REGISTRY,DOCKER_REGISTRY",
},
cli.StringFlag{
Name: "docker-username",
Usage: "docker username",
Expand Down Expand Up @@ -242,6 +247,7 @@ func run(c *cli.Context) error {
noPush := c.Bool("no-push")

dockerConfig, err := createDockerConfig(
c.String("docker-registry"),
c.String("docker-username"),
c.String("docker-password"),
c.String("access-key"),
Expand Down Expand Up @@ -328,12 +334,16 @@ func run(c *cli.Context) error {
return plugin.Exec()
}

func createDockerConfig(dockerUsername, dockerPassword, accessKey, secretKey,
func createDockerConfig(dockerRegistry, dockerUsername, dockerPassword, accessKey, secretKey,
registry, assumeRole, externalId, region string, noPush bool) (*docker.Config, error) {
dockerConfig := docker.NewConfig()

if dockerUsername != "" {
dockerConfig.SetAuth(docker.RegistryV1, dockerUsername, dockerPassword)
// if no docker registry provided, use dockerhub by default
if len(dockerRegistry) == 0 {
dockerRegistry = docker.RegistryV1
}
dockerConfig.SetAuth(dockerRegistry, dockerUsername, dockerPassword)
}

if assumeRole != "" {
Expand Down
28 changes: 28 additions & 0 deletions cmd/kaniko-ecr/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

func TestCreateDockerConfig(t *testing.T) {
got, err := createDockerConfig(
"",
"docker-username",
"docker-password",
"access-key",
Expand All @@ -34,10 +35,37 @@ func TestCreateDockerConfig(t *testing.T) {
}
}

func TestCreateDockerConfigFromGivenRegistry(t *testing.T) {
got, err := createDockerConfig(
"docker-registry",
"docker-username",
"docker-password",
"access-key",
"secret-key",
"ecr-registry",
"",
"",
"",
false,
)
if err != nil {
t.Error("failed to create docker config")
}

want := docker.NewConfig()
want.SetAuth("docker-registry", "docker-username", "docker-password")
want.SetCredHelper(docker.RegistryECRPublic, "ecr-login")
want.SetCredHelper("ecr-registry", "ecr-login")
if !reflect.DeepEqual(want, got) {
t.Errorf("not equal:\n want: %#v\n got: %#v", want, got)
}
}

func TestCreateDockerConfigKanikoOneDotEight(t *testing.T) {
os.Setenv(kanikoVersionEnv, "1.8.1")
defer os.Setenv(kanikoVersionEnv, "")
got, err := createDockerConfig(
"",
"docker-username",
"docker-password",
"access-key",
Expand Down

0 comments on commit 4893b5b

Please sign in to comment.