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

Commit c6102cc

Browse files
Merge pull request #660 from rumpl/feat-inspect
Add a json output as default for app inspect
2 parents 5dbe6f4 + bd3038c commit c6102cc

20 files changed

Lines changed: 476 additions & 125 deletions

e2e/commands_test.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,38 +144,33 @@ maintainers:
144144
golden.Assert(t, stdOut, "validate-output.golden")
145145
}
146146

147-
func TestDetectApp(t *testing.T) {
147+
func TestInspectApp(t *testing.T) {
148148
cmd, cleanup := dockerCli.createTestCmd()
149149
defer cleanup()
150150

151151
// cwd = e2e
152152
dir := fs.NewDir(t, "detect-app-binary",
153-
fs.WithDir("attachments.dockerapp", fs.FromDir("testdata/attachments.dockerapp")),
154-
fs.WithDir("render",
155-
fs.WithDir("app1.dockerapp", fs.FromDir("testdata/render/envvariables/my.dockerapp")),
156-
fs.WithDir("app2.dockerapp", fs.FromDir("testdata/render/envvariables/my.dockerapp")),
157-
),
158-
)
153+
fs.WithDir("attachments.dockerapp", fs.FromDir("testdata/attachments.dockerapp")))
159154
defer dir.Remove()
160155

161-
cmd.Command = dockerCli.Command("app", "inspect")
162-
cmd.Dir = dir.Path()
163-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
164-
165-
cmd.Command = dockerCli.Command("app", "inspect")
166-
cmd.Dir = dir.Join("attachments.dockerapp")
167-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
168-
169-
cmd.Command = dockerCli.Command("app", "inspect", ".")
170-
cmd.Dir = dir.Join("attachments.dockerapp")
171-
icmd.RunCmd(cmd).Assert(t, icmd.Success)
156+
tmpDir := fs.NewDir(t, t.Name())
157+
defer tmpDir.Remove()
172158

173159
cmd.Command = dockerCli.Command("app", "inspect")
174-
cmd.Dir = dir.Join("render")
160+
cmd.Dir = dir.Path()
175161
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
176162
ExitCode: 1,
177-
Err: "multiple applications found in current directory, specify the application name on the command line",
163+
Err: "invalid reference format",
178164
})
165+
166+
cmd.Command = dockerCli.Command("app", "bundle", filepath.Join("testdata", "simple", "simple.dockerapp"), "--output", tmpDir.Join("simple-bundle.json"), "--tag", "simple-app:1.0.0")
167+
cmd.Dir = ""
168+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
169+
170+
cmd.Command = dockerCli.Command("app", "inspect", "simple-app:1.0.0")
171+
cmd.Dir = dir.Path()
172+
output := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
173+
golden.Assert(t, output, "app-inspect.golden")
179174
}
180175

