From b704463e8abf6570013d110cac6653c554ea9062 Mon Sep 17 00:00:00 2001 From: Lionello Lunesu Date: Wed, 26 Jun 2024 10:48:08 -0700 Subject: [PATCH] make project optional for CD --- src/pkg/cli/bootstrap.go | 7 ++++--- src/pkg/cli/cert.go | 2 +- src/pkg/cli/client/byoc/aws/byoc.go | 2 +- src/pkg/cli/composeDown.go | 2 +- src/pkg/cli/configDelete.go | 2 +- src/pkg/cli/configList.go | 2 +- src/pkg/cli/configSet.go | 2 +- src/pkg/cli/getServices.go | 2 +- src/pkg/cli/tail.go | 6 +++++- src/tests/sanity/compose.yaml.convert | 28 ++++++++++++++++++++++++++ src/tests/sanity/compose.yaml.golden | 19 +++++++++++++++++ src/tests/sanity/compose.yaml.warnings | 1 + 12 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 src/tests/sanity/compose.yaml.convert create mode 100644 src/tests/sanity/compose.yaml.golden create mode 100644 src/tests/sanity/compose.yaml.warnings diff --git a/src/pkg/cli/bootstrap.go b/src/pkg/cli/bootstrap.go index 9f26a3db0..5974378ea 100644 --- a/src/pkg/cli/bootstrap.go +++ b/src/pkg/cli/bootstrap.go @@ -12,10 +12,11 @@ import ( func BootstrapCommand(ctx context.Context, client client.Client, command string) error { projectName, err := client.LoadProjectName(ctx) if err != nil { - return err + // Some CD commands don't require a project name, so we don't return an error here. + term.Debug("Failed to load project name:", err) } - term.Debug("Running CD command", command, "in project", projectName) + term.Debugf("Running CD command %s in project %q", command, projectName) if DoDryRun { return ErrDryRun } @@ -26,7 +27,7 @@ func BootstrapCommand(ctx context.Context, client client.Client, command string) return err } - return Tail(ctx, client, TailOptions{Etag: etag, Since: since}) + return tail(ctx, client, TailOptions{Etag: etag, Since: since}) } func BootstrapLocalList(ctx context.Context, client client.Client) error { diff --git a/src/pkg/cli/cert.go b/src/pkg/cli/cert.go index b4ebb852e..a2b3c12d5 100644 --- a/src/pkg/cli/cert.go +++ b/src/pkg/cli/cert.go @@ -31,7 +31,7 @@ func GenerateLetsEncryptCert(ctx context.Context, client cliClient.Client) error if err != nil { return err } - term.Debug("Generating TLS cert for project", projectName) + term.Debugf("Generating TLS cert for project %q", projectName) services, err := client.GetServices(ctx) if err != nil { diff --git a/src/pkg/cli/client/byoc/aws/byoc.go b/src/pkg/cli/client/byoc/aws/byoc.go index b06a57cae..8f9fc9d0b 100644 --- a/src/pkg/cli/client/byoc/aws/byoc.go +++ b/src/pkg/cli/client/byoc/aws/byoc.go @@ -471,7 +471,7 @@ func (b *ByocAws) Tail(ctx context.Context, req *defangv1.TailRequest) (client.S term.Debug("Tailing task", etag) etag = "" // no need to filter by etag } else { - // Tail CD, kaniko, and all services + // Tail CD, kaniko, and all services (this requires PulumiProject to be set) kanikoTail := ecs.LogGroupInput{LogGroupARN: b.driver.MakeARN("logs", "log-group:"+b.stackDir("builds"))} // must match logic in ecs/common.ts term.Debug("Tailing kaniko logs", kanikoTail.LogGroupARN) servicesTail := ecs.LogGroupInput{LogGroupARN: b.driver.MakeARN("logs", "log-group:"+b.stackDir("logs"))} // must match logic in ecs/common.ts diff --git a/src/pkg/cli/composeDown.go b/src/pkg/cli/composeDown.go index 0b5eae43c..fa37fc215 100644 --- a/src/pkg/cli/composeDown.go +++ b/src/pkg/cli/composeDown.go @@ -13,7 +13,7 @@ func ComposeDown(ctx context.Context, client client.Client) (types.ETag, error) if err != nil { return "", err } - term.Debug("Destroying project", projectName) + term.Debugf("Destroying project %q", projectName) if DoDryRun { return "", ErrDryRun diff --git a/src/pkg/cli/configDelete.go b/src/pkg/cli/configDelete.go index f390ce738..b1c0eb157 100644 --- a/src/pkg/cli/configDelete.go +++ b/src/pkg/cli/configDelete.go @@ -13,7 +13,7 @@ func ConfigDelete(ctx context.Context, client client.Client, names ...string) er if err != nil { return err } - term.Debug("Deleting config", names, "in project", projectName) + term.Debugf("Deleting config %v in project %q", names, projectName) if DoDryRun { return ErrDryRun diff --git a/src/pkg/cli/configList.go b/src/pkg/cli/configList.go index ad05f3e00..5346e4a00 100644 --- a/src/pkg/cli/configList.go +++ b/src/pkg/cli/configList.go @@ -12,7 +12,7 @@ func ConfigList(ctx context.Context, client client.Client) error { if err != nil { return err } - term.Debug("Listing config in project", projectName) + term.Debugf("Listing config in project %q", projectName) config, err := client.ListConfig(ctx) if err != nil { diff --git a/src/pkg/cli/configSet.go b/src/pkg/cli/configSet.go index f234d3773..92915718d 100644 --- a/src/pkg/cli/configSet.go +++ b/src/pkg/cli/configSet.go @@ -13,7 +13,7 @@ func ConfigSet(ctx context.Context, client client.Client, name string, value str if err != nil { return err } - term.Debug("Setting config", name, "in project", projectName) + term.Debugf("Setting config %q in project %q", name, projectName) if DoDryRun { return ErrDryRun diff --git a/src/pkg/cli/getServices.go b/src/pkg/cli/getServices.go index 03d5a7207..f3fcd188f 100644 --- a/src/pkg/cli/getServices.go +++ b/src/pkg/cli/getServices.go @@ -13,7 +13,7 @@ func GetServices(ctx context.Context, client client.Client, long bool) error { if err != nil { return err } - term.Debug("Listing services in project", projectName) + term.Debugf("Listing services in project %q", projectName) serviceList, err := client.GetServices(ctx) if err != nil { diff --git a/src/pkg/cli/tail.go b/src/pkg/cli/tail.go index 73ea30beb..41058432e 100644 --- a/src/pkg/cli/tail.go +++ b/src/pkg/cli/tail.go @@ -141,7 +141,7 @@ func Tail(ctx context.Context, client client.Client, params TailOptions) error { if err != nil { return err } - term.Debug("Tailing logs in project", projectName) + term.Debugf("Tailing logs in project %q", projectName) if len(params.Services) > 0 { for _, service := range params.Services { @@ -164,6 +164,10 @@ func Tail(ctx context.Context, client client.Client, params TailOptions) error { return ErrDryRun } + return tail(ctx, client, params) +} + +func tail(ctx context.Context, client client.Client, params TailOptions) error { ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/src/tests/sanity/compose.yaml.convert b/src/tests/sanity/compose.yaml.convert new file mode 100644 index 000000000..416571454 --- /dev/null +++ b/src/tests/sanity/compose.yaml.convert @@ -0,0 +1,28 @@ +[ + { + "name": "nginx", + "image": "nginx", + "platform": 2, + "internal": true, + "deploy": { + "replicas": 1, + "resources": { + "reservations": { + "memory": 256 + } + } + }, + "ports": [ + { + "target": 80, + "mode": 1 + } + ], + "secrets": [ + { + "source": "dummy" + } + ], + "networks": 1 + } +] \ No newline at end of file diff --git a/src/tests/sanity/compose.yaml.golden b/src/tests/sanity/compose.yaml.golden new file mode 100644 index 000000000..332d71c85 --- /dev/null +++ b/src/tests/sanity/compose.yaml.golden @@ -0,0 +1,19 @@ +name: sanity +services: + nginx: + deploy: + resources: + reservations: + memory: "268435456" + environment: + dummy: null + image: nginx + networks: + default: null + ports: + - mode: ingress + target: 80 + restart: unless-stopped +networks: + default: + name: sanity_default diff --git a/src/tests/sanity/compose.yaml.warnings b/src/tests/sanity/compose.yaml.warnings new file mode 100644 index 000000000..43e58b7ed --- /dev/null +++ b/src/tests/sanity/compose.yaml.warnings @@ -0,0 +1 @@ +level=warning msg="service \"nginx\": ingress port without healthcheck defaults to GET / HTTP/1.1" \ No newline at end of file