Skip to content

Commit 2bf0c15

Browse files
jbadeauclaude
andcommitted
fix: use jib-compatible ${param} syntax for template parameters
Changes $${param} to ${param} to match Jib CLI's template parameter syntax. Escaped parameters use $${param} to produce literal ${param}. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7a9beaa commit 2bf0c15

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

gib/buildfile/parse.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,19 @@ func validateOctalPermissions(perm, field string) error {
174174
return nil
175175
}
176176

177-
// substituteParams replaces $${paramName} with values from the params map.
178-
// Escaped $$$${...} produces a literal $${...}.
177+
// substituteParams replaces ${paramName} with values from the params map.
178+
// Compatible with Jib CLI template parameter syntax.
179+
// Escaped $${...} produces a literal ${...}.
179180
func substituteParams(content string, params map[string]string) (string, error) {
180-
if len(params) == 0 && !strings.Contains(content, "$${") {
181+
if len(params) == 0 && !strings.Contains(content, "${") {
181182
return content, nil
182183
}
183184

184185
var result strings.Builder
185186
i := 0
186187
for i < len(content) {
187-
// Look for $${
188-
idx := strings.Index(content[i:], "$${")
188+
// Look for ${
189+
idx := strings.Index(content[i:], "${")
189190
if idx == -1 {
190191
result.WriteString(content[i:])
191192
break
@@ -194,15 +195,15 @@ func substituteParams(content string, params map[string]string) (string, error)
194195
// Write everything before the match
195196
result.WriteString(content[i : i+idx])
196197

197-
// Check for escaped $$$${
198+
// Check for escaped $${
198199
if idx > 0 && content[i+idx-1] == '$' {
199-
// This is an escaped $$$${...} -> produce literal $${...}
200+
// This is an escaped $${...} -> produce literal ${...}
200201
// Remove the extra $ we already wrote
201202
s := result.String()
202203
result.Reset()
203204
result.WriteString(s[:len(s)-1]) // remove trailing $
204-
result.WriteString("$${")
205-
i = i + idx + 3
205+
result.WriteString("${")
206+
i = i + idx + 2
206207
// Find closing }
207208
end := strings.Index(content[i:], "}")
208209
if end == -1 {
@@ -214,7 +215,7 @@ func substituteParams(content string, params map[string]string) (string, error)
214215
}
215216

216217
// Find closing }
217-
paramStart := i + idx + 3
218+
paramStart := i + idx + 2
218219
end := strings.Index(content[paramStart:], "}")
219220
if end == -1 {
220221
return "", fmt.Errorf("unclosed template parameter at position %d", i+idx)

gib/buildfile/parse_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,29 @@ func TestSubstituteParams_NoParams(t *testing.T) {
138138
}
139139

140140
func TestSubstituteParams_SingleParam(t *testing.T) {
141-
result, err := substituteParams("image: $${name}", map[string]string{"name": "alpine"})
141+
result, err := substituteParams("image: ${name}", map[string]string{"name": "alpine"})
142142
require.NoError(t, err)
143143
assert.Equal(t, "image: alpine", result)
144144
}
145145

146146
func TestSubstituteParams_MultipleParams(t *testing.T) {
147-
result, err := substituteParams("$${a}:$${b}", map[string]string{"a": "x", "b": "y"})
147+
result, err := substituteParams("${a}:${b}", map[string]string{"a": "x", "b": "y"})
148148
require.NoError(t, err)
149149
assert.Equal(t, "x:y", result)
150150
}
151151

152152
func TestSubstituteParams_UnclosedBrace(t *testing.T) {
153-
_, err := substituteParams("$${unclosed", nil)
153+
_, err := substituteParams("${unclosed", nil)
154154
require.Error(t, err)
155155
assert.Contains(t, err.Error(), "unclosed")
156156
}
157157

158+
func TestSubstituteParams_EscapedParam(t *testing.T) {
159+
result, err := substituteParams("literal: $${name}", map[string]string{"name": "alpine"})
160+
require.NoError(t, err)
161+
assert.Equal(t, "literal: ${name}", result)
162+
}
163+
158164
// --- Validation tests ported from Jib's BuildFileSpecTest ---
159165

160166
func TestParseBytes_EmptyAPIVersion(t *testing.T) {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: jib/v1alpha1
22
kind: BuildFile
33
from:
4-
image: "$${baseImage}"
4+
image: "${baseImage}"
55
environment:
6-
VERSION: "$${version}"
7-
user: "$${user}"
6+
VERSION: "${version}"
7+
user: "${user}"

0 commit comments

Comments
 (0)