2
2
CLI command for "deploy" command
3
3
"""
4
4
5
+ import tempfile
6
+
5
7
import click
6
8
7
- from samcli .cli .cli_config_file import configuration_option , TomlProvider
8
9
from samcli .commands ._utils .options import (
9
10
parameter_override_option ,
10
11
capabilities_override_option ,
11
12
tags_override_option ,
12
13
notification_arns_override_option ,
13
14
template_click_option ,
15
+ metadata_override_option ,
14
16
)
17
+ from samcli .cli .cli_config_file import configuration_option , TomlProvider
15
18
from samcli .cli .main import pass_context , common_options , aws_creds_options
16
19
from samcli .lib .telemetry .metrics import track_command
17
20
28
31
"""
29
32
30
33
31
- @configuration_option (provider = TomlProvider (section = "parameters" ))
32
34
@click .command (
33
35
"deploy" ,
34
36
short_help = SHORT_HELP ,
35
37
context_settings = {"ignore_unknown_options" : False , "allow_interspersed_args" : True , "allow_extra_args" : True },
36
38
help = HELP_TEXT ,
37
39
)
38
- @template_click_option (include_build = False )
40
+ @configuration_option (provider = TomlProvider (section = "parameters" ))
41
+ @template_click_option (include_build = True )
39
42
@click .option (
40
43
"--stack-name" ,
41
44
required = True ,
96
99
"changes to be made to the stack. The default behavior is to return a"
97
100
"non-zero exit code." ,
98
101
)
102
+ @click .option (
103
+ "--use-json" ,
104
+ required = False ,
105
+ is_flag = True ,
106
+ help = "Indicates whether to use JSON as the format for "
107
+ "the output AWS CloudFormation template. YAML is used by default." ,
108
+ )
109
+ @metadata_override_option
99
110
@notification_arns_override_option
100
111
@tags_override_option
101
112
@parameter_override_option
@@ -118,7 +129,9 @@ def cli(
118
129
role_arn ,
119
130
notification_arns ,
120
131
fail_on_empty_changeset ,
132
+ use_json ,
121
133
tags ,
134
+ metadata ,
122
135
):
123
136
124
137
# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing
@@ -135,7 +148,9 @@ def cli(
135
148
role_arn ,
136
149
notification_arns ,
137
150
fail_on_empty_changeset ,
151
+ use_json ,
138
152
tags ,
153
+ metadata ,
139
154
ctx .region ,
140
155
ctx .profile ,
141
156
) # pragma: no cover
@@ -154,27 +169,47 @@ def do_cli(
154
169
role_arn ,
155
170
notification_arns ,
156
171
fail_on_empty_changeset ,
172
+ use_json ,
157
173
tags ,
174
+ metadata ,
158
175
region ,
159
176
profile ,
160
177
):
178
+ from samcli .commands .package .package_context import PackageContext
161
179
from samcli .commands .deploy .deploy_context import DeployContext
162
180
163
- with DeployContext (
164
- template_file = template_file ,
165
- stack_name = stack_name ,
166
- s3_bucket = s3_bucket ,
167
- force_upload = force_upload ,
168
- s3_prefix = s3_prefix ,
169
- kms_key_id = kms_key_id ,
170
- parameter_overrides = parameter_overrides ,
171
- capabilities = capabilities ,
172
- no_execute_changeset = no_execute_changeset ,
173
- role_arn = role_arn ,
174
- notification_arns = notification_arns ,
175
- fail_on_empty_changeset = fail_on_empty_changeset ,
176
- tags = tags ,
177
- region = region ,
178
- profile = profile ,
179
- ) as deploy_context :
180
- deploy_context .run ()
181
+ with tempfile .NamedTemporaryFile () as output_template_file :
182
+
183
+ with PackageContext (
184
+ template_file = template_file ,
185
+ s3_bucket = s3_bucket ,
186
+ s3_prefix = s3_prefix ,
187
+ output_template_file = output_template_file .name ,
188
+ kms_key_id = kms_key_id ,
189
+ use_json = use_json ,
190
+ force_upload = force_upload ,
191
+ metadata = metadata ,
192
+ on_deploy = True ,
193
+ region = region ,
194
+ profile = profile ,
195
+ ) as package_context :
196
+ package_context .run ()
197
+
198
+ with DeployContext (
199
+ template_file = output_template_file .name ,
200
+ stack_name = stack_name ,
201
+ s3_bucket = s3_bucket ,
202
+ force_upload = force_upload ,
203
+ s3_prefix = s3_prefix ,
204
+ kms_key_id = kms_key_id ,
205
+ parameter_overrides = parameter_overrides ,
206
+ capabilities = capabilities ,
207
+ no_execute_changeset = no_execute_changeset ,
208
+ role_arn = role_arn ,
209
+ notification_arns = notification_arns ,
210
+ fail_on_empty_changeset = fail_on_empty_changeset ,
211
+ tags = tags ,
212
+ region = region ,
213
+ profile = profile ,
214
+ ) as deploy_context :
215
+ deploy_context .run ()
0 commit comments