181176
func TestBundle(t *testing.T) {

e2e/pushpull_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestPushInstall(t *testing.T) {
145145
cmd.Command = dockerCli.Command("app", "push", "--tag", ref, filepath.Join("testdata", "push-pull", "push-pull.dockerapp"))
146146
icmd.RunCmd(cmd).Assert(t, icmd.Success)
147147

148-
cmd.Command = dockerCli.Command("app", "install", ref, "--name", t.Name())
148+
cmd.Command = dockerCli.Command("app", "install", ref, "--pull", "--name", t.Name())
149149
icmd.RunCmd(cmd).Assert(t, icmd.Success)
150150
cmd.Command = dockerCli.Command("service", "ls")
151151
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))
@@ -203,7 +203,7 @@ func TestPushInstallBundle(t *testing.T) {
203203
cmd.Command = dockerCli.Command("app", "push", "--tag", ref, bundleFile)
204204
icmd.RunCmd(cmd).Assert(t, icmd.Success)
205205

206-
cmd.Command = dockerCli.Command("app", "install", ref, "--name", name)
206+
cmd.Command = dockerCli.Command("app", "install", ref, "--pull", "--name", name)
207207
icmd.RunCmd(cmd).Assert(t, icmd.Success)
208208
cmd.Command = dockerCli.Command("service", "ls")
209209
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))
@@ -223,7 +223,7 @@ func TestPushInstallBundle(t *testing.T) {
223223
cmd.Command = dockerCli.Command("app", "push", "--tag", ref2, ref+":latest")
224224
icmd.RunCmd(cmd).Assert(t, icmd.Success)
225225

226-
cmd.Command = dockerCli.Command("app", "install", ref2, "--name", name)
226+
cmd.Command = dockerCli.Command("app", "install", ref2, "--pull", "--name", name)
227227
icmd.RunCmd(cmd).Assert(t, icmd.Success)
228228
cmd.Command = dockerCli.Command("service", "ls")
229229
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref2))
@@ -250,7 +250,7 @@ func TestPushInstallBundle(t *testing.T) {
250250
// remove the bundle from the bundle store to be sure it won't be used instead of registry
251251
cleanupIsolatedStore()
252252
// install from the registry
253-
cmd.Command = dockerCli.Command("app", "install", ref2, "--name", name)
253+
cmd.Command = dockerCli.Command("app", "install", ref2, "--pull", "--name", name)
254254
icmd.RunCmd(cmd).Assert(t, icmd.Success)
255255
cmd.Command = dockerCli.Command("service", "ls")
256256
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))

e2e/testdata/app-inspect.golden

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"Metadata": {
3+
"version": "1.1.0-beta1",
4+
"name": "simple",
5+
"description": "new fancy webapp with microservices",
6+
"maintainers": [
7+
{
8+
"name": "John Developer",
9+
"email": "john.dev@example.com"
10+
},
11+
{
12+
"name": "Jane Developer",
13+
"email": "jane.dev@example.com"
14+
}
15+
]
16+
},
17+
"Services": [
18+
{
19+
"Name": "api",
20+
"Image": "python:3.6",
21+
"Replicas": 1
22+
},
23+
{
24+
"Name": "db",
25+
"Image": "postgres:9.3",
26+
"Replicas": 1
27+
},
28+
{
29+
"Name": "web",
30+
"Image": "nginx:latest",
31+
"Replicas": 1,
32+
"Ports": "8082"
33+
}
34+
],
35+
"Networks": [
36+
"back",
37+
"front"
38+
],
39+
"Volumes": [
40+
"static"
41+
],
42+
"Parameters": {
43+
"api_host": "example.com",
44+
"static_subdir": "data/static",
45+
"web_port": "8082"
46+
}
47+
}

