Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit 98b221e

Browse files
committed
Use first squashed layer, then first from
If you were using a squashed base layer, the default insertion point wasn't what it would be expected to be.
1 parent 1d7c9f7 commit 98b221e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

export.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,30 @@ func (e *Export) ExtractLayers() error {
237237
return nil
238238
}
239239

240-
func (e *Export) FirstFrom() *ExportedImage {
240+
func (e *Export) firstLayer(pattern string) *ExportedImage {
241241
root := e.Root()
242242
for {
243243
if root == nil {
244244
break
245245
}
246246

247247
cmd := strings.Join(root.LayerConfig.ContainerConfig.Cmd, " ")
248-
if strings.Contains(cmd, "#(nop) ADD file") {
248+
if strings.Contains(cmd, pattern) {
249249
break
250250
}
251251
root = e.ChildOf(root.LayerConfig.Id)
252252
}
253253
return root
254254
}
255255

256+
func (e *Export) FirstFrom() *ExportedImage {
257+
return e.firstLayer("#(nop) ADD file")
258+
}
259+
260+
func (e *Export) FirstSquash() *ExportedImage {
261+
return e.firstLayer("#(squash)")
262+
}
263+
256264
// Root returns the top layer in the export
257265
func (e *Export) Root() *ExportedImage {
258266
return e.ChildOf("")

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ func main() {
9595

9696
}
9797

98-
start := export.FirstFrom()
98+
start := export.FirstSquash()
99+
// Can't find a previously squashed layer, use first FROM
100+
if start == nil {
101+
start = export.FirstFrom()
102+
}
99103
// Can't find a FROM, default to root
100104
if start == nil {
101105
start = export.Root()

0 commit comments

Comments
 (0)