Skip to content

Commit

Permalink
chore: swap deployEnv to opt in when environment already exists (#5262)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bvtujo authored Aug 31, 2023
1 parent 3a73f6e commit e61b1aa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
7 changes: 0 additions & 7 deletions internal/pkg/cli/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 3 additions & 31 deletions internal/pkg/cli/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand All @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions site/content/docs/commands/deploy.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e61b1aa

Please sign in to comment.