diff --git a/e2e/commands_test.go b/e2e/commands_test.go index 57eb1f406..98b8521bd 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,16 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) { } } +func TestRenderAppNotFound(t *testing.T) { + cmd, cleanup := dockerCli.createTestCmd() + defer cleanup() + + 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) { 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 90e258b56..a673d72b9 100644 --- a/internal/commands/render.go +++ b/internal/commands/render.go @@ -13,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" ) @@ -28,10 +29,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 +76,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 + return nil, nil, nil, errors.Wrapf(err, "could not render %q: no such App image", appname) } - installation, err := appstore.NewInstallation("custom-action", ref) + installation, err := appstore.NewInstallation("custom-action", ref.String()) if err != nil { return nil, nil, nil, err }