Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update app show to display if workload is deployed #3379

Merged
merged 16 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 60 additions & 10 deletions internal/pkg/cli/app_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ package cli

import (
"fmt"
"io"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/copilot-cli/internal/pkg/aws/identity"
"golang.org/x/net/context"
"golang.org/x/sync/errgroup"
"io"
"sort"
"sync"

"github.com/aws/copilot-cli/internal/pkg/aws/codepipeline"
"github.com/aws/copilot-cli/internal/pkg/aws/sessions"
Expand Down Expand Up @@ -40,18 +43,25 @@ type showAppOpts struct {
w io.Writer
sel appSelector
pipelineSvc pipelineGetter
deployStore deployedEnvironmentLister
newVersionGetter func(string) (versionGetter, error)
}

func newShowAppOpts(vars showAppVars) (*showAppOpts, error) {
defaultSession, err := sessions.ImmutableProvider(sessions.UserAgentExtras("app show")).Default()
sessProvider := sessions.ImmutableProvider(sessions.UserAgentExtras("app show"))
defaultSession, err := sessProvider.Default()
if err != nil {
return nil, fmt.Errorf("default session: %w", err)
}
store := config.NewSSMStore(identity.New(defaultSession), ssm.New(defaultSession), aws.StringValue(defaultSession.Config.Region))
deployStore, err := deploy.NewStore(sessProvider, store)
if err != nil {
return nil, fmt.Errorf("connect to deploy store: %w", err)
}
return &showAppOpts{
showAppVars: vars,
store: store,
deployStore: deployStore,
w: log.OutputWriter,
sel: selector.NewSelect(prompt.New(), store),
pipelineSvc: codepipeline.New(defaultSession),
Expand Down Expand Up @@ -105,6 +115,7 @@ func (o *showAppOpts) Execute() error {
}

func (o *showAppOpts) description() (*describe.App, error) {
wkldDeployedtoEnvs := make(map[string][]string)
app, err := o.store.GetApplication(o.name)
if err != nil {
return nil, fmt.Errorf("get application %s: %w", o.name, err)
Expand All @@ -121,7 +132,45 @@ func (o *showAppOpts) description() (*describe.App, error) {
if err != nil {
return nil, fmt.Errorf("list jobs in application %s: %w", o.name, err)
}
var mux sync.Mutex
g, ctx := errgroup.WithContext(context.Background())
defer ctx.Done()
for i := range envs {
env := envs[i]
g.Go(func() error {
deployedJobs, err := o.deployStore.ListDeployedJobs(o.name, env.Name)
if err != nil {
return fmt.Errorf("list jobs deployed to %s: %w", env.Name, err)
}

mux.Lock()
defer mux.Unlock()
for _, job := range deployedJobs {
wkldDeployedtoEnvs[job] = append(wkldDeployedtoEnvs[job], env.Name)
}
return nil
})
g.Go(func() error {
deployedSvcs, err := o.deployStore.ListDeployedServices(o.name, env.Name)
if err != nil {
return fmt.Errorf("list services deployed to %s: %w", env.Name, err)
}
mux.Lock()
defer mux.Unlock()
for _, svc := range deployedSvcs {
wkldDeployedtoEnvs[svc] = append(wkldDeployedtoEnvs[svc], env.Name)
}
return nil
})
}
if err := g.Wait(); err != nil {
return nil, err
}
// Sort the map values so that `output` is consistent and the unit test won't be flaky.
for key, value := range wkldDeployedtoEnvs {
sort.Strings(value)
wkldDeployedtoEnvs[key] = value
}
pipelines, err := o.pipelineSvc.GetPipelinesByTags(map[string]string{
deploy.AppTagKey: o.name,
})
Expand Down Expand Up @@ -162,13 +211,14 @@ func (o *showAppOpts) description() (*describe.App, error) {
return nil, fmt.Errorf("get version for application %s: %w", o.name, err)
}
return &describe.App{
Name: app.Name,
Version: version,
URI: app.Domain,
Envs: trimmedEnvs,
Services: trimmedSvcs,
Jobs: trimmedJobs,
Pipelines: pipelines,
Name: app.Name,
Version: version,
URI: app.Domain,
Envs: trimmedEnvs,
Services: trimmedSvcs,
Jobs: trimmedJobs,
Pipelines: pipelines,
WkldDeployedtoEnvs: wkldDeployedtoEnvs,
}, nil
}

Expand Down
Loading