Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 384883a

Browse files
rumplsilvin-lubecki
authored andcommitted
Add debug logs (#590)
* Add more logs Fixed some logs that didn't log the error buffer from the invocation image. * Update cnab-to-oci dependency And pass a logger when pushing and pulling Signed-off-by: Djordje Lukic <[email protected]>
1 parent a41ba08 commit 384883a

File tree

21 files changed

+609
-448
lines changed

21 files changed

+609
-448
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/commands_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestDetectApp(t *testing.T) {
183183
cmd.Dir = dir.Join("render")
184184
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
185185
ExitCode: 1,
186-
Err: "Error: multiple applications found in current directory, specify the application name on the command line",
186+
Err: "multiple applications found in current directory, specify the application name on the command line",
187187
})
188188
}
189189

internal/commands/bundle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
dockertypes "github.com/docker/docker/api/types"
2121
"github.com/docker/docker/pkg/jsonmessage"
2222
"github.com/pkg/errors"
23+
"github.com/sirupsen/logrus"
2324
"github.com/spf13/cobra"
2425
)
2526

@@ -88,6 +89,7 @@ func makeBundle(dockerCli command.Cli, appName string, refOverride reference.Nam
8889
}
8990

9091
func makeBundleFromApp(dockerCli command.Cli, app *types.App, refOverride reference.NamedTagged) (*bundle.Bundle, error) {
92+
logrus.Debug("Making app bundle")
9193
meta := app.Metadata()
9294
invocationImageName, err := makeInvocationImageName(meta, refOverride)
9395
if err != nil {
@@ -99,6 +101,7 @@ func makeBundleFromApp(dockerCli command.Cli, app *types.App, refOverride refere
99101
return nil, err
100102
}
101103

104+
logrus.Debugf("Building invocation image %s", invocationImageName)
102105
buildResp, err := dockerCli.Client().ImageBuild(context.TODO(), buildContext, dockertypes.ImageBuildOptions{
103106
Dockerfile: "Dockerfile",
104107
Tags: []string{invocationImageName},

internal/commands/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) erro
3939
return err
4040
}
4141
if err := action.Run(&installation.Claim, nil, nil); err != nil {
42-
return fmt.Errorf("inspect failed: %s", errBuf)
42+
return fmt.Errorf("inspect failed: %s\n%s", err, errBuf)
4343
}
4444
return nil
4545
}

internal/commands/install.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/docker/app/internal/store"
1010
"github.com/docker/cli/cli"
1111
"github.com/docker/cli/cli/command"
12+
"github.com/sirupsen/logrus"
1213
"github.com/spf13/cobra"
1314
)
1415

