Make plugins/kaniko behave the same as plugins/kaniko-{ecr,gcr} by prefixing the registry to the repo (#31)
This commit is contained in:
parent
59e09c14de
commit
39f3398dfe
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -190,7 +191,7 @@ func run(c *cli.Context) error {
|
|||||||
},
|
},
|
||||||
Artifact: kaniko.Artifact{
|
Artifact: kaniko.Artifact{
|
||||||
Tags: c.StringSlice("tags"),
|
Tags: c.StringSlice("tags"),
|
||||||
Repo: c.String("repo"),
|
Repo: buildRepo(c.String("registry"), c.String("repo")),
|
||||||
Registry: c.String("registry"),
|
Registry: c.String("registry"),
|
||||||
ArtifactFile: c.String("artifact-file"),
|
ArtifactFile: c.String("artifact-file"),
|
||||||
RegistryType: artifact.Docker,
|
RegistryType: artifact.Docker,
|
||||||
@ -231,3 +232,17 @@ func createDockerCfgFile(username, password, registry string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildRepo(registry, repo string) string {
|
||||||
|
if registry == "" {
|
||||||
|
// No custom registry, just return the repo name
|
||||||
|
return repo
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(repo, registry + "/") {
|
||||||
|
// Repo already includes the registry prefix
|
||||||
|
// For backward compatibility, we won't add the prefix again.
|
||||||
|
return repo
|
||||||
|
}
|
||||||
|
// Prefix the repo with the registry
|
||||||
|
return registry + "/" + repo
|
||||||
|
}
|
||||||
|
37
cmd/kaniko-docker/main_test.go
Normal file
37
cmd/kaniko-docker/main_test.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func Test_buildRepo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
registry string
|
||||||
|
repo string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "dockerhub",
|
||||||
|
repo: "golang",
|
||||||
|
want: "golang",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "internal",
|
||||||
|
registry: "artifactory.example.com",
|
||||||
|
repo: "service",
|
||||||
|
want: "artifactory.example.com/service",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "backward_compatibility",
|
||||||
|
registry: "artifactory.example.com",
|
||||||
|
repo: "artifactory.example.com/service",
|
||||||
|
want: "artifactory.example.com/service",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := buildRepo(tt.registry, tt.repo); got != tt.want {
|
||||||
|
t.Errorf("buildRepo(%q, %q) = %v, want %v", tt.registry, tt.repo, got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user