diff --git a/export.go b/export.go index 34af934..00dc135 100644 --- a/export.go +++ b/export.go @@ -237,7 +237,7 @@ func (e *Export) ExtractLayers() error { return nil } -func (e *Export) FirstFrom() *ExportedImage { +func (e *Export) firstLayer(pattern string) *ExportedImage { root := e.Root() for { if root == nil { @@ -245,7 +245,7 @@ func (e *Export) FirstFrom() *ExportedImage { } cmd := strings.Join(root.LayerConfig.ContainerConfig.Cmd, " ") - if strings.Contains(cmd, "#(nop) ADD file") { + if strings.Contains(cmd, pattern) { break } root = e.ChildOf(root.LayerConfig.Id) @@ -253,6 +253,14 @@ func (e *Export) FirstFrom() *ExportedImage { return root } +func (e *Export) FirstFrom() *ExportedImage { + return e.firstLayer("#(nop) ADD file") +} + +func (e *Export) FirstSquash() *ExportedImage { + return e.firstLayer("#(squash)") +} + // Root returns the top layer in the export func (e *Export) Root() *ExportedImage { return e.ChildOf("") diff --git a/main.go b/main.go index d334b55..6a7e37d 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,11 @@ func main() { } - start := export.FirstFrom() + start := export.FirstSquash() + // Can't find a previously squashed layer, use first FROM + if start == nil { + start = export.FirstFrom() + } // Can't find a FROM, default to root if start == nil { start = export.Root()