e2e/testdata/bundle-with-tag.json.golden

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
"env": "docker_param1"
5353
}
5454
},
55+
"com.docker.app.inspect-format": {
56+
"definition": "com.docker.app.inspect-format",
57+
"applyTo": [
58+
"com.docker.app.inspect"
59+
],
60+
"destination": {
61+
"env": "DOCKER_INSPECT_FORMAT"
62+
}
63+
},
5564
"com.docker.app.kubernetes-namespace": {
5665
"definition": "com.docker.app.kubernetes-namespace",
5766
"applyTo": [
@@ -117,6 +126,16 @@
117126
"default": "example.com",
118127
"type": "string"
119128
},
129+
"com.docker.app.inspect-format": {
130+
"default": "json",
131+
"description": "Output format for the inspect command",
132+
"enum": [
133+
"json",
134+
"pretty"
135+
],
136+
"title": "Inspect format",
137+
"type": "string"
138+
},
120139
"com.docker.app.kubernetes-namespace": {
121140
"default": "",
122141
"description": "Namespace in which to deploy",

e2e/testdata/simple-bundle.json.golden

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
"env": "docker_param1"
5353
}
5454
},
55+
"com.docker.app.inspect-format": {
56+
"definition": "com.docker.app.inspect-format",
57+
"applyTo": [
58+
"com.docker.app.inspect"
59+
],
60+
"destination": {
61+
"env": "DOCKER_INSPECT_FORMAT"
62+
}
63+
},
5564
"com.docker.app.kubernetes-namespace": {
5665
"definition": "com.docker.app.kubernetes-namespace",
5766
"applyTo": [
@@ -117,6 +126,16 @@
117126
"default": "example.com",
118127
"type": "string"
119128
},
129+
"com.docker.app.inspect-format": {
130+
"default": "json",
131+
"description": "Output format for the inspect command",
132+
"enum": [
133+
"json",
134+
"pretty"
135+
],
136+
"title": "Inspect format",
137+
"type": "string"
138+
},
120139
"com.docker.app.kubernetes-namespace": {
121140
"default": "",
122141
"description": "Namespace in which to deploy",

internal/commands/cnab.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,26 @@ func resolveBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name
281281
}
282282
return extractAndLoadAppBasedBundle(dockerCli, name)
283283
case nameKindReference:
284-
ref, err := reference.ParseNormalizedNamed(name)
285-
if err != nil {
286-
return nil, "", errors.Wrap(err, name)
287-
}
288-
tagRef := reference.TagNameOnly(ref)
289-
insecureRegistries, err := insecureRegistriesFromEngine(dockerCli)
290-
if err != nil {
291-
return nil, "", fmt.Errorf("could not retrieve insecure registries: %v", err)
292-
}
293-
bndl, err := bundleStore.LookupOrPullBundle(tagRef, pullRef, dockerCli.ConfigFile(), insecureRegistries)
284+
bndl, tagRef, err := getLocalBundle(dockerCli, bundleStore, name, pullRef)
294285
return bndl, tagRef.String(), err
295286
}
296287
return nil, "", fmt.Errorf("could not resolve bundle %q", name)
297288
}
298289

290+
func getLocalBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name string, pullRef bool) (*bundle.Bundle, reference.Named, error) {
291+
ref, err := reference.ParseNormalizedNamed(name)
292+
if err != nil {
293+
return nil, nil, errors.Wrap(err, name)
294+
}
295+
tagRef := reference.TagNameOnly(ref)
296+
insecureRegistries, err := insecureRegistriesFromEngine(dockerCli)
297+
if err != nil {
298+
return nil, tagRef, fmt.Errorf("could not retrieve insecure registries: %v", err)
299+
}
300+
bndl, err := bundleStore.LookupOrPullBundle(tagRef, pullRef, dockerCli.ConfigFile(), insecureRegistries)
301+
return bndl, tagRef, err
302+
}
303+
299304
func requiredClaimBindMount(c claim.Claim, targetContextName string, dockerCli command.Cli) (bindMount, error) {
300305
var specifiedOrchestrator string
301306
if rawOrchestrator, ok := c.Parameters[internal.ParameterOrchestratorName]; ok {
@@ -359,7 +364,6 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
359364
if err != nil {
360365
return nil, nil, nil, err
361366
}
362-
driverImpl, errBuf := prepareDriver(dockerCli, bindMount{}, stdout)
363367
bundle, ref, err := resolveBundle(dockerCli, bundleStore, appname, pullOpts.pull)
364368
if err != nil {
365369
return nil, nil, nil, err
@@ -377,6 +381,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
377381
return nil, nil, nil, err
378382
}
379383

384+
driverImpl, errBuf := prepareDriver(dockerCli, bindMount{}, stdout)
380385
a := &action.RunCustom{
381386
Action: actionName,
382387
Driver: driverImpl,

internal/commands/inspect.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,71 @@ package commands
33
import (
44
"fmt"
55

6+
"github.com/deislabs/cnab-go/action"
67
"github.com/docker/app/internal"
8+
appstore "github.com/docker/app/internal/store"
79
"github.com/docker/cli/cli"
810
"github.com/docker/cli/cli/command"
11+
"github.com/docker/cli/cli/config"
912
"github.com/spf13/cobra"
1013
)
1114

1215
type inspectOptions struct {
13-
parametersOptions
14-
pullOptions
16+
pretty bool
1517
}
1618

1719
func inspectCmd(dockerCli command.Cli) *cobra.Command {
1820
var opts inspectOptions
1921
cmd := &cobra.Command{
20-
Use: "inspect [APP_NAME] [OPTIONS]",
21-
Short: "Shows metadata, parameters and a summary of the Compose file for a given application",
22-
Example: `$ docker app inspect myapp.dockerapp`,
23-
Args: cli.RequiresMaxArgs(1),
22+
Use: "inspect [APP_NAME] [OPTIONS]",
23+
Short: "Shows metadata, parameters and a summary of the Compose file for a given application",
24+
Example: `$ docker app inspect my-installed-app
25+
$docker app inspect my-app:1.0.0`,
26+
Args: cli.RequiresMaxArgs(1),
2427
RunE: func(cmd *cobra.Command, args []string) error {
2528
return runInspect(dockerCli, firstOrEmpty(args), opts)
2629
},
2730
}
28-
opts.parametersOptions.addFlags(cmd.Flags())
29-
opts.pullOptions.addFlags(cmd.Flags())
31+
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Pretty print the output")
32+
3033
return cmd
3134
}
3235

3336
func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) error {
3437
defer muteDockerCli(dockerCli)()
35-
action, installation, errBuf, err := prepareCustomAction(internal.ActionInspectName, dockerCli, appname, nil, opts.pullOptions, opts.parametersOptions)
38+
s, err := appstore.NewApplicationStore(config.Dir())
3639
if err != nil {
3740
return err
3841
}
39-
if err := action.Run(&installation.Claim, nil, nil); err != nil {
42+
bundleStore, err := s.BundleStore()
43+
if err != nil {
44+
return err
45+
}
46+
bndl, ref, err := getLocalBundle(dockerCli, bundleStore, appname, false)
47+
48+
if err != nil {
49+
return err
50+
}
51+
installation, err := appstore.NewInstallation("custom-action", ref.String())
52+
if err != nil {
53+
return err
54+
}
55+
installation.Bundle = bndl
56+
57+
driverImpl, errBuf := prepareDriver(dockerCli, bindMount{}, nil)
58+
a := &action.RunCustom{
59+
Action: internal.ActionInspectName,
60+
Driver: driverImpl,
61+
}
62+
63+
format := "json"
64+
if opts.pretty {
65+
format = "pretty"
66+
}
67+
68+
installation.SetParameter(internal.ParameterInspectFormatName, format)
69+
70+
if err := a.Run(&installation.Claim, nil, nil); err != nil {
4071
return fmt.Errorf("inspect failed: %s\n%s", err, errBuf)
4172
}
4273
return nil

internal/commands/pull.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
1010
"github.com/docker/cli/cli/config"
11-
"github.com/docker/distribution/reference"
1211
"github.com/pkg/errors"
1312
"github.com/spf13/cobra"
1413
)
@@ -36,15 +35,7 @@ func runPull(dockerCli command.Cli, name string) error {
3635
return err
3736
}
3837

39-
ref, err := reference.ParseNormalizedNamed(name)
40-
if err != nil {
41-
return errors.Wrap(err, name)
42-
}
43-
insecureRegistries, err := insecureRegistriesFromEngine(dockerCli)
44-
if err != nil {
45-
return errors.Wrap(err, "could not retrieve insecure registries")
46-
}
47-
bndl, err := bundleStore.LookupOrPullBundle(reference.TagNameOnly(ref), true, dockerCli.ConfigFile(), insecureRegistries)
38+
bndl, ref, err := getLocalBundle(dockerCli, bundleStore, name, true)
4839
if err != nil {
4940
return errors.Wrap(err, name)
5041
}

0 commit comments

Comments
 (0)