diff --git a/pkg/dashboard/gitops/helper.go b/pkg/dashboard/gitops/helper.go index b918c2058..7071b4557 100644 --- a/pkg/dashboard/gitops/helper.go +++ b/pkg/dashboard/gitops/helper.go @@ -385,51 +385,14 @@ func ExtractImageStrategy(envConfig *dx.Manifest) string { return "dynamic" } - image := envConfig.Values["image"] - hasVariable := false - pointsToBuiltInRegistry := false - hasDockerfile := false - - if image != nil { + if image, ok := envConfig.Values["image"]; ok { imageMap := image.(map[string]interface{}) - - var repository, tag, dockerfile string - if val, ok := imageMap["repository"]; ok { - repository = val.(string) - } - if val, ok := imageMap["tag"]; ok { - tag = val.(string) - } - if val, ok := imageMap["dockerfile"]; ok { - dockerfile = val.(string) - } - - if strings.Contains(repository, "{{") || - strings.Contains(tag, "{{") { - hasVariable = true - } - if strings.Contains(repository, "127.0.0.1:32447") { - pointsToBuiltInRegistry = true - } - if dockerfile != "" { - hasDockerfile = true - } - } - - strategy := "static" - if hasVariable { - if pointsToBuiltInRegistry { - if hasDockerfile { - strategy = "dockerfile" - } else { - strategy = "buildpacks" - } - } else { - strategy = "dynamic" + if strategy, ok := imageMap["strategy"]; ok { + return strategy.(string) } } - return strategy + return "dynamic" } func ExtractImageRepoTagAndDockerfile(envConfig *dx.Manifest, vars map[string]string) (string, string, string) { diff --git a/pkg/dashboard/gitops/helper_test.go b/pkg/dashboard/gitops/helper_test.go index 18ea98512..55ee6a1e7 100644 --- a/pkg/dashboard/gitops/helper_test.go +++ b/pkg/dashboard/gitops/helper_test.go @@ -164,6 +164,20 @@ func initHistory() *git.Repository { return repo } +/* +static-site + +static +dynamic (artifact) + +image: + repository: + tag: + dockerfile: + startegy: dynamic(default)/static/dockerfile/buildpacks + +*/ + func Test_ExtractImageStrategy(t *testing.T) { strategy := ExtractImageStrategy(&dx.Manifest{}) assert.Equal(t, "dynamic", strategy) @@ -174,7 +188,7 @@ func Test_ExtractImageStrategy(t *testing.T) { Name: "onechart", }, }) - assert.Equal(t, "static", strategy) + assert.Equal(t, "dynamic", strategy) strategy = ExtractImageStrategy(&dx.Manifest{ Chart: dx.Chart{ @@ -185,6 +199,7 @@ func Test_ExtractImageStrategy(t *testing.T) { "image": map[string]interface{}{ "repository": "nginx", "tag": "1.19", + "strategy": "static", //breaking change }, }, }) @@ -221,8 +236,25 @@ func Test_ExtractImageStrategy(t *testing.T) { "image": map[string]interface{}{ "repository": "127.0.0.1:32447", "tag": "{{ .SHA }}", + "strategy": "buildpacks", //breaking change }, }, }) assert.Equal(t, "buildpacks", strategy) + + strategy = ExtractImageStrategy(&dx.Manifest{ + Chart: dx.Chart{ + Repository: "repository: https://chart.onechart.dev", + Name: "onechart", + }, + Values: map[string]interface{}{ + "image": map[string]interface{}{ + "repository": "127.0.0.1:32447", + "tag": "{{ .SHA }}", + "dockerfile": "Dockerfile", + "strategy": "dockerfile", + }, + }, + }) + assert.Equal(t, "dockerfile", strategy) }