Skip to content

Commit

Permalink
feat: Render interactive output (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws authored Nov 7, 2023
2 parents d5f4015 + f420661 commit 4c00476
Show file tree
Hide file tree
Showing 23 changed files with 3,326 additions and 1,393 deletions.
33 changes: 30 additions & 3 deletions cloud/aws/deploy/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ package deploy
import (
"context"

tea "github.com/charmbracelet/bubbletea"
commonDeploy "github.com/nitrictech/nitric/cloud/common/deploy"
"github.com/nitrictech/nitric/cloud/common/deploy/output/interactive"
"github.com/nitrictech/nitric/cloud/common/deploy/output/noninteractive"
pulumiutils "github.com/nitrictech/nitric/cloud/common/deploy/pulumi"
deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/auto/events"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -34,18 +38,41 @@ func (d *DeployServer) Down(request *deploy.DeployDownRequest, stream deploy.Dep
return status.Errorf(codes.InvalidArgument, err.Error())
}

// TODO: Tear down the requested stack
dsMessageWriter := &pulumiutils.DownStreamMessageWriter{
// If we're interactive then we want to provide
outputStream := &pulumiutils.DownStreamMessageWriter{
Stream: stream,
}

pulumiDestroyOpts := []optdestroy.Option{
optdestroy.ProgressStreams(noninteractive.NewNonInterativeOutput(outputStream)),
}

if request.Interactive {
pulumiEventChan := make(chan events.EngineEvent)
deployModel, err := interactive.NewOutputModel(make(chan tea.Msg), pulumiEventChan)
if err != nil {
return err
}

teaProgram := tea.NewProgram(deployModel, tea.WithOutput(outputStream))
pulumiDestroyOpts = []optdestroy.Option{
optdestroy.ProgressStreams(deployModel),
optdestroy.EventStreams(pulumiEventChan),
}

//nolint:errcheck
go teaProgram.Run()
// Close the program when we're done
defer teaProgram.Quit()
}

s, err := auto.UpsertStackInlineSource(context.TODO(), details.FullStackName, details.Project, nil)
if err != nil {
return status.Errorf(codes.Internal, err.Error())
}

// destroy the stack
_, err = s.Destroy(context.TODO(), optdestroy.ProgressStreams(dsMessageWriter))
_, err = s.Destroy(context.TODO(), pulumiDestroyOpts...)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 4c00476

Please sign in to comment.