Skip to content

Commit

Permalink
Skip restore and analyze when clearing cache
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Romero <j.romero.1214@gmail.com>
  • Loading branch information
jromero committed Apr 1, 2019
1 parent 69a8484 commit 289060a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
output = h.Run(t, cmd)
h.AssertContains(t, output, fmt.Sprintf("Successfully built image '%s'", repoName))

t.Log("doesn't restore the cache")
h.AssertContains(t, output, "nothing to restore")
t.Log("skips restore")
h.AssertContains(t, output, "Skipping 'restore' due to clearing cache")

t.Log("skips analyze")
h.AssertContains(t, output, "Skipping 'analyze' due to clearing cache")

t.Log("exporter reuses unchanged layers")
h.AssertContainsMatch(t, output, `\[exporter] reusing layer 'io.buildpacks.samples.nodejs:nodejs'`)
Expand Down
14 changes: 10 additions & 4 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,20 @@ func (b *BuildConfig) Run(ctx context.Context) error {
}

b.Logger.Verbose(style.Step("RESTORING"))
if err := b.restore(ctx, lifecycle); err != nil {
if b.ClearCache {
b.Logger.Verbose("Skipping 'restore' due to clearing cache")
} else if err := b.restore(ctx, lifecycle); err != nil {
return err
}

b.Logger.Verbose(style.Step("ANALYZING"))
b.Logger.Verbose("Reading information from previous image for possible re-use")
if err := b.analyze(ctx, lifecycle); err != nil {
return err
if b.ClearCache {
b.Logger.Verbose("Skipping 'analyze' due to clearing cache")
} else {
b.Logger.Verbose("Reading information from previous image for possible re-use")
if err := b.analyze(ctx, lifecycle); err != nil {
return err
}
}

b.Logger.Verbose(style.Step("BUILDING"))
Expand Down

0 comments on commit 289060a

Please sign in to comment.