Skip to content

Commit

Permalink
update for handle failed deployment case
Browse files Browse the repository at this point in the history
update message to show error or success

update error text

update text
  • Loading branch information
nullfunc committed Jun 25, 2024
1 parent f235ae5 commit 3c678e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
const DEFANG_PORTAL_HOST = "portal.defang.dev"
const SERVICE_PORTAL_URL = "https://" + DEFANG_PORTAL_HOST + "/service"

var ErrorFailedToReachRunningState = errors.New("failed to reach running state")
var ErrorDeploymentFailed = errors.New("deployment failed")

const authNeeded = "auth-needed" // annotation to indicate that a command needs authorization
var authNeededAnnotation = map[string]string{authNeeded: ""}

Expand Down Expand Up @@ -828,6 +831,7 @@ var composeUpCmd = &cobra.Command{

tailCtx, cancelTail := context.WithCancel(ctx)

deploymentFailed := false
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand All @@ -841,15 +845,20 @@ var composeUpCmd = &cobra.Command{
}
}()
if err := waitServiceStatus(ctx, cli.ServiceStarted, serviceInfos); err != nil && !errors.Is(err, context.Canceled) {
if !errors.Is(err, cli.ErrDryRun) && !errors.As(err, new(cliClient.ErrNotImplemented)) {
if errors.Is(err, ErrorDeploymentFailed) {
term.Warn("Deployment FAILED. Service(s) not running.")
deploymentFailed = true
} else {
term.Warnf("failed to wait for service status: %v", err)
}
wg.Wait() // Wait until ctrl+c is pressed
}
cancelTail()
wg.Wait() // Wait for tail to finish

printEndpoints(serviceInfos)
if !deploymentFailed {
printEndpoints(serviceInfos)
}

term.Info("Done.")
return nil
},
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/cli/command/servicemonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"fmt"

"github.com/DefangLabs/defang/src/pkg/cli"
"github.com/DefangLabs/defang/src/pkg/term"
Expand Down Expand Up @@ -34,6 +33,11 @@ func waitServiceStatus(ctx context.Context, targetStatus cli.ServiceStatus, serv
continue
}

// exit on detecting a FAILED state
if newStatus.Status == string(cli.ServiceFailed) {
return ErrorDeploymentFailed
}

serviceStatus[newStatus.Name] = newStatus.Status

if allInStatus(targetStatus, serviceStatus) {
Expand All @@ -44,7 +48,7 @@ func waitServiceStatus(ctx context.Context, targetStatus cli.ServiceStatus, serv
}
}

return fmt.Errorf("service state monitoring terminated without all services reaching desired state: %s", targetStatus)
return ErrorFailedToReachRunningState
}

func allInStatus(targetStatus cli.ServiceStatus, serviceStatuses map[string]string) bool {
Expand Down

0 comments on commit 3c678e1

Please sign in to comment.