Skip to content

Commit

Permalink
Merge pull request buildpacks#314 from buildpack/verbose
Browse files Browse the repository at this point in the history
Add verbose option
  • Loading branch information
ekcasey authored Sep 26, 2019
2 parents 3512dfa + 42683be commit 91c44c9
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 69 deletions.
1 change: 1 addition & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S, builder, runImageMirro
cmdArgs := append([]string{
name,
"--no-color",
"--verbose",
}, args...)
cmd := exec.Command(
packPath,
Expand Down
4 changes: 2 additions & 2 deletions app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (i *Image) Run(ctx context.Context, docker *client.Client, ports []string)
ctx,
docker,
ctr.ID,
logging.GetDebugWriter(i.Logger),
logging.GetDebugErrorWriter(i.Logger),
logging.GetInfoWriter(i.Logger),
logging.GetInfoErrorWriter(i.Logger),
); err != nil {
return errors.Wrap(err, "run container")
}
Expand Down
16 changes: 9 additions & 7 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Lifecycle struct {
httpProxy string
httpsProxy string
noProxy string
version string
LayersVolume string
AppVolume string
}
Expand Down Expand Up @@ -72,37 +73,37 @@ func (l *Lifecycle) Execute(ctx context.Context, opts LifecycleOptions) error {
l.logger.Debugf("Build cache %s cleared", style.Symbol(buildCache.Name()))
}

l.logger.Debug(style.Step("DETECTING"))
l.logger.Info(style.Step("DETECTING"))
if err := l.Detect(ctx); err != nil {
return err
}

l.logger.Debug(style.Step("RESTORING"))
l.logger.Info(style.Step("RESTORING"))
if opts.ClearCache {
l.logger.Debug("Skipping 'restore' due to clearing cache")
l.logger.Info("Skipping 'restore' due to clearing cache")
} else {
if err := l.Restore(ctx, buildCache.Name()); err != nil {
return err
}
}

l.logger.Debug(style.Step("ANALYZING"))
l.logger.Info(style.Step("ANALYZING"))
if err := l.Analyze(ctx, opts.Image.Name(), opts.Publish, opts.ClearCache); err != nil {
return err
}

l.logger.Debug(style.Step("BUILDING"))
l.logger.Info(style.Step("BUILDING"))
if err := l.Build(ctx); err != nil {
return err
}

l.logger.Debug(style.Step("EXPORTING"))
l.logger.Info(style.Step("EXPORTING"))
launchCacheName := launchCache.Name()
if err := l.Export(ctx, opts.Image.Name(), opts.RunImage, opts.Publish, launchCacheName); err != nil {
return err
}

l.logger.Debug(style.Step("CACHING"))
l.logger.Info(style.Step("CACHING"))
if err := l.Cache(ctx, buildCache.Name()); err != nil {
return err
}
Expand All @@ -118,6 +119,7 @@ func (l *Lifecycle) Setup(opts LifecycleOptions) {
l.httpProxy = opts.HTTPProxy
l.httpsProxy = opts.HTTPSProxy
l.noProxy = opts.NoProxy
l.version = opts.Builder.GetLifecycleDescriptor().Info.Version.String()
}

func (l *Lifecycle) Cleanup() error {
Expand Down
4 changes: 2 additions & 2 deletions build/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func (p *Phase) Run(ctx context.Context) error {
ctx,
p.docker,
p.ctr.ID,
logging.NewPrefixWriter(logging.GetDebugWriter(p.logger), p.name),
logging.NewPrefixWriter(logging.GetDebugErrorWriter(p.logger), p.name),
logging.NewPrefixWriter(logging.GetInfoWriter(p.logger), p.name),
logging.NewPrefixWriter(logging.GetInfoErrorWriter(p.logger), p.name),
)
}

Expand Down
66 changes: 46 additions & 20 deletions build/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package build
import (
"context"
"fmt"

"github.com/Masterminds/semver"
)

