This repository was archived by the owner on Jan 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ import (
9
9
"github.com/moby/buildkit/frontend/dockerfile/parser"
10
10
)
11
11
12
+ // Represents info about a heredoc.
13
+ type Heredoc struct {
14
+ Name string
15
+ FileDescriptor uint
16
+ Content string
17
+ }
18
+
12
19
// Represents a single line (layer) in a Dockerfile.
13
20
// For example `FROM ubuntu:xenial`
14
21
type Command struct {
@@ -20,6 +27,7 @@ type Command struct {
20
27
EndLine int // The original source line number which ends this command
21
28
Flags []string // Any flags such as `--from=...` for `COPY`.
22
29
Value []string // The contents of the command (ex: `ubuntu:xenial`)
30
+ Heredocs []Heredoc // Extra heredoc content attachments
23
31
}
24
32
25
33
// A failure in opening a file for reading.
@@ -88,6 +96,9 @@ func ParseReader(file io.Reader) ([]Command, error) {
88
96
for _ , heredoc := range child .Heredocs {
89
97
cmd .Original = cmd .Original + heredoc .Content + heredoc .Name + "\n "
90
98
cmd .Value = append (cmd .Value , heredoc .Content )
99
+ cmd .Heredocs = append (cmd .Heredocs , Heredoc {Name : heredoc .Name ,
100
+ FileDescriptor : heredoc .FileDescriptor ,
101
+ Content : heredoc .Content })
91
102
}
92
103
}
93
104
Original file line number Diff line number Diff line change 134
134
EndLine : 5 ,
135
135
Flags : []string {},
136
136
Value : []string {"source $HOME/.bashrc && echo $HOME\n echo \" Hello\" >> /hello\n echo \" World!\" >> /hello\n " },
137
+ Heredocs : []Heredoc {Heredoc {Name : "EOF" ,
138
+ FileDescriptor : 0 ,
139
+ Content : "source $HOME/.bashrc && echo $HOME\n echo \" Hello\" >> /hello\n echo \" World!\" >> /hello\n " },
140
+ },
137
141
},
138
142
}
139
143
assert .Equal (t , expected , cmds )
@@ -156,6 +160,13 @@ FILE2
156
160
EndLine : 5 ,
157
161
Flags : []string {},
158
162
Value : []string {"content 1\n " , "content 2\n " },
163
+ Heredocs : []Heredoc {Heredoc {Name : "FILE1" ,
164
+ FileDescriptor : 0 ,
165
+ Content : "content 1\n " },
166
+ Heredoc {Name : "FILE2" ,
167
+ FileDescriptor : 0 ,
168
+ Content : "content 2\n " },
169
+ },
159
170
},
160
171
}
161
172
assert .Equal (t , expected , cmds )
You can’t perform that action at this time.
0 commit comments