From e61b1aa12998ccd70c7dc7db5bbdbf63eb853eb5 Mon Sep 17 00:00:00 2001 From: Austin Ely Date: Thu, 31 Aug 2023 14:17:55 -0400 Subject: [PATCH] chore: swap deployEnv to opt in when environment already exists (#5262) The new logic with no flags is: 1. Check whether workload is uninitialized. If so, prompt for workload init. 2. Check whether environment is uninitialized. If so, prompt for env init, then proceed directly to env deploy. 3. Deploy workload. Now, there is no extra prompt for environment deployment at any time. The behavior is purely opt-in, which actually I think makes more sense. --- internal/pkg/cli/deploy.go | 7 ----- internal/pkg/cli/deploy_test.go | 34 +++---------------------- site/content/docs/commands/deploy.en.md | 4 +-- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/internal/pkg/cli/deploy.go b/internal/pkg/cli/deploy.go index d91a288b33f..c48e73044f6 100644 --- a/internal/pkg/cli/deploy.go +++ b/internal/pkg/cli/deploy.go @@ -397,13 +397,6 @@ func (o *deployOpts) maybeDeployEnv() error { if !o.envExistsInWs { return nil } - if o.deployEnv == nil { - v, err := o.prompt.Confirm(fmt.Sprintf("Would you like to deploy the environment %q before deploying your workload?", o.envName), "", prompt.WithFinalMessage("Deploy environment:")) - if err != nil { - return fmt.Errorf("confirm env deployment: %w", err) - } - o.deployEnv = aws.Bool(v) - } if aws.BoolValue(o.deployEnv) { cmd, err := o.newDeployEnvCmd(o) diff --git a/internal/pkg/cli/deploy_test.go b/internal/pkg/cli/deploy_test.go index c73b643d093..76f79bbff19 100644 --- a/internal/pkg/cli/deploy_test.go +++ b/internal/pkg/cli/deploy_test.go @@ -945,51 +945,26 @@ func Test_deployOpts_maybeInitEnv(t *testing.T) { } func Test_deployOpts_maybeDeployEnv(t *testing.T) { - mockError := errors.New("some error") tests := map[string]struct { envExistsInWs bool deployEnv *bool - mockPrompt func(m *mocks.Mockprompter) mockDeployEnvCmd func(m *mocks.Mockcmd) wantErr string }{ "env does not exist in ws": { envExistsInWs: false, - mockPrompt: func(m *mocks.Mockprompter) {}, mockDeployEnvCmd: func(m *mocks.Mockcmd) {}, }, - "env exists; deploy false when prompted": { - envExistsInWs: true, - mockPrompt: func(m *mocks.Mockprompter) { - m.EXPECT().Confirm(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil) - }, + "env exists in app, flag set false": { + envExistsInWs: true, + deployEnv: aws.Bool(false), mockDeployEnvCmd: func(m *mocks.Mockcmd) {}, }, - "env exists; deploy true when prompted": { - envExistsInWs: true, - mockPrompt: func(m *mocks.Mockprompter) { - m.EXPECT().Confirm(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil) - }, - mockDeployEnvCmd: func(m *mocks.Mockcmd) { - m.EXPECT().Validate().Return(nil) - m.EXPECT().Ask().Return(nil) - m.EXPECT().Execute().Return(nil) - }, - }, - "error selecting whether to deploy env": { - envExistsInWs: true, - mockPrompt: func(m *mocks.Mockprompter) { - m.EXPECT().Confirm(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, mockError) - }, - mockDeployEnvCmd: func(m *mocks.Mockcmd) {}, - wantErr: "confirm env deployment: some error", - }, "env exists; deploy flag set": { envExistsInWs: true, deployEnv: aws.Bool(true), - mockPrompt: func(m *mocks.Mockprompter) {}, mockDeployEnvCmd: func(m *mocks.Mockcmd) { m.EXPECT().Validate().Return(nil) m.EXPECT().Ask().Return(nil) @@ -1002,10 +977,8 @@ func Test_deployOpts_maybeDeployEnv(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockPrompt := mocks.NewMockprompter(ctrl) mockDeployEnvCmd := mocks.NewMockcmd(ctrl) - tc.mockPrompt(mockPrompt) tc.mockDeployEnvCmd(mockDeployEnvCmd) o := &deployOpts{ @@ -1017,7 +990,6 @@ func Test_deployOpts_maybeDeployEnv(t *testing.T) { deployEnv: tc.deployEnv, }, envExistsInWs: tc.envExistsInWs, - prompt: mockPrompt, newDeployEnvCmd: func(o *deployOpts) (cmd, error) { return mockDeployEnvCmd, nil }, diff --git a/site/content/docs/commands/deploy.en.md b/site/content/docs/commands/deploy.en.md index 3f8d5748e62..c08894415f4 100644 --- a/site/content/docs/commands/deploy.en.md +++ b/site/content/docs/commands/deploy.en.md @@ -64,12 +64,12 @@ rollback of the stack via the AWS console or AWS CLI before the next deployment. ## Examples Deploys a service named "frontend" to a "test" environment. ```console -$ copilot deploy --name frontend --env test --deploy-env=false +$ copilot deploy --name frontend --env test ``` Deploys a job named "mailer" with additional resource tags to a "prod" environment. ```console -$ copilot deploy -n mailer -e prod --resource-tags source/revision=bb133e7,deployment/initiator=manual --deploy-env=false +$ copilot deploy -n mailer -e prod --resource-tags source/revision=bb133e7,deployment/initiator=manual ``` Initializes and deploys an environment named "test" in us-west-2 under the "default" profile with local manifest,