const (
Expand All @@ -17,8 +19,10 @@ func (l *Lifecycle) Detect(ctx context.Context) error {
detect, err := l.NewPhase(
"detector",
WithArgs(
"-app", appDir,
"-platform", platformDir,
l.withLogLevel(
"-app", appDir,
"-platform", platformDir,
)...,
),
)
if err != nil {
Expand All @@ -33,8 +37,10 @@ func (l *Lifecycle) Restore(ctx context.Context, cacheName string) error {
"restorer",
WithDaemonAccess(),
WithArgs(
"-path", cacheDir,
"-layers", layersDir,
l.withLogLevel(
"-path", cacheDir,
"-layers", layersDir,
)...,
),
WithBinds(fmt.Sprintf("%s:%s", cacheName, cacheDir)),
)
Expand Down Expand Up @@ -73,10 +79,14 @@ func (l *Lifecycle) newAnalyze(repoName string, publish, clearCache bool) (*Phas
return l.NewPhase(
"analyzer",
WithDaemonAccess(),
WithArgs(prependArg(
"-daemon",
args,
)...),
WithArgs(
l.withLogLevel(
prependArg(
"-daemon",
args,
)...,
)...,
),
)
}

Expand Down Expand Up @@ -115,10 +125,12 @@ func (l *Lifecycle) newExport(repoName, runImage string, publish bool, launchCac
"exporter",
WithRegistryAccess(repoName, runImage),
WithArgs(
"-image", runImage,
"-layers", layersDir,
"-app", appDir,
repoName,
l.withLogLevel(
"-image", runImage,
"-layers", layersDir,
"-app", appDir,
repoName,
)...,
),
)
}
Expand All @@ -127,12 +139,14 @@ func (l *Lifecycle) newExport(repoName, runImage string, publish bool, launchCac
"exporter",
WithDaemonAccess(),
WithArgs(
"-image", runImage,
"-layers", layersDir,
"-app", appDir,
"-daemon",
"-launch-cache", launchCacheDir,
repoName,
l.withLogLevel(
"-image", runImage,
"-layers", layersDir,
"-app", appDir,
"-daemon",
"-launch-cache", launchCacheDir,
repoName,
)...,
),
WithBinds(fmt.Sprintf("%s:%s", launchCacheName, launchCacheDir)),
)
Expand All @@ -143,8 +157,10 @@ func (l *Lifecycle) Cache(ctx context.Context, cacheName string) error {
"cacher",
WithDaemonAccess(),
WithArgs(
"-path", cacheDir,
"-layers", layersDir,
l.withLogLevel(
"-path", cacheDir,
"-layers", layersDir,
)...,
),
WithBinds(fmt.Sprintf("%s:%s", cacheName, cacheDir)),
)
Expand All @@ -154,3 +170,13 @@ func (l *Lifecycle) Cache(ctx context.Context, cacheName string) error {
defer cache.Cleanup()
return cache.Run(ctx)
}

func (l *Lifecycle) withLogLevel(args ...string) []string {
version := semver.MustParse(l.version)
if semver.MustParse("0.4.0").LessThan(version) {
if l.logger.IsVerbose() {
return append(args, "-log-level", "debug")
}
}
return args
}
12 changes: 5 additions & 7 deletions build/testdata/fake-lifecycle/go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module step

require (
github.com/buildpack/lifecycle v0.0.0-20190131183901-e63977609a26
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v0.7.3-0.20181027010111-b8e87cfdad8d
github.com/google/go-containerregistry v0.0.0-20190206233756-dbc4da98389f
github.com/pkg/errors v0.8.1 // indirect
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/buildpack/lifecycle v0.4.1-0.20190923204251-11f83ef99246
github.com/docker/docker v0.7.3-0.20190307005417-54dddadc7d5d
github.com/google/go-containerregistry v0.0.0-20190503220729-1c6c7f61e8a5
github.com/gorilla/context v1.1.1 // indirect
)

go 1.13
Loading

0 comments on commit 91c44c9

Please sign in to comment.