@@ -68,6 +68,7 @@ type DeployOptions struct {
6868 TargetApps , SkipApps []string
6969 SkipAllApps bool
7070 SkipDNS bool
71+ SkipMonitoring bool
7172 SkipDiff bool
7273 SkipApply bool
7374 SkipStateCreate bool
@@ -104,7 +105,7 @@ func (d *Deploy) stateLockDeploy(ctx context.Context, state *statefile.StateData
104105 return nil , err
105106 }
106107
107- res , err := d .planAndApplyDeploy (ctx , verify , state , nil , false )
108+ res , err := d .planAndApply (ctx , verify , state , nil , false )
108109 if res == nil && err != nil {
109110 return nil , err
110111 }
@@ -255,7 +256,7 @@ func (d *Deploy) checkIfDNSAreUsed(stateApps map[string]*apiv1.AppState, showWar
255256 continue
256257 }
257258
258- u , _ := config .ParseAppURL (app .App .Url )
259+ u , _ := config .ParseURL (app .App .Url , false )
259260 if u == nil {
260261 continue
261262 }
@@ -374,7 +375,7 @@ func (d *Deploy) multilockPlanAndApplyDeploy(ctx context.Context, state *statefi
374375
375376 showWarnings = false
376377
377- res , err := d .planAndApplyDeploy (ctx , verify , state , acquiredLocks , true )
378+ res , err := d .planAndApply (ctx , verify , state , acquiredLocks , true )
378379 if err != nil {
379380 _ = releaseLocks (d .cfg , acquiredLocks )
380381 d .log .Debugf ("Released locks: %s\n " , acquiredLocks )
@@ -512,11 +513,15 @@ func (d *Deploy) Run(ctx context.Context) error {
512513 return nil
513514}
514515
515- func (d * Deploy ) promptDiff (deployChanges , dnsChanges []* change , acquiredLocks map [string ]string , checkLocks bool ) (empty , canceled bool , missingLocks []string ) {
516+ func (d * Deploy ) promptDiff (deployChanges , dnsChanges , monitoringChanges []* change , acquiredLocks map [string ]string , checkLocks bool ) (empty , canceled bool , missingLocks []string ) {
516517 missingLocksMap := make (map [string ]struct {})
517518
519+ changes := deployChanges
520+ changes = append (changes , dnsChanges ... )
521+ changes = append (changes , monitoringChanges ... )
522+
518523 if checkLocks {
519- for _ , chg := range append ( deployChanges , dnsChanges ... ) {
524+ for _ , chg := range changes {
520525 var lockID string
521526
522527 switch {
@@ -543,10 +548,10 @@ func (d *Deploy) promptDiff(deployChanges, dnsChanges []*change, acquiredLocks m
543548 }
544549
545550 if d .opts .SkipDiff {
546- return len (deployChanges ) == 0 && len ( dnsChanges ) == 0 , false , missingLocks
551+ return len (changes ) == 0 , false , missingLocks
547552 }
548553
549- empty , canceled = planPrompt (d .log , d .cfg .Env (), deployChanges , dnsChanges , d .opts .AutoApprove , d .opts .ForceApprove )
554+ empty , canceled = planPrompt (d .log , d .cfg .Env (), deployChanges , dnsChanges , monitoringChanges , d .opts .AutoApprove , d .opts .ForceApprove )
550555
551556 return empty , canceled , missingLocks
552557}
@@ -572,7 +577,7 @@ func computeDomainsInfo(cfg *config.Project, state *statefile.StateData) []*apiv
572577 continue
573578 }
574579
575- u , _ := config .ParseAppURL (app .App .Url )
580+ u , _ := config .ParseURL (app .App .Url , false )
576581 if u == nil {
577582 continue
578583 }
@@ -644,14 +649,22 @@ func computeDomainsInfo(cfg *config.Project, state *statefile.StateData) []*apiv
644649 return ret
645650}
646651
647- func (d * Deploy ) planAndApplyDeploy (ctx context.Context , verify bool , state * statefile.StateData , acquiredLocks map [string ]string , checkLocks bool ) (* planAndApplyResults , error ) { // nolint: gocyclo
652+ func (d * Deploy ) planAndApply (ctx context.Context , verify bool , state * statefile.StateData , acquiredLocks map [string ]string , checkLocks bool ) (* planAndApplyResults , error ) { // nolint: gocyclo
648653 var domains []* apiv1.DomainInfo
649654
650655 ret := & planAndApplyResults {
651656 acquiredLocks : acquiredLocks ,
652657 }
653658 stateBefore := state .DeepCopy ()
654659
660+ monitoring := d .cfg .Monitoring .Proto ()
661+
662+ if d .opts .SkipMonitoring || d .opts .Destroy {
663+ monitoring = state .Monitoring
664+ } else {
665+ state .Monitoring = monitoring
666+ }
667+
655668 if d .opts .SkipDNS || d .opts .Destroy {
656669 domains = state .DomainsInfo
657670 } else {
@@ -715,12 +728,19 @@ func (d *Deploy) planAndApplyDeploy(ctx context.Context, verify bool, state *sta
715728 return nil , err
716729 }
717730
731+ monitoringChanges , err := d .planMonitoring (ctx , state , monitoring , verify , destroy )
732+ if err != nil {
733+ spinner .Stop ()
734+
735+ return nil , err
736+ }
737+
718738 spinner .Stop ()
719739
720740 deployChanges := computeDeployChange (d .cfg , & oldState , state , planRetMap )
721741 dnsChanges := computeDNSChange (d .cfg , & oldState , state , planDNSRetMap )
722742
723- ret .empty , ret .canceled , ret .missingLocks = d .promptDiff (deployChanges , dnsChanges , acquiredLocks , checkLocks )
743+ ret .empty , ret .canceled , ret .missingLocks = d .promptDiff (deployChanges , dnsChanges , monitoringChanges , acquiredLocks , checkLocks )
724744 if len (ret .missingLocks ) != 0 {
725745 return ret , nil
726746 }
@@ -749,6 +769,13 @@ func (d *Deploy) planAndApplyDeploy(ctx context.Context, verify bool, state *sta
749769 prog .Stop ()
750770 }
751771
772+ if err == nil {
773+ prog , cb := applyProgress (d .log , monitoringChanges )
774+ err = d .applyMonitoring (context .Background (), state , monitoring , destroy , cb )
775+
776+ prog .Stop ()
777+ }
778+
752779 if err == nil {
753780 err = d .postApplyHook (ctx , state , apps , deps , verify , destroy )
754781 }
@@ -1425,3 +1452,45 @@ func (d *Deploy) applyDNS(ctx context.Context, state *statefile.StateData, planM
14251452
14261453 return g .Wait ()
14271454}
1455+
1456+ func (d * Deploy ) planMonitoring (ctx context.Context , state * statefile.StateData , monitoring * apiv1.MonitoringData , verify , destroy bool ) ([]* change , error ) {
1457+ if monitoring .Plugin == "" {
1458+ return nil , nil
1459+ }
1460+
1461+ plug := d .cfg .FindLoadedPlugin (monitoring .Plugin )
1462+ if plug == nil {
1463+ return nil , merry .Errorf ("missing monitoring plugin: %s" , plug .Name )
1464+ }
1465+
1466+ ret , err := plug .Client ().PlanMonitoring (ctx , state , monitoring , plug .CommandArgs (deployCommand ), verify , destroy )
1467+ if err != nil {
1468+ return nil , err
1469+ }
1470+
1471+ mergeState (state , plug .Name , ret .State , nil , nil , nil , nil )
1472+
1473+ chg := computeChangeInfo (d .cfg , state , plug , ret .Plan .Actions )
1474+
1475+ return chg , nil
1476+ }
1477+
1478+ func (d * Deploy ) applyMonitoring (ctx context.Context , state * statefile.StateData , monitoring * apiv1.MonitoringData , destroy bool , callback func (* apiv1.ApplyAction )) error {
1479+ if monitoring .Plugin == "" {
1480+ return nil
1481+ }
1482+
1483+ plug := d .cfg .FindLoadedPlugin (monitoring .Plugin )
1484+ if plug == nil {
1485+ return merry .Errorf ("missing monitoring plugin: %s" , plug .Name )
1486+ }
1487+
1488+ ret , err := plug .Client ().ApplyMonitoring (ctx , state , monitoring , plug .CommandArgs (deployCommand ), destroy , callback )
1489+ if err != nil {
1490+ return err
1491+ }
1492+
1493+ mergeState (state , plug .Name , ret .State , nil , nil , nil , nil )
1494+
1495+ return nil
1496+ }
0 commit comments