Skip to content

Commit e61b1aa

Browse files
authored
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.
1 parent 3a73f6e commit e61b1aa

3 files changed

Lines changed: 5 additions & 40 deletions

File tree

internal/pkg/cli/deploy.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,6 @@ func (o *deployOpts) maybeDeployEnv() error {
397397
if !o.envExistsInWs {
398398
return nil
399399
}
400-
if o.deployEnv == nil {
401-
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:"))
402-
if err != nil {
403-
return fmt.Errorf("confirm env deployment: %w", err)
404-
}
405-
o.deployEnv = aws.Bool(v)
406-
}
407400

408401
if aws.BoolValue(o.deployEnv) {
409402
cmd, err := o.newDeployEnvCmd(o)

internal/pkg/cli/deploy_test.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -945,51 +945,26 @@ func Test_deployOpts_maybeInitEnv(t *testing.T) {
945945
}
946946

947947
func Test_deployOpts_maybeDeployEnv(t *testing.T) {
948-
mockError := errors.New("some error")
949948
tests := map[string]struct {
950949
envExistsInWs bool
951950
deployEnv *bool
952951

953-
mockPrompt func(m *mocks.Mockprompter)
954952
mockDeployEnvCmd func(m *mocks.Mockcmd)
955953

956954
wantErr string
957955
}{
958956
"env does not exist in ws": {
959957
envExistsInWs: false,
960-
mockPrompt: func(m *mocks.Mockprompter) {},
961958
mockDeployEnvCmd: func(m *mocks.Mockcmd) {},
962959
},
963-
"env exists; deploy false when prompted": {
964-
envExistsInWs: true,
965-
mockPrompt: func(m *mocks.Mockprompter) {
966-
m.EXPECT().Confirm(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
967-
},
960+
"env exists in app, flag set false": {
961+
envExistsInWs: true,
962+
deployEnv: aws.Bool(false),
968963
mockDeployEnvCmd: func(m *mocks.Mockcmd) {},
969964
},
970-
"env exists; deploy true when prompted": {
971-
envExistsInWs: true,
972-
mockPrompt: func(m *mocks.Mockprompter) {
973-
m.EXPECT().Confirm(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil)
974-
},
975-
mockDeployEnvCmd: func(m *mocks.Mockcmd) {
976-
m.EXPECT().Validate().Return(nil)
977-
m.EXPECT().Ask().Return(nil)
978-
m.EXPECT().Execute().Return(nil)
979-
},
980-
},
981-
"error selecting whether to deploy env": {
982-
envExistsInWs: true,
983-
mockPrompt: func(m *mocks.Mockprompter) {
984-
m.EXPECT().Confirm(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, mockError)
985-
},
986-
mockDeployEnvCmd: func(m *mocks.Mockcmd) {},
987-
wantErr: "confirm env deployment: some error",
988-
},
989965
"env exists; deploy flag set": {
990966
envExistsInWs: true,
991967
deployEnv: aws.Bool(true),
992-
mockPrompt: func(m *mocks.Mockprompter) {},
993968
mockDeployEnvCmd: func(m *mocks.Mockcmd) {
994969
m.EXPECT().Validate().Return(nil)
995970
m.EXPECT().Ask().Return(nil)
@@ -1002,10 +977,8 @@ func Test_deployOpts_maybeDeployEnv(t *testing.T) {
1002977
ctrl := gomock.NewController(t)
1003978
defer ctrl.Finish()
1004979

1005-
mockPrompt := mocks.NewMockprompter(ctrl)
1006980
mockDeployEnvCmd := mocks.NewMockcmd(ctrl)
1007981

1008-
tc.mockPrompt(mockPrompt)
1009982
tc.mockDeployEnvCmd(mockDeployEnvCmd)
1010983

1011984
o := &deployOpts{
@@ -1017,7 +990,6 @@ func Test_deployOpts_maybeDeployEnv(t *testing.T) {
1017990
deployEnv: tc.deployEnv,
1018991
},
1019992
envExistsInWs: tc.envExistsInWs,
1020-
prompt: mockPrompt,
1021993
newDeployEnvCmd: func(o *deployOpts) (cmd, error) {
1022994
return mockDeployEnvCmd, nil
1023995
},

site/content/docs/commands/deploy.en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ rollback of the stack via the AWS console or AWS CLI before the next deployment.
6464
## Examples
6565
Deploys a service named "frontend" to a "test" environment.
6666
```console
67-
$ copilot deploy --name frontend --env test --deploy-env=false
67+
$ copilot deploy --name frontend --env test
6868
```
6969

7070
Deploys a job named "mailer" with additional resource tags to a "prod" environment.
7171
```console
72-
$ copilot deploy -n mailer -e prod --resource-tags source/revision=bb133e7,deployment/initiator=manual --deploy-env=false
72+
$ copilot deploy -n mailer -e prod --resource-tags source/revision=bb133e7,deployment/initiator=manual
7373
```
7474

7575
Initializes and deploys an environment named "test" in us-west-2 under the "default" profile with local manifest,

0 commit comments

Comments
 (0)