Skip to content

Add --json to cd command #1142

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

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
**Develop Anything. Deploy Anywhere.** <br>
Take your app from Docker Compose to a secure and scalable deployment on your favorite cloud in minutes.

**Defang CLI**
**Defang CLI**
The Defang Command-Line Interface [(CLI)](https://docs.defang.io/docs/getting-started) is designed for developers who prefer to manage their workflows directly from the terminal. It offers full access to Defang’s capabilities, allowing you to build, test, and deploy applications efficiently to the cloud.

**Defang MCP Server**
**Defang MCP Server**
The Defang Model Context Protocol [(MCP)](https://docs.defang.io/docs/concepts/mcp) Server is tailored for developers who work primarily within integrated development environments (IDEs). It enables seamless cloud deployment from supported editors such as Cursor, Windsurf, VS Code, VS Code Insiders and Claude delivering a fully integrated experience without leaving your development environment.

**This repo includes:**

- Public releases of the Defang CLI; [click here](https://github.com/DefangLabs/defang/releases/latest/) for the latest version
- Built-in support for MCP Server — the Defang MCP Server makes cloud deployment as easy as a single prompt. [Learn more](https://docs.defang.io/docs/concepts/mcp)
- Built-in support for MCP Server — the Defang MCP Server makes cloud deployment as easy as a single prompt. [Learn more](https://docs.defang.io/docs/concepts/mcp)
- [Samples](https://github.com/DefangLabs/samples) in Golang, Python, and Node.js that show how to accomplish various tasks and deploy them to the DOP using a Docker Compose file using the Defang CLI.
- Samples that show how to deploy an app using the [Defang Pulumi Provider](https://github.com/DefangLabs/pulumi-defang).

Expand Down Expand Up @@ -119,6 +119,7 @@ The Defang CLI recognizes the following environment variables:
- `DEFANG_DEBUG` - set this to `1` or `true` to enable debug logging
- `DEFANG_DISABLE_ANALYTICS` - If set to `true`, disables sending analytics to Defang; defaults to `false`
- `DEFANG_FABRIC` - The address of the Defang Fabric to use; defaults to `fabric-prod1.defang.dev`
- `DEFANG_JSON` - If set to `true`, outputs JSON instead of human-readable output; defaults to `false`
- `DEFANG_HIDE_HINTS` - If set to `true`, hides hints in the CLI output; defaults to `false`
- `DEFANG_HIDE_UPDATE` - If set to `true`, hides the update notification; defaults to `false`
- `DEFANG_MODEL_ID` - The model ID of the LLM to use for the generate/debug AI integration (Pro users only)
Expand Down
11 changes: 9 additions & 2 deletions src/cmd/cli/command/cd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command

import (
"os"

"github.com/DefangLabs/defang/src/pkg/cli"
cliClient "github.com/DefangLabs/defang/src/pkg/cli/client"
"github.com/spf13/cobra"
Expand All @@ -9,16 +11,21 @@ import (
var cdCmd = &cobra.Command{
Use: "cd",
Aliases: []string{"bootstrap"},
Args: cobra.NoArgs,
Short: "Manually run a command with the CD task (for BYOC only)",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
var utc, _ = cmd.Flags().GetBool("utc")
var json, _ = cmd.Flags().GetBool("json")

if utc {
cli.EnableUTCMode()
}

return nil
if json {
os.Setenv("DEFANG_JSON", "1")
verbose = true
}
},
}

Expand Down
5 changes: 4 additions & 1 deletion src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func Execute(ctx context.Context) error {
}

func SetupCommands(ctx context.Context, version string) {
cobra.EnableTraverseRunHooks = true // we always need to run the RootCmd's pre-run hook

RootCmd.Version = version
RootCmd.PersistentFlags().Var(&colorMode, "color", fmt.Sprintf(`colorize output; one of %v`, allColorModes))
RootCmd.PersistentFlags().StringVarP(&cluster, "cluster", "s", cli.DefangFabric, "Defang cluster to connect to")
Expand All @@ -164,7 +166,8 @@ func SetupCommands(ctx context.Context, version string) {

// CD command
RootCmd.AddCommand(cdCmd)
cdCmd.Flags().Bool("utc", false, "show logs in UTC timezone (ie. TZ=UTC)")
cdCmd.PersistentFlags().Bool("utc", false, "show logs in UTC timezone (ie. TZ=UTC)")
cdCmd.PersistentFlags().Bool("json", pkg.GetenvBool("DEFANG_JSON"), "show logs in JSON format")
cdCmd.PersistentFlags().StringVar(&byoc.DefangPulumiBackend, "pulumi-backend", "", `specify an alternate Pulumi backend URL or "pulumi-cloud"`)
cdCmd.AddCommand(cdDestroyCmd)
cdCmd.AddCommand(cdDownCmd)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/cli/client/byoc/aws/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ func (b *ByocAws) environment(projectName string) (map[string]string, error) {
env := map[string]string{
// "AWS_REGION": region.String(), should be set by ECS (because of CD task role)
"DEFANG_DEBUG": os.Getenv("DEFANG_DEBUG"), // TODO: use the global DoDebug flag
"DEFANG_JSON": os.Getenv("DEFANG_JSON"),
"DEFANG_ORG": b.TenantName,
"DEFANG_PREFIX": byoc.DefangPrefix,
"DEFANG_STATE_URL": defangStateUrl,
Expand Down
6 changes: 5 additions & 1 deletion src/pkg/cli/client/byoc/do/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,11 @@ func (b *ByocDo) environment(projectName, delegateDomain string) ([]*godo.AppVar
},
{
Key: "DEFANG_DEBUG",
Value: pkg.Getenv("DEFANG_DEBUG", "false"),
Value: os.Getenv("DEFANG_DEBUG"),
},
{
Key: "DEFANG_JSON",
Value: os.Getenv("DEFANG_JSON"),
},
{
Key: "DEFANG_ORG",
Expand Down
1 change: 1 addition & 0 deletions src/pkg/cli/client/byoc/gcp/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) (string, erro
}
env := map[string]string{
"DEFANG_DEBUG": os.Getenv("DEFANG_DEBUG"), // TODO: use the global DoDebug flag
"DEFANG_JSON": os.Getenv("DEFANG_JSON"),
"DEFANG_MODE": strings.ToLower(cmd.Mode.String()),
"DEFANG_ORG": "defang",
"DEFANG_PREFIX": byoc.DefangPrefix,
Expand Down
Loading