Skip to content

Commit

Permalink
chore: uri for backend services on svc deploy (#3650)
Browse files Browse the repository at this point in the history
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
  • Loading branch information
dannyrandall authored Jun 13, 2022
1 parent 1a7759c commit 33ee39e
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 178 deletions.
13 changes: 8 additions & 5 deletions internal/pkg/cli/svc_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,16 @@ func (o *deploySvcOpts) uriRecommendedActions() ([]string, error) {
}

network := "over the internet."
if o.svcType == manifest.BackendServiceType {
switch uri.AccessType {
case describe.URIAccessTypeInternal:
network = "from your internal network."
case describe.URIAccessTypeServiceDiscovery:
network = "with service discovery."
}
recs := []string{
fmt.Sprintf("You can access your service at %s %s", color.HighlightResource(uri), network),
}
return recs, nil

return []string{
fmt.Sprintf("You can access your service at %s %s", color.HighlightResource(uri.URI), network),
}, nil
}

func (o *deploySvcOpts) publishRecommendedActions() []string {
Expand Down
38 changes: 38 additions & 0 deletions internal/pkg/describe/backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"bytes"
"encoding/json"
"fmt"
"strings"
"text/tabwriter"

"github.com/aws/copilot-cli/internal/pkg/aws/elbv2"
"github.com/aws/copilot-cli/internal/pkg/aws/sessions"
"github.com/aws/copilot-cli/internal/pkg/docker/dockerengine"

cfnstack "github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/stack"
Expand All @@ -33,6 +36,7 @@ type BackendServiceDescriber struct {
store DeployedEnvServicesLister
initECSServiceDescribers func(string) (ecsDescriber, error)
initEnvDescribers func(string) (envDescriber, error)
initLBDescriber func(string) (lbDescriber, error)
ecsServiceDescribers map[string]ecsDescriber
envStackDescriber map[string]envDescriber
}
Expand All @@ -47,6 +51,17 @@ func NewBackendServiceDescriber(opt NewServiceConfig) (*BackendServiceDescriber,
ecsServiceDescribers: make(map[string]ecsDescriber),
envStackDescriber: make(map[string]envDescriber),
}
describer.initLBDescriber = func(envName string) (lbDescriber, error) {
env, err := opt.ConfigStore.GetEnvironment(opt.App, envName)
if err != nil {
return nil, fmt.Errorf("get environment %s: %w", envName, err)
}
sess, err := sessions.ImmutableProvider().FromRole(env.ManagerRoleARN, env.Region)
if err != nil {
return nil, err
}
return elbv2.New(sess), nil
}
describer.initECSServiceDescribers = func(env string) (ecsDescriber, error) {
if describer, ok := describer.ecsServiceDescribers[env]; ok {
return describer, nil
Expand Down Expand Up @@ -87,6 +102,7 @@ func (d *BackendServiceDescriber) Describe() (HumanJSONStringer, error) {
return nil, fmt.Errorf("list deployed environments for application %s: %w", d.app, err)
}

var routes []*WebServiceRoute
var configs []*ECSServiceConfig
var services []*ServiceDiscovery
var envVars []*containerEnvVar
Expand All @@ -96,6 +112,16 @@ func (d *BackendServiceDescriber) Describe() (HumanJSONStringer, error) {
if err != nil {
return nil, err
}
uri, err := d.URI(env)
if err != nil {
return nil, fmt.Errorf("retrieve service URI: %w", err)
}
if uri.AccessType == URIAccessTypeInternal {
routes = append(routes, &WebServiceRoute{
Environment: env,
URL: uri.URI,
})
}
svcParams, err := svcDescr.Params()
if err != nil {
return nil, fmt.Errorf("get stack parameters for environment %s: %w", env, err)
Expand Down Expand Up @@ -163,6 +189,7 @@ func (d *BackendServiceDescriber) Describe() (HumanJSONStringer, error) {
Type: manifest.BackendServiceType,
App: d.app,
Configurations: configs,
Routes: routes,
ServiceDiscovery: services,
Variables: envVars,
Secrets: secrets,
Expand All @@ -178,6 +205,7 @@ type backendSvcDesc struct {
Type string `json:"type"`
App string `json:"application"`
Configurations ecsConfigurations `json:"configurations"`
Routes []*WebServiceRoute `json:"routes"`
ServiceDiscovery serviceDiscoveries `json:"serviceDiscovery"`
Variables containerEnvVars `json:"variables"`
Secrets secrets `json:"secrets,omitempty"`
Expand Down Expand Up @@ -207,6 +235,16 @@ func (w *backendSvcDesc) HumanString() string {
fmt.Fprint(writer, color.Bold.Sprint("\nConfigurations\n\n"))
writer.Flush()
w.Configurations.humanString(writer)
if len(w.Routes) > 0 {
fmt.Fprint(writer, color.Bold.Sprint("\nRoutes\n\n"))
writer.Flush()
headers := []string{"Environment", "URL"}
fmt.Fprintf(writer, " %s\n", strings.Join(headers, "\t"))
fmt.Fprintf(writer, " %s\n", strings.Join(underline(headers), "\t"))
for _, route := range w.Routes {
fmt.Fprintf(writer, " %s\t%s\n", route.Environment, route.URL)
}
}
fmt.Fprint(writer, color.Bold.Sprint("\nService Discovery\n\n"))
writer.Flush()
w.ServiceDiscovery.humanString(writer)
Expand Down
Loading

0 comments on commit 33ee39e

Please sign in to comment.