Making prepend of registry url to repo name optional (#48)
This commit is contained in:
parent
ea64d40995
commit
c39a1155b5
@ -75,6 +75,11 @@ func main() {
|
||||
EnvVar: "PLUGIN_TAGS",
|
||||
FilePath: ".tags",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "expand-repo",
|
||||
Usage: "Prepends the registry url to the repo if registry url is not specified in repo name",
|
||||
EnvVar: "PLUGIN_EXPAND_REPO",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "expand-tag",
|
||||
Usage: "enable for semver tagging",
|
||||
@ -206,13 +211,13 @@ func run(c *cli.Context) error {
|
||||
ExpandTag: c.Bool("expand-tag"),
|
||||
Args: c.StringSlice("args"),
|
||||
Target: c.String("target"),
|
||||
Repo: buildRepo(c.String("registry"), c.String("repo")),
|
||||
Repo: buildRepo(c.String("registry"), c.String("repo"), c.Bool("expand-repo")),
|
||||
Mirrors: c.StringSlice("registry-mirrors"),
|
||||
Labels: c.StringSlice("custom-labels"),
|
||||
SkipTlsVerify: c.Bool("skip-tls-verify"),
|
||||
SnapshotMode: c.String("snapshot-mode"),
|
||||
EnableCache: c.Bool("enable-cache"),
|
||||
CacheRepo: buildRepo(c.String("registry"), c.String("cache-repo")),
|
||||
CacheRepo: buildRepo(c.String("registry"), c.String("cache-repo"), c.Bool("expand-repo")),
|
||||
CacheTTL: c.Int("cache-ttl"),
|
||||
DigestFile: defaultDigestFile,
|
||||
NoPush: noPush,
|
||||
@ -221,7 +226,7 @@ func run(c *cli.Context) error {
|
||||
},
|
||||
Artifact: kaniko.Artifact{
|
||||
Tags: c.StringSlice("tags"),
|
||||
Repo: buildRepo(c.String("registry"), c.String("repo")),
|
||||
Repo: buildRepo(c.String("registry"), c.String("repo"), c.Bool("expand-repo")),
|
||||
Registry: c.String("registry"),
|
||||
ArtifactFile: c.String("artifact-file"),
|
||||
RegistryType: artifact.Docker,
|
||||
@ -263,8 +268,8 @@ func createDockerCfgFile(username, password, registry string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildRepo(registry, repo string) string {
|
||||
if registry == "" || registry == v1RegistryURL {
|
||||
func buildRepo(registry, repo string, expandRepo bool) string {
|
||||
if !expandRepo || registry == "" || registry == v1RegistryURL {
|
||||
// No custom registry, just return the repo name
|
||||
return repo
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func Test_buildRepo(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := buildRepo(tt.registry, tt.repo); got != tt.want {
|
||||
if got := buildRepo(tt.registry, tt.repo, true); 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