@@ -91,6 +92,7 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro
9192
if installationName == "" {
9293
installationName = bndl.Name
9394
}
95+
logrus.Debugf(`Looking for a previous installation "%q"`, installationName)
9496
if installation, err := installationStore.Read(installationName); err == nil {
9597
// A failed installation can be overridden, but with a warning
9698
if isInstallationFailed(installation) {
@@ -100,6 +102,8 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro
100102
// their was already a successful installation.
101103
return fmt.Errorf("Installation %q already exists, use 'docker app upgrade' instead", installationName)
102104
}
105+
} else {
106+
logrus.Debug(err)
103107
}
104108
installation, err := store.NewInstallation(installationName, ref)
105109
if err != nil {
@@ -134,7 +138,7 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro
134138
// so any installation needs a clean uninstallation.
135139
err2 := installationStore.Store(installation)
136140
if err != nil {
137-
return fmt.Errorf("Installation failed: %s\n%s", errBuf, err)
141+
return fmt.Errorf("Installation failed: %s\n%s", err, errBuf)
138142
}
139143
if err2 != nil {
140144
return err2

internal/commands/push.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"os"
1010
"strings"
1111

12-
"github.com/containerd/containerd/log"
1312
"github.com/containerd/containerd/platforms"
1413
"github.com/deislabs/cnab-go/bundle"
14+
"github.com/docker/app/internal/log"
1515
"github.com/docker/app/types/metadata"
1616
"github.com/docker/cli/cli"
1717
"github.com/docker/cli/cli/command"
@@ -83,6 +83,7 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
8383
return err
8484
}
8585
if retag.shouldRetag {
86+
logrus.Debugf(`Retagging invocation image "%q"`, retag.invocationImageRef.String())
8687
if err := retagInvocationImage(dockerCli, bndl, retag.invocationImageRef.String()); err != nil {
8788
return err
8889
}
@@ -112,6 +113,7 @@ func resolveReferenceAndBundle(dockerCli command.Cli, name string) (*bundle.Bund
112113
}
113114

114115
func pushInvocationImage(dockerCli command.Cli, retag retagResult) error {
116+
logrus.Debugf("Pushing the invocation image %q", retag.invocationImageRef)
115117
repoInfo, err := registry.ParseRepositoryInfo(retag.invocationImageRef)
116118
if err != nil {
117119
return err
@@ -150,21 +152,15 @@ func pushBundle(dockerCli command.Cli, opts pushOptions, bndl *bundle.Bundle, re
150152
return errors.Wrapf(err, "fixing up %q for push", retag.cnabRef)
151153
}
152154
// push bundle manifest
153-
descriptor, err := remotes.Push(newMuteLogContext(), bndl, retag.cnabRef, resolver, true, withAppAnnotations)
155+
logrus.Debugf("Pushing the bundle %q", retag.cnabRef)
156+
descriptor, err := remotes.Push(log.WithLogContext(context.Background()), bndl, retag.cnabRef, resolver, true, withAppAnnotations)
154157
if err != nil {
155158
return errors.Wrapf(err, "pushing to %q", retag.cnabRef)
156159
}
157160
fmt.Fprintf(os.Stdout, "Successfully pushed bundle to %s. Digest is %s.\n", retag.cnabRef.String(), descriptor.Digest)
158161
return nil
159162
}
160163

161-
func newMuteLogContext() context.Context {
162-
logger := logrus.New()
163-
logger.SetLevel(logrus.ErrorLevel)
164-
logger.SetOutput(ioutil.Discard)
165-
return log.WithLogger(context.Background(), logrus.NewEntry(logger))
166-
}
167-
168164
func withAppAnnotations(index *ocischemav1.Index) error {
169165
if index.Annotations == nil {
170166
index.Annotations = make(map[string]string)

internal/commands/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions) error
6060
installation.Parameters[internal.ParameterRenderFormatName] = opts.formatDriver
6161

6262
if err := action.Run(&installation.Claim, nil, nil); err != nil {
63-
return fmt.Errorf("render failed: %s", errBuf)
63+
return fmt.Errorf("render failed: %s\n%s", err, errBuf)
6464
}
6565
return nil
6666
}

internal/commands/upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func runUpgrade(dockerCli command.Cli, installationName string, opts upgradeOpti
9090
err = u.Run(&installation.Claim, creds, os.Stdout)
9191
err2 := installationStore.Store(installation)
9292
if err != nil {
93-
return fmt.Errorf("Upgrade failed: %s", errBuf)
93+
return fmt.Errorf("Upgrade failed: %s\n%s", err, errBuf)
9494
}
9595
if err2 != nil {
9696
return err2

internal/log/log.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package log
2+
3+
import (
4+
"context"
5+
6+
"github.com/containerd/containerd/log"
7+
"github.com/sirupsen/logrus"
8+
)
9+
10+
func WithLogContext(ctx context.Context) context.Context {
11+
logger := logrus.New()
12+
logger.SetLevel(logrus.GetLevel())
13+
return log.WithLogger(ctx, logrus.NewEntry(logger))
14+
}

internal/packager/cnab.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package packager
22

33
import (
4+
"encoding/json"
5+
46
"github.com/deislabs/cnab-go/bundle"
57
"github.com/deislabs/cnab-go/bundle/definition"
68
"github.com/docker/app/internal"
79
"github.com/docker/app/internal/compose"
810
"github.com/docker/app/types"
11+
"github.com/sirupsen/logrus"
912
)
1013

1114
const (
@@ -120,7 +123,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
120123
return nil, err
121124
}
122125

123-
return &bundle.Bundle{
126+
bndl := &bundle.Bundle{
124127
SchemaVersion: CNABVersion1_0_0,
125128
Credentials: map[string]bundle.Credential{
126129
internal.CredentialDockerContextName: {
@@ -162,7 +165,13 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
162165
},
163166
},
164167
Images: bundleImages,
165-
}, nil
168+
}
169+
170+
if js, err := json.Marshal(bndl); err == nil {
171+
logrus.Debugf("App converted to CNAB %q", string(js))
172+
}
173+
174+
return bndl, nil
166175
}
167176

168177
func extractBundleImages(composeFiles [][]byte) (map[string]bundle.Image, error) {

0 commit comments

Comments
 (0)