1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
2
4
3
package cmd
5
4
@@ -33,11 +32,11 @@ import (
33
32
)
34
33
35
34
type DeployFlags struct {
36
- ServiceName string
37
- All bool
38
- PublishOnly bool
39
- fromPackage string
40
- global * internal.GlobalCommandOptions
35
+ ServiceName string
36
+ All bool
37
+ fromPackage string
38
+ forcePublish bool
39
+ global * internal.GlobalCommandOptions
41
40
* internal.EnvFlag
42
41
}
43
42
@@ -71,21 +70,19 @@ func (d *DeployFlags) bindCommon(local *pflag.FlagSet, global *internal.GlobalCo
71
70
false ,
72
71
"Deploys all services that are listed in " + azdcontext .ProjectFileName ,
73
72
)
74
- local .BoolVar (
75
- & d .PublishOnly ,
76
- "publish-only" ,
77
- false ,
78
- "Publishes the container image to the registry without deploying the application." ,
79
- )
80
- // `azd publish` is an alias for this
81
- _ = local .MarkHidden ("publish-only" )
82
73
local .StringVar (
83
74
& d .fromPackage ,
84
75
"from-package" ,
85
76
"" ,
86
77
//nolint:lll
87
78
"Deploys the packaged service located at the provided path. Supports zipped file packages (file path) or container images (image tag)." ,
88
79
)
80
+ local .BoolVar (
81
+ & d .forcePublish ,
82
+ "force-publish" ,
83
+ false ,
84
+ "Force publishes and overwrites existing images" ,
85
+ )
89
86
}
90
87
91
88
func (d * DeployFlags ) SetCommon (envFlag * internal.EnvFlag ) {
@@ -230,10 +227,6 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
230
227
231
228
verb := "Deploying"
232
229
commandTitle := "Deploying services (azd deploy)"
233
- if da .flags .PublishOnly {
234
- verb = "Publishing"
235
- commandTitle = "Publishing services (azd publish)"
236
- }
237
230
238
231
// Command title
239
232
da .console .MessageUxItem (ctx , & ux.MessageTitle {
@@ -266,25 +259,19 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
266
259
da .console .WarnForFeature (ctx , alphaFeatureId )
267
260
}
268
261
269
- if da .flags .PublishOnly {
270
- // Check if this service is a container app
271
- if svc .Host != project .ContainerAppTarget {
272
- da .console .StopSpinner (ctx , stepMessage , input .StepFailed )
273
- return nil , fmt .Errorf (
274
- "'publish' is only supported for container app services, but service '%s' has host type '%s'" ,
275
- svc .Name , svc .Host )
276
- }
277
-
278
- // Set publish-only context and continue with normal deploy flow
279
- ctx = project .WithPublishOnly (ctx , true )
280
- }
281
-
282
262
var packageResult * project.ServicePackageResult
263
+ var publishResult * project.ServicePublishResult
264
+ var publishOptions * project.PublishOptions
265
+
283
266
if da .flags .fromPackage != "" {
284
267
// --from-package set, skip packaging
285
268
packageResult = & project.ServicePackageResult {
286
269
PackagePath : da .flags .fromPackage ,
287
270
}
271
+
272
+ publishOptions = & project.PublishOptions {
273
+ Overwrite : da .flags .forcePublish ,
274
+ }
288
275
} else {
289
276
// --from-package not set, automatically package the application
290
277
packageResult , err = async .RunWithProgress (
@@ -297,11 +284,31 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
297
284
},
298
285
)
299
286
300
- // do not stop progress here as next step is to deploy
287
+ // do not stop progress here as next step is to publish
301
288
if err != nil {
302
289
da .console .StopSpinner (ctx , stepMessage , input .StepFailed )
303
290
return nil , err
304
291
}
292
+
293
+ publishOptions = & project.PublishOptions {
294
+ Overwrite : true ,
295
+ }
296
+ }
297
+
298
+ publishResult , err = async .RunWithProgress (
299
+ func (publishProgress project.ServiceProgress ) {
300
+ progressMessage := fmt .Sprintf ("Publishing service %s (%s)" , svc .Name , publishProgress .Message )
301
+ da .console .ShowSpinner (ctx , progressMessage , input .Step )
302
+ },
303
+ func (progress * async.Progress [project.ServiceProgress ]) (* project.ServicePublishResult , error ) {
304
+ return da .serviceManager .Publish (ctx , svc , packageResult , progress , publishOptions )
305
+ },
306
+ )
307
+
308
+ // do not stop progress here as next step is to deploy
309
+ if err != nil {
310
+ da .console .StopSpinner (ctx , stepMessage , input .StepFailed )
311
+ return nil , err
305
312
}
306
313
307
314
deployResult , err := async .RunWithProgress (
@@ -310,7 +317,7 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
310
317
da .console .ShowSpinner (ctx , progressMessage , input .Step )
311
318
},
312
319
func (progress * async.Progress [project.ServiceProgress ]) (* project.ServiceDeployResult , error ) {
313
- return da .serviceManager .Deploy (ctx , svc , packageResult , progress )
320
+ return da .serviceManager .Deploy (ctx , svc , packageResult , publishResult , progress )
314
321
},
315
322
)
316
323
@@ -349,10 +356,6 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
349
356
}
350
357
351
358
messageHeader := fmt .Sprintf ("Your application was deployed to Azure in %s." , ux .DurationAsText (since (startTime )))
352
- if da .flags .PublishOnly {
353
- messageHeader = fmt .Sprintf ("Your application was published to the container registry in %s." ,
354
- ux .DurationAsText (since (startTime )))
355
- }
356
359
357
360
return & actions.ActionResult {
358
361
Message : & actions.ResultMessage {
0 commit comments