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

Commit 72b27fc

Browse files
author
Jean-Christophe Sirot
committed
Makes the interpolation of parameters containing special characters (. and -) not allowed by
the original compose file format more robust. Docker App is now using 2 different regexps when parsing a .dockerapp file and processing a compose file to generate a .dockerapp Signed-off-by: Jean-Christophe Sirot <[email protected]>
1 parent 8d52f6d commit 72b27fc

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

e2e/commands_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) {
8282
}
8383
}
8484

85+
func TestRenderParametersWithSpecialChars(t *testing.T) {
86+
cmd, cleanup := dockerCli.createTestCmd()
87+
defer cleanup()
88+
dir := fs.NewDir(t, "")
89+
defer dir.Remove()
90+
91+
appPath := filepath.Join("testdata", "parameters-with-special-chars")
92+
cmd.Command = dockerCli.Command("app", "render", filepath.Join(appPath, "my.dockerapp"))
93+
result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
94+
golden.Assert(t, result.Stdout(), filepath.Join("parameters-with-special-chars", "expected.golden"))
95+
}
8596
func TestRenderFormatters(t *testing.T) {
8697
cmd, cleanup := dockerCli.createTestCmd()
8798
defer cleanup()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3.0"
2+
services:
3+
test:
4+
command:
5+
- echo
6+
- brave
7+
- gnu
8+
- world
9+
image: alpine:latest
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 0.1.0
2+
name: myapp
3+
maintainers:
4+
- name: dev
5+
6+
---
7+
version: "3.0"
8+
services:
9+
test:
10+
image: alpine:latest
11+
command: echo ${texts.first} ${texts.second-1} ${texts.second-2}
12+
---
13+
texts:
14+
first: "brave"
15+
second-1: "gnu"
16+
second-2: "world"

internal/compose/compose.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ import (
1212
)
1313

1414
const (
15-
delimiter = "\\$"
16-
substitution = "[_a-z][._a-z0-9]*(?::?[-?][^}]*)?"
15+
delimiter = "\\$"
16+
substitution = "[_a-z][._a-z0-9-]*"
17+
composeSubstitution = "[_a-z][._a-z0-9]*(?::?[-?][^}]*)?"
1718
)
1819

1920
var (
2021
patternString = fmt.Sprintf(
2122
"%s(?i:(?P<escaped>%s)|(?P<named>%s)|{(?P<braced>%s)}|(?P<invalid>))",
2223
delimiter, delimiter, substitution, substitution,
2324
)
25+
composePatternString = fmt.Sprintf(
26+
"%s(?i:(?P<escaped>%s)|(?P<named>%s)|{(?P<braced>%s)}|(?P<invalid>))",
27+
delimiter, delimiter, composeSubstitution, composeSubstitution,
28+
)
2429
// ExtrapolationPattern is the variable regexp pattern used to interpolate or extract variables when rendering
2530
ExtrapolationPattern = regexp.MustCompile(patternString)
31+
// ComposeExtrapolationPattern is the compose original variable regexp pattern used to interpolate or extract
32+
// variables when rendering. This pattern is only used when a docherapp file is initialized from a compose file
33+
ComposeExtrapolationPattern = regexp.MustCompile(composePatternString)
2634
)
2735

2836
// Load applies the specified function when loading a slice of compose data

internal/packager/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func initFromComposeFile(name string, composeFile string) error {
148148
}
149149
}
150150
}
151-
vars, err := compose.ExtractVariables(composeRaw, compose.ExtrapolationPattern)
151+
vars, err := compose.ExtractVariables(composeRaw, compose.ComposeExtrapolationPattern)
152152
if err != nil {
153153
return errors.Wrap(err, "failed to parse compose file")
154154
}

internal/packager/init_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ services:
5252
image: image1
5353
ports:
5454
- ${ports.service1:-9001}
55-
5655
service2:
5756
image: image2
5857
ports:

0 commit comments

Comments
 (0)