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

Commit

Permalink
Use first squashed layer, then first from
Browse files Browse the repository at this point in the history
If you were using a squashed base layer, the default insertion
point wasn't what it would be expected to be.
  • Loading branch information
jwilder committed Aug 20, 2014
1 parent 1d7c9f7 commit 98b221e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,30 @@ 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 {
break
}

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)
}
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("")
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 98b221e

Please sign in to comment.