Skip to content

Commit 4b42bfd

Browse files
committed
dockerfile: implement additional expansions
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
1 parent 4ee0d8a commit 4b42bfd

9 files changed

Lines changed: 314 additions & 42 deletions

File tree

rhel/dockerfile/generate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dockerfile
2+
3+
//go:generate -command stringer go run golang.org/x/tools/cmd/stringer
4+
//go:generate stringer -type itemKind
5+
//go:generate stringer -type varExpand -linecomment

rhel/dockerfile/lex.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ type item struct {
5858

5959
type itemKind int
6060

61-
//go:generate -command stringer go run golang.org/x/tools/cmd/stringer
62-
//go:generate stringer -type itemKind
63-
6461
const (
6562
itemError itemKind = iota
6663
itemComment
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
error: dockerfile: bad expansion of "error": rogue colon
2+
-- Dockerfile --
3+
LABEL a ${error::}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Dockerfile --
2+
LABEL a ${unset}
3+
LABEL b ${unset=set}
4+
LABEL c ${unset}
5+
6+
LABEL null=
7+
LABEL d ${null:=reset}
8+
-- Want --
9+
{
10+
"a": "",
11+
"b": "set",
12+
"c": "set",
13+
"d": "reset",
14+
"null": ""
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
error: dockerfile: bad expansion of "unset": should error (error if unset or null)
2+
-- Dockerfile --
3+
LABEL a ${unset:?should error}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Dockerfile --
2+
ARG a=\"
3+
ARG a=\'
4+
ARG a=\\
5+
ARG a=\b
6+
LABEL s='single\' quote: \\\b' d="double\" quote: \\\b\e"
7+
-- Want --
8+
{
9+
"s": "single' quote: \\\\b",
10+
"d": "double\" quote: \\\b\\e"
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- Dockerfile --
2+
ARG null=''
3+
LABEL dash_a ${unset-default}
4+
LABEL dash_b ${unset:-default}
5+
LABEL dash_c ${null-default}
6+
LABEL dash_d ${null:-default}
7+
LABEL plus_a ${unset+default}
8+
LABEL plus_b ${unset:+default}
9+
LABEL plus_c ${null+default}
10+
LABEL plus_d ${null:+default}
11+
12+
ARG var=some-pattern.
13+
LABEL prefix ${var#*e}
14+
LABEL greedyprefix ${var##*e}
15+
LABEL suffix ${var%e*.}
16+
LABEL greedysuffix ${var%%e*.}
17+
LABEL singlechar ${var%?}
18+
LABEL greedysinglechar ${var%%?}
19+
LABEL noreplace ${var#\?}
20+
-- Want --
21+
{
22+
"dash_a": "default",
23+
"dash_b": "default",
24+
"dash_c": "",
25+
"dash_d": "default",
26+
"plus_a": "",
27+
"plus_b": "",
28+
"plus_c": "default",
29+
"plus_d": "",
30+
"prefix": "-pattern.",
31+
"greedyprefix": "rn.",
32+
"suffix": "some-patt",
33+
"greedysuffix": "som",
34+
"singlechar": "some-pattern",
35+
"greedysinglechar": "some-pattern",
36+
"noreplace": "some-pattern."
37+
}

rhel/dockerfile/varexpand_string.go

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

0 commit comments

Comments
 (0)