From 154c45cfd3c739b5ecb15338d1b8be1d913d0358 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Sirot Date: Tue, 29 Oct 2019 17:09:40 +0100 Subject: [PATCH 1/3] Make render command takes exactly one argument which is an App image name. Rendering a .dockerapp dir is not allowed anymore Signed-off-by: Jean-Christophe Sirot --- internal/commands/render.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/commands/render.go b/internal/commands/render.go index 90e258b56..531d55a71 100644 --- a/internal/commands/render.go +++ b/internal/commands/render.go @@ -28,10 +28,10 @@ func renderCmd(dockerCli command.Cli) *cobra.Command { Use: "render [OPTIONS] APP_IMAGE", Short: "Render the Compose file for an App image", Example: `$ docker app render myrepo/myapp:1.0.0 --set key=value --parameters-file myparam.yml`, - Args: cli.RequiresMaxArgs(1), + Args: cli.ExactArgs(1), Hidden: true, RunE: func(cmd *cobra.Command, args []string) error { - return runRender(dockerCli, firstOrEmpty(args), opts) + return runRender(dockerCli, args[0], opts) }, } opts.parametersOptions.addFlags(cmd.Flags()) @@ -75,11 +75,11 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin if err != nil { return nil, nil, nil, err } - bundle, ref, err := cnab.ResolveBundle(dockerCli, bundleStore, appname) + bundle, ref, err := cnab.GetBundle(dockerCli, bundleStore, appname) if err != nil { return nil, nil, nil, err } - installation, err := appstore.NewInstallation("custom-action", ref) + installation, err := appstore.NewInstallation("custom-action", ref.String()) if err != nil { return nil, nil, nil, err } From 7263c1850409bdeb29b233acc0d639c0e319fbd2 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Sirot Date: Thu, 31 Oct 2019 12:59:05 +0100 Subject: [PATCH 2/3] Update e2e tests Signed-off-by: Jean-Christophe Sirot --- e2e/commands_test.go | 19 ++++++++++++++++++- e2e/envfile_test.go | 5 ++++- internal/commands/render.go | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/e2e/commands_test.go b/e2e/commands_test.go index 57eb1f406..7cb7c2528 100644 --- a/e2e/commands_test.go +++ b/e2e/commands_test.go @@ -48,11 +48,16 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) { dir := fs.NewDir(t, "") defer dir.Remove() + // Build the App + cmd.Command = dockerCli.Command("app", "build", ".", "--folder", filepath.Join(appPath, "my.dockerapp"), "--tag", "a-simple-tag", "--no-resolve-image") + icmd.RunCmd(cmd).Assert(t, icmd.Success) + + // Render the App envParameters := map[string]string{} data, err := ioutil.ReadFile(filepath.Join(appPath, "env.yml")) assert.NilError(t, err) assert.NilError(t, yaml.Unmarshal(data, &envParameters)) - args := dockerCli.Command("app", "render", filepath.Join(appPath, "my.dockerapp"), "--parameters-file", filepath.Join(appPath, "parameters-0.yml")) + args := dockerCli.Command("app", "render", "a-simple-tag", "--parameters-file", filepath.Join(appPath, "parameters-0.yml")) for k, v := range envParameters { args = append(args, "--set", fmt.Sprintf("%s=%s", k, v)) } @@ -70,6 +75,18 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) { } } +func TestRenderAppDirectoryFails(t *testing.T) { + cmd, cleanup := dockerCli.createTestCmd() + defer cleanup() + appPath := filepath.Join("testdata", "envfile", "envfile.dockerapp") + + cmd.Command = dockerCli.Command("app", "render", appPath) + icmd.RunCmd(cmd).Assert(t, icmd.Expected{ + ExitCode: 1, + Err: fmt.Sprintf("%q looks like a docker App directory and App must be built first before rendering", appPath), + }) +} + func TestRenderFormatters(t *testing.T) { runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) { cmd := info.configuredCmd diff --git a/e2e/envfile_test.go b/e2e/envfile_test.go index cf909855b..76ede91d4 100644 --- a/e2e/envfile_test.go +++ b/e2e/envfile_test.go @@ -12,7 +12,10 @@ func TestRenderWithEnvFile(t *testing.T) { defer cleanup() appPath := filepath.Join("testdata", "envfile", "envfile.dockerapp") - cmd.Command = dockerCli.Command("app", "render", appPath) + cmd.Command = dockerCli.Command("app", "build", "-f", appPath, "--tag", "a-simple-tag", "--no-resolve-image", ".") + icmd.RunCmd(cmd).Assert(t, icmd.Success) + + cmd.Command = dockerCli.Command("app", "render", "a-simple-tag") icmd.RunCmd(cmd).Assert(t, icmd.Expected{Out: `version: "3.7" services: db: diff --git a/internal/commands/render.go b/internal/commands/render.go index 531d55a71..29ad2c354 100644 --- a/internal/commands/render.go +++ b/internal/commands/render.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "strings" "github.com/deislabs/cnab-go/action" "github.com/docker/app/internal" @@ -77,6 +78,9 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin } bundle, ref, err := cnab.GetBundle(dockerCli, bundleStore, appname) if err != nil { + if strings.HasSuffix(appname, ".dockerapp") { + return nil, nil, nil, fmt.Errorf("%q looks like a docker App directory and App must be built first before rendering", appname) + } return nil, nil, nil, err } installation, err := appstore.NewInstallation("custom-action", ref.String()) From c2f76a85a91aa02db87fb691f59cf45ac273a865 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Sirot Date: Tue, 5 Nov 2019 08:48:10 +0100 Subject: [PATCH 3/3] Fix error handling and message when the App to render does not exist Signed-off-by: Jean-Christophe Sirot --- e2e/commands_test.go | 12 +++++------- internal/commands/render.go | 7 ++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/e2e/commands_test.go b/e2e/commands_test.go index 7cb7c2528..98b8521bd 100644 --- a/e2e/commands_test.go +++ b/e2e/commands_test.go @@ -75,16 +75,14 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) { } } -func TestRenderAppDirectoryFails(t *testing.T) { +func TestRenderAppNotFound(t *testing.T) { cmd, cleanup := dockerCli.createTestCmd() defer cleanup() - appPath := filepath.Join("testdata", "envfile", "envfile.dockerapp") - cmd.Command = dockerCli.Command("app", "render", appPath) - icmd.RunCmd(cmd).Assert(t, icmd.Expected{ - ExitCode: 1, - Err: fmt.Sprintf("%q looks like a docker App directory and App must be built first before rendering", appPath), - }) + appName := "non_existing_app:some_tag" + cmd.Command = dockerCli.Command("app", "render", appName) + checkContains(t, icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 1}).Combined(), + []string{fmt.Sprintf("could not render %q: no such App image", appName)}) } func TestRenderFormatters(t *testing.T) { diff --git a/internal/commands/render.go b/internal/commands/render.go index 29ad2c354..a673d72b9 100644 --- a/internal/commands/render.go +++ b/internal/commands/render.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "strings" "github.com/deislabs/cnab-go/action" "github.com/docker/app/internal" @@ -14,6 +13,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/config" + "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -78,10 +78,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin } bundle, ref, err := cnab.GetBundle(dockerCli, bundleStore, appname) if err != nil { - if strings.HasSuffix(appname, ".dockerapp") { - return nil, nil, nil, fmt.Errorf("%q looks like a docker App directory and App must be built first before rendering", appname) - } - return nil, nil, nil, err + return nil, nil, nil, errors.Wrapf(err, "could not render %q: no such App image", appname) } installation, err := appstore.NewInstallation("custom-action", ref.String()) if err != nil {