Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 0b92d64

Browse files
author
Vincent Demeester
authored
Merge pull request #335 from vdemeester/fix-helm-generation
Fix helm generation
2 parents 23bdc1e + f33314d commit 0b92d64

7 files changed

Lines changed: 75 additions & 53 deletions

File tree

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/commands_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ func TestHelmBinary(t *testing.T) {
240240
chart, _ := ioutil.ReadFile(dir.Join("helm.chart/Chart.yaml"))
241241
values, _ := ioutil.ReadFile(dir.Join("helm.chart/values.yaml"))
242242
stack, _ := ioutil.ReadFile(dir.Join("helm.chart/templates/stack.yaml"))
243-
golden.Assert(t, string(chart), "helm-expected.chart/Chart.yaml")
244-
golden.Assert(t, string(values), "helm-expected.chart/values.yaml")
245-
golden.Assert(t, string(stack), "helm-expected.chart/templates/stack.yaml")
243+
golden.Assert(t, string(chart), "helm-expected.chart/Chart.yaml", "chart file is wrong")
244+
golden.Assert(t, string(values), "helm-expected.chart/values.yaml", "values file is wrong")
245+
golden.Assert(t, string(stack), "helm-expected.chart/templates/stack.yaml", "stack file is wrong")
246246
}
247247

248248
func TestHelmV1Beta1Binary(t *testing.T) {
@@ -252,9 +252,9 @@ func TestHelmV1Beta1Binary(t *testing.T) {
252252
chart, _ := ioutil.ReadFile(dir.Join("helm.chart/Chart.yaml"))
253253
values, _ := ioutil.ReadFile(dir.Join("helm.chart/values.yaml"))
254254
stack, _ := ioutil.ReadFile(dir.Join("helm.chart/templates/stack.yaml"))
255-
golden.Assert(t, string(chart), "helm-expected.chart/Chart.yaml")
256-
golden.Assert(t, string(values), "helm-expected.chart/values.yaml")
257-
golden.Assert(t, string(stack), "helm-expected.chart/templates/stack-v1beta1.yaml")
255+
golden.Assert(t, string(chart), "helm-expected.chart/Chart.yaml", "chart file is wrong")
256+
golden.Assert(t, string(values), "helm-expected.chart/values.yaml", "values file is wrong")
257+
golden.Assert(t, string(stack), "helm-expected.chart/templates/stack-v1beta1.yaml", "stack file is wrong")
258258
}
259259

260260
func TestHelmInvalidStackVersionBinary(t *testing.T) {

internal/helm/helm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ with the appropriate content (value or template)
4444
*/
4545

4646
// Helm renders an app as an Helm Chart
47-
func Helm(appname string, composeFiles []string, settingsFile []string, env map[string]string, render bool, stackVersion string) error {
47+
func Helm(appname string, composeFiles []string, settingsFile []string, env map[string]string, shouldRender bool, stackVersion string) error {
4848
targetDir := internal.AppNameFromDir(appname) + ".chart"
4949
if err := os.MkdirAll(targetDir, 0755); err != nil {
5050
return errors.Wrap(err, "failed to create Chart directory")
@@ -53,7 +53,7 @@ func Helm(appname string, composeFiles []string, settingsFile []string, env map[
5353
if err != nil {
5454
return err
5555
}
56-
if render {
56+
if shouldRender {
5757
return helmRender(appname, targetDir, composeFiles, settingsFile, env, stackVersion)
5858
}
5959
data, err := ioutil.ReadFile(filepath.Join(appname, internal.ComposeFileName))
@@ -64,7 +64,7 @@ func Helm(appname string, composeFiles []string, settingsFile []string, env map[
6464
if err != nil {
6565
return errors.Wrap(err, "failed to parse compose file")
6666
}
67-
vars := template.ExtractVariables(cfgMap)
67+
vars := template.ExtractVariables(cfgMap, render.Pattern)
6868
// FIXME(vdemeester): remove the need to create this slice
6969
variables := []string{}
7070
for k := range vars {

internal/packager/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"text/template"
1313

1414
"github.com/docker/app/internal"
15+
"github.com/docker/app/internal/render"
1516
"github.com/docker/app/internal/types"
1617
"github.com/docker/cli/cli/compose/loader"
1718
dtemplate "github.com/docker/cli/cli/compose/template"
@@ -128,7 +129,7 @@ func initFromComposeFile(name string, composeFile string) error {
128129
}
129130
}
130131
}
131-
vars := dtemplate.ExtractVariables(cfgMap)
132+
vars := dtemplate.ExtractVariables(cfgMap, render.Pattern)
132133
needsFilling := false
133134
for k, v := range vars {
134135
if _, ok := settings[k]; !ok {

internal/render/render.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ var (
3434
delimiter, delimiter, substitution, substitution,
3535
)
3636

37-
pattern = regexp.MustCompile(patternString)
37+
// Pattern is the variable regexp pattern used to interpolate or extract variables when rendering
38+
Pattern = regexp.MustCompile(patternString)
3839
)
3940

4041
// Render renders the Compose file for this app, merging in settings files, other compose files, and env
@@ -109,7 +110,7 @@ func render(configFiles []composetypes.ConfigFile, finalEnv map[string]string) (
109110
}
110111

111112
func substitute(template string, mapping composetemplate.Mapping) (string, error) {
112-
return composetemplate.SubstituteWith(template, mapping, pattern, errorIfMissing)
113+
return composetemplate.SubstituteWith(template, mapping, Pattern, errorIfMissing)
113114
}
114115

115116
func errorIfMissing(substitution string, mapping composetemplate.Mapping) (string, bool, error) {

vendor/github.com/docker/cli/cli/command/stack/cmd.go

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/cli/cli/compose/template/template.go

Lines changed: 47 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)