### Install Defang MCP Server Setup Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Run this command to set up the Defang MCP Server for your chosen IDE client. Ensure the Defang CLI is installed first. Restart your IDE after setup. ```bash defang mcp setup --client= ``` -------------------------------- ### Install Dependencies Source: https://github.com/defanglabs/defang-docs/blob/main/AGENTS.md Use this command to install project dependencies. ```bash npm install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/defanglabs/defang-docs/blob/main/README.md Starts a local development server and automatically opens the website in your browser. Useful for testing changes during development. ```bash $ npm run start ``` -------------------------------- ### Install Defang MCP Server via NPX Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Alternative installation method using npx. This is supported but not recommended. ```bash npx -y defang@latest mcp setup --client= ``` -------------------------------- ### Install Defang CLI Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-10-10-n8n-aws-deployment.md Installs the Defang CLI tool. Run this command in your terminal to get started. ```bash eval "$(curl -fsSL s.defang.io/install)" ``` -------------------------------- ### Install MCP Server for IDEs Source: https://context7.com/defanglabs/defang-docs/llms.txt Commands to install the MCP server for various IDEs. Use the specific command for your IDE or the npx alternative if preferred. ```bash # Install MCP server for your IDE defang mcp setup --client=vscode defang mcp setup --client=cursor defang mcp setup --client=claude-code defang mcp setup --client=windsurf # npx alternative (not recommended) npx -y defang@latest mcp setup --client=vscode ``` -------------------------------- ### Setup MCP Client for VS Code Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP client for VS Code. After setup, you can interact with the AI coding agent. ```bash defang mcp setup --client=vscode ``` -------------------------------- ### Example IDE Chat Prompts for MCP Source: https://context7.com/defanglabs/defang-docs/llms.txt Example prompts to use with AI coding assistants after setting up the MCP server. These demonstrate how to interact with Defang services via chat. ```text # Example IDE chat prompts after MCP setup: "can you deploy this to defang?" "what services do I have?" "please destroy this project." "can you estimate balance mode on aws for this project?" "set the defang config DATABASE_URL to example.com" "list all the defang configs I have set for this project" ``` -------------------------------- ### Install Defang CLI Source: https://context7.com/defanglabs/defang-docs/llms.txt Install the Defang CLI using a shell script, Homebrew, Winget, or Nix. ```bash eval "$(curl -fsSL s.defang.io/install)" ``` ```bash brew install DefangLabs/defang/defang ``` ```bash winget install defang ``` ```bash nix profile install github:DefangLabs/defang#defang-bin --refresh ``` -------------------------------- ### Example Cost Estimation Output Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/estimation.md This example shows the estimated monthly cost for deploying the django-postgres sample to AWS using the balanced deployment mode. It includes a breakdown of costs per service and a total estimated monthly cost. ```bash defang estimate --provider=aws --mode=balanced * Packaging the project files for django at /Users/defang/samples/samples/django-postgres/app * Generating deployment preview * Preparing estimate Estimate for Deployment Mode: BALANCED This mode strikes a balance between cost and availability. Your application will be deployed with spot instances. Databases will be provisioned using resources optimized for production. Services in the "internal" network will be deployed to a private subnet with a NAT gateway for outbound internet access. Cost Quantity Service Description $16.43 730 Hours (shared) AWSELB USW2-LoadBalancerUsage $32.85 730 Hours (shared) AmazonEC2 USW2-NatGateway-Hours $25.00 100 %Utilized/mo db AmazonRDS USW2-InstanceUsage:db.r5.large $1.62 14600 GB-Hours django AmazonECS USW2-Fargate-EphemeralStorage-GB-Hours (20 GB * 730 hours) $1.62 365 GB-Hours django AmazonECS USW2-Fargate-GB-Hours (0.50 GB * 730 hours) -$1.14 365 GB-Hours django AmazonECS USW2-Fargate-GB-Hours-SpotDiscount (Estimated @ 70%) $7.39 182.50 vCPU-Hours django AmazonECS USW2-Fargate-vCPU-Hours:perCPU (0.25 vCPU * 730 hours) -$5.17 182.50 vCPU-Hours django AmazonECS USW2-Fargate-vCPU-Hours:perCPU-SpotDiscount (Estimated @ 70%) Estimated Monthly Cost: $78.60 (+ usage) Estimate does not include taxes or Discount Programs. To estimate other modes, use defang estimate --mode=affordable|balanced|high_availability For help with warnings, check our FAQ at https://s.defang.io/warnings ``` -------------------------------- ### Deploy Project Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/agent-skills.md Navigate to your project directory and execute this command to deploy. The agent will guide you through the deployment steps. ```shell /defang:deploy ``` -------------------------------- ### Initialize Heroku Migration Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-09-25-heroku-migration.md Run this command after installing and logging into the Defang CLI to start the migration process from Heroku. It prompts you to select the 'Migrate from Heroku' option. ```bash defang init ``` -------------------------------- ### Setup Defang MCP Server for Kiro Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP Server specifically for the Kiro IDE. After setup, interact with the AI agent using Defang actions. ```bash defang mcp setup --client=kiro ``` -------------------------------- ### Install Defang CLI with Homebrew Source: https://github.com/defanglabs/defang-docs/blob/main/docs/intro/getting-started.mdx Installs the Defang CLI using Homebrew. Ensure you have Homebrew installed. ```bash brew install DefangLabs/defang/defang ``` -------------------------------- ### Setup MCP Client for Windsurf Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP client for Windsurf. After setup, you can interact with the AI coding agent. ```bash defang mcp setup --client=windsurf ``` -------------------------------- ### Non-CI/CD Stack Configuration Example Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/deploying-from-github-actions/to-aws.mdx This example shows a `.defang/` stack configuration that is NOT compatible with CI/CD due to the inclusion of `AWS_PROFILE`. Remove the `AWS_PROFILE` line for deployments from GitHub Actions. ```bash # .defang/production - NOT CI/CD compatible (will fail) AWS_PROFILE="my-local-profile" # Remove this line AWS_REGION="us-west-2" DEFANG_PROVIDER="aws" ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/defanglabs/defang-docs/blob/main/README.md Installs all necessary Node.js dependencies for the project. Ensure you have cloned the required repositories in sibling directories. ```bash $ npm install ``` -------------------------------- ### Setup Defang MCP Server for Claude Desktop Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP Server specifically for the Claude Desktop client. After setup, interact with the AI agent using Defang actions. ```bash defang mcp setup --client=claude-desktop ``` -------------------------------- ### Setup Defang MCP Server for Cursor Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP Server specifically for the Cursor IDE. After setup, interact with the AI agent using Defang actions. ```bash defang mcp setup --client=cursor ``` -------------------------------- ### Example GitHub New Repository URL Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/adding-custom-one-click-deploy.md This is an example of the URL generated when creating a new repository from a template. It includes parameters for the template name and owner. ```text https://github.com/new?template_name=&template_owner= ``` -------------------------------- ### Initialize Defang for Heroku Migration Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/migrating-from-heroku.md Start the Defang initialization process and select the 'Migrate from Heroku' option. ```bash $ defang init ? How would you like to start? [Use arrows to move, type to filter] Generate with AI Clone a sample > Migrate from Heroku ``` -------------------------------- ### Start Local Development Server Source: https://github.com/defanglabs/defang-docs/blob/main/AGENTS.md Runs the local development server with hot-reloading. This command also executes the prebuild script. ```bash npm run start ``` -------------------------------- ### Example Managed MongoDB Configuration Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/managed-storage/managed-mongodb.md This example shows how to define a managed MongoDB service using the `x-defang-mongodb` extension in your `compose.yaml`. It includes environment variables for the database name and connection string. ```yaml services: app: # [...] environment: DB_URL: mongodb://$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@db:27017/ depends_on: - db db: image: mongo:5 x-defang-mongodb: true environment: MONGO_INITDB_DATABASE: mydb ``` -------------------------------- ### Install Defang CLI with Nix Source: https://github.com/defanglabs/defang-docs/blob/main/docs/intro/getting-started.mdx Installs the Defang CLI using Nix. This command ensures your Nix profile is up-to-date before installation. ```bash nix profile install github:DefangLabs/defang#defang-bin --refresh ``` -------------------------------- ### Install Defang CLI with Winget Source: https://github.com/defanglabs/defang-docs/blob/main/docs/intro/getting-started.mdx Installs the Defang CLI on Windows using Winget. This is a convenient option for Windows users. ```powershell winget install defang ``` -------------------------------- ### Setup MCP Client for VS Code Insiders Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP client for VS Code Insiders. After setup, you can interact with the AI coding agent. ```bash defang mcp setup --client=vscode-insiders ``` -------------------------------- ### Setup Defang MCP Server for Rovo Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP Server specifically for the Rovo platform. After setup, interact with the AI agent using Defang actions. ```bash defang mcp setup --client=rovo ``` -------------------------------- ### List Running Defang Services Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/using-codespaces-gitpod.md After successfully logging in, use this command to verify your Defang setup by listing any currently running services. This confirms that Defang is operational in your environment. ```bash defang ls ``` -------------------------------- ### Heroku Add-on Information Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/migrating-from-heroku.md Example output listing a PostgreSQL database add-on for a Heroku application. ```bash heroku addons -a vast-badlands-production Add-on Plan Price Max price State ────────────────────────────────────────── ─────────── ──────────── ───────── ─────── heroku-postgresql (postgresql-rosy-12345) essential-0 ~$0.007/hour $5/month created └─ as DATABASE ``` -------------------------------- ### Defang Deployment Output Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/deploy-to-playground.mdx This is an example of the output you will see during and after a successful deployment. It includes build context upload, service deployment status, a link to monitor services, and the final URL where your service will be available. ```bash * Uploading build context for app * Deploying service app * Monitor your services' status in the defang portal - https://portal.defang.dev/service/app * Tailing logs for deployment ID o59k89vk3qc8 ; press Ctrl+C to detach: * Press V to toggle verbose mode 2024-09-19T10:50:53.572443-07:00 cd Update started for stack jordanstephens-prod1 2024-09-19T10:51:05.536299-07:00 cd Update succeeded in 11.99769745s ; provisioning... 2024-09-19T10:51:39.419693-07:00 app Server running at http://0.0.0.0:3000/ * Service app is in state DEPLOYMENT_COMPLETED and will be available at: - https://jordanstephens-app--3000.prod1.defang.dev * Done. ``` -------------------------------- ### Initial Compose File Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/deploy-openai-apps/aws-bedrock.mdx This is the starting point for a Docker Compose file with a single application service. ```yaml services: app: build: context: . ports: - 3000:3000 environment: OPENAI_API_KEY: healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/"] ``` -------------------------------- ### Install Defang Pulumi Provider with npm Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/pulumi.md Use this command to add the Defang Pulumi provider to your project when using npm. ```bash npm i @defang-io/pulumi-defang ``` -------------------------------- ### Setup Defang MCP Server for Claude Code Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md Use this command to set up the Defang MCP Server specifically for the Claude Code client. After setup, interact with the AI agent using Defang actions. ```bash defang mcp setup --client=claude-code ``` -------------------------------- ### Install Defang Pulumi Provider with pnpm Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/pulumi.md Use this command to add the Defang Pulumi provider to your project when using pnpm. ```bash pnpm i @defang-io/pulumi-defang ``` -------------------------------- ### Clone Repositories Source: https://github.com/defanglabs/defang-docs/blob/main/README.md Clones the defanglabs/defang and defanglabs/samples repositories into sibling directories. This is a prerequisite for installation. ```bash $ git clone https://github.com/DefangLabs/defang.git ../defang $ git clone https://github.com/DefangLabs/samples.git ../samples ``` -------------------------------- ### Heroku Dyno Information Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/migrating-from-heroku.md Example output showing a single 'web' dyno for a Heroku application. ```bash $ heroku ps -a vast-badlands-production === web (Eco): bin/rails server -p ${PORT:-5000} -e $RAILS_ENV (1) ``` -------------------------------- ### Tail Live Logs for All Services Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/monitoring-your-services.md Use this command to view real-time logs from all your deployed services. Ensure the Defang CLI is installed and configured. ```bash $ defang tail ``` -------------------------------- ### Build and Run Docker Compose Locally Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-02-18-model-context-protocol.md Use this command to build your Docker images and start your application services locally. ```bash docker compose up --build ``` -------------------------------- ### Complete Example Compose File for AWS Bedrock Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/deploy-openai-apps/aws-bedrock.mdx This is the complete Docker Compose file configuration for deploying an OpenAI app to AWS Bedrock using Defang's openai-access-gateway. ```yaml services: app: build: context: . ports: - 3000:3000 environment: OPENAI_API_KEY: OPENAI_BASE_URL: "http://llm/api/v1" MODEL: "anthropic.claude-3-sonnet-20240229-v1:0" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/"] llm: image: defangio/openai-access-gateway x-defang-llm: true ports: - target: 80 published: 80 mode: host environment: - OPENAI_API_KEY - REGION ``` -------------------------------- ### Clone Sample Project Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/estimating-gcp-deployment-costs.md Clone a sample project and navigate into its directory to prepare for cost estimation. ```bash defang generate # select `django-postgres` (or any other sample) from the list cd django-postgres # or the name of your project's working directory ``` -------------------------------- ### Run Defang CLI without Global Installation Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2024-05-01-may-product-updates.md Use npx to execute the latest Defang CLI version without needing to install it globally. This simplifies getting started and ensures you're always using the most recent release. ```bash npx defang@latest ``` -------------------------------- ### Manual MCP Server Configuration Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/mcp.md This JSON configuration can be manually added to your IDE's MCP file to set up the Defang MCP Server without using the setup command or installing the Defang CLI. ```json { "mcpServers": { "defang": { "command": "npx", "args": ["-y", "defang@latest", "mcp", "serve"] } } } ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/migrating-from-heroku.md Change to your project's working directory before running `defang init`. ```bash $ cd ~/w/vast-badlands $ ls Gemfile Procfile Rakefile bin config.ru lib public test vendor Gemfile.lock README.md app config db log storage tmp ``` -------------------------------- ### Verify Defang CLI Installation Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-10-10-n8n-aws-deployment.md Checks if the Defang CLI has been installed correctly. Use this after installation to confirm. ```bash defang version ``` -------------------------------- ### Build and Deploy with `defang compose up` Source: https://context7.com/defanglabs/defang-docs/llms.txt Build and deploy applications defined in `compose.yaml`. This command uploads source code, builds images in-cloud, provisions resources, and tails logs. Specify the cloud provider using `--provider` or the `DEFANG_PROVIDER` environment variable. Deployment modes like `high_availability` can also be set. ```bash # Deploy to Defang Playground (default, non-production) defang compose up # Deploy to AWS BYOC defang compose up --provider=aws # Deploy to GCP defang compose up --provider=gcp # Deploy with a specific deployment mode defang compose up --provider=aws --mode=high_availability # Using environment variable instead of flag export DEFANG_PROVIDER=digitalocean defang compose up # Expected output: # * Uploading build context for app # * Deploying service app # * Tailing logs for deployment ID o59k89vk3qc8 ; press Ctrl+C to detach: # 2024-09-19T10:51:39 app Server running at http://0.0.0.0:3000/ # * Service app is in state DEPLOYMENT_COMPLETED and will be available at: # - https://alice-app--3000.prod1.defang.dev ``` -------------------------------- ### Install Defang Pulumi Provider Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/pulumi.md Install the Defang Pulumi provider in your Pulumi project using npm, pnpm, or yarn. ```bash npm i @defang-io/pulumi-defang pnpm i @defang-io/pulumi-defang yarn add @defang-io/pulumi-defang ``` -------------------------------- ### Serve Production Build Source: https://github.com/defanglabs/defang-docs/blob/main/AGENTS.md Tests the generated production build by serving it locally. ```bash npm run serve ``` -------------------------------- ### Configure Managed Postgres with Defang Source: https://context7.com/defanglabs/defang-docs/llms.txt Demonstrates setting up a managed PostgreSQL instance using Defang's `x-defang-postgres` extension. Requires setting the password and SSL mode via `defang config set` before deployment. ```bash # Must set the password before deploying defang config set POSTGRES_PASSWORD=mysecretpassword defang config set SSL_MODE=require ``` -------------------------------- ### Defang Compose Deployment Modes Source: https://context7.com/defanglabs/defang-docs/llms.txt Demonstrates how to deploy applications using different Defang compose modes: affordable (development/test), balanced (staging), and high_availability (production). Each mode affects cost, logging, and update strategies. ```bash # Development — spot instances, 1-day logs, no rolling updates defang compose up --provider=aws --mode=affordable # Staging — 7-day logs, single NAT gateway defang compose up --provider=aws --mode=balanced # Production — on-demand instances, 30-day logs, rolling updates, multiple NAT gateways defang compose up --provider=aws --mode=high_availability ``` -------------------------------- ### Generate HTTP GET Endpoint for Memes Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/generate.md Use this prompt to generate an HTTP GET endpoint that returns an HTML page with a random meme from the imgflip API. ```text An HTTP GET endpoint that returns an HTML with a random meme from the imgflip API ``` -------------------------------- ### Deploy Application Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-09-25-heroku-migration.md Execute this command to provision AWS infrastructure (ECS, RDS, VPC, etc.) and deploy your application. Defang handles database readiness and service startup. ```bash defang up ``` -------------------------------- ### Build for Production Source: https://github.com/defanglabs/defang-docs/blob/main/AGENTS.md Generates production-ready static output for the documentation site. ```bash npm run build ``` -------------------------------- ### Deploy Project to DigitalOcean Source: https://github.com/defanglabs/defang-docs/blob/main/docs/providers/digitalocean.md Use the `--provider=digitalocean` flag or set the `DEFANG_PROVIDER` environment variable to deploy your project using the DigitalOcean provider. ```bash $ defang compose up --provider=digitalocean ``` ```bash $ export DEFANG_PROVIDER=digitalocean ``` -------------------------------- ### Defang Railpack Deployment Example Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/railpack.md This Compose file example demonstrates how to configure a service for a Defang Railpack deployment. Ensure your Compose file does not explicitly mention a Dockerfile when using Railpack for automatic image building. ```yaml services: app: restart: unless-stopped build: context: . deploy: resources: reservations: cpus: "1.0" memory: 512M ports: - mode: ingress target: 3000 published: 3000 ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/generate-new-code-using-ai.mdx After the project is generated, change into the newly created project directory to review or modify the files. ```shell cd project1 ``` -------------------------------- ### Example Managed Postgres Configuration Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/managed-storage/managed-postgres.mdx An example of configuring application and database services for managed Postgres. Leaving `POSTGRES_PASSWORD` empty instructs Defang to use the value set via `defang config set POSTGRES_PASSWORD`. A connection string is constructed using interpolation. ```yaml app: # [...] environment: POSTGRES_HOST: database POSTGRES_USER: postgres POSTGRES_DB: postgres // highlight-start # Note: by leaving the value empty, Defang will use the # value set using `defang config set POSTGRES_PASSWORD` POSTGRES_PASSWORD: // highlight-end # Note: you can create a connection string by using interpolation, # reference config variables by using ${} CONNECTURL: postgresql://postgres:${POSTGRES_PASSWORD}@database:5432/postgres?sslmode=require database: image: postgres:18 x-defang-postgres: true ports: - mode: host target: 5432 environment: // highlight-start # Note: by leaving the value empty, Defang will use the # value set using `defang config set POSTGRES_PASSWORD` POSTGRES_PASSWORD: // highlight-end ``` -------------------------------- ### Deploy Project to Cloud Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/estimation.md After estimating costs, use this command to deploy your project. It supports multiple cloud providers (aws, azure, gcp, digitalocean) and deployment modes. ```bash defang compose up [--provider aws|azure|gcp|digitalocean] [--mode affordable|balanced|high_availability] ``` -------------------------------- ### Generate Project with AI Source: https://context7.com/defanglabs/defang-docs/llms.txt Generate a project skeleton from a natural language description or a named sample using the AI agent. After generation, navigate to the project directory and run `defang compose up` to build and deploy. ```bash # Generate from a named sample defang generate nodejs-http # Prompts: "What folder would you like to create the project in?" # → Writes: compose.yaml, Dockerfile, app/main.js, .github/workflows/deploy.yaml # Generate from a natural language prompt defang generate # Select language: Nodejs # Choose: "Generate with AI" # Prompt: "A basic service with 2 REST endpoints. The default endpoint returns # { "status": "OK" } and /echo echoes request parameters." # Folder: my-service # → Generates all required project files cd my-service defang compose up ``` -------------------------------- ### Set DigitalOcean Credentials and Deploy Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/migrating-from-heroku.md Set environment variables for DigitalOcean access and then deploy your application using Defang. Ensure your DigitalOcean token and Spaces credentials are correctly configured. ```bash export DIGITALOCEAN_TOKEN=your_digitalocean_token export SPACES_ACCESS_KEY_ID=your_spaces_access_key_id export SPACES_SECRET_ACCESS_KEY=your_spaces_secret_access_key $ defang compose up --provider digitalocean ``` -------------------------------- ### Configure One-off Job with Dependencies Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/one-off-jobs.md Set up a 'migrate' one-off job to run database migrations using './migrate.sh' only after the 'db' service is ready. The 'web' service then depends on the 'migrate' job. ```yaml services: db: image: postgres:latest migrate: build: . command: ["./migrate.sh"] depends_on: - db restart: "no" web: build: . ports: - "80:80" depends_on: - migrate ``` -------------------------------- ### Initialize Heroku Migration (Alternative) Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-09-25-heroku-migration.md An alternative command to directly initiate the Heroku migration workflow, potentially skipping interactive prompts. ```bash defang init migrate-from-heroku ``` -------------------------------- ### Valid Healthcheck for Ingress Ports Source: https://github.com/defanglabs/defang-docs/blob/main/docs/intro/faq/warnings-errors.md This is an example of a valid healthcheck configuration for services with ingress ports, which includes 'localhost'. ```yaml healthcheck: test: ["CMD", "curl", "-f", "http://localhost:1234/health"] ``` -------------------------------- ### Initialize Pulumi TypeScript Project Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/deploy-using-pulumi.mdx Create a new Pulumi project using the TypeScript template. The `--force` flag is used because the directory is not empty. ```bash pulumi new typescript -y --force ``` -------------------------------- ### Authenticate GCP CLI Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/setting_up_your_gcp_account.md Run this command after installing the gcloud CLI to generate application default credentials. These are used during deployment. ```bash gcloud auth application-default login ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/defanglabs/defang-docs/blob/main/docs/intro/getting-started.mdx Changes the current directory to the newly generated project folder. ```bash cd welcome-to-defang ``` -------------------------------- ### Install Defang Pulumi Provider with yarn Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/pulumi.md Use this command to add the Defang Pulumi provider to your project when using yarn. ```bash yarn add @defang-io/pulumi-defang ``` -------------------------------- ### Deploy Project to Azure Source: https://github.com/defanglabs/defang-docs/blob/main/docs/providers/azure.md Deploy your project to Azure using the Defang CLI. Specify the Azure provider explicitly or set it as an environment variable. ```bash defang compose up --provider=azure ``` ```bash export DEFANG_PROVIDER=azure ``` -------------------------------- ### Configure Service Healthchecks (wget) Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/compose.md Define healthcheck configurations for services, required for exposed ports. This example uses `wget`. ```yaml healthcheck: test: ["CMD", "wget", "--spider", "http://localhost:8080/"] interval: 30s timeout: 90s retries: 3 ``` -------------------------------- ### Clone Slackbot Sample Code Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2024-03-28-slackbot-sample.md Clone the Defang repository and navigate to the slackbot sample directory. This sets up the necessary files for deployment. ```bash git clone https://github.com/DefangLabs/defang cd defang/samples/golang/slackbot ``` -------------------------------- ### Create New n8n Project Directory Source: https://github.com/defanglabs/defang-docs/blob/main/blog/2025-10-10-n8n-aws-deployment.md Creates a new directory for your n8n deployment and navigates into it. This is the first step in setting up your n8n project with Defang. ```bash defang new n8n cd n8n ``` -------------------------------- ### Configure Service Healthchecks (curl) Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/compose.md Define healthcheck configurations for services, required for exposed ports. This example uses `curl`. ```yaml healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/"] interval: 30s timeout: 90s retries: 3 ``` -------------------------------- ### Minimal Defang Service with Pulumi Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/pulumi.md This is a minimal example of a Pulumi program that defines a Defang service. It requires the `@defang-io/pulumi-defang` package to be imported. ```typescript import * as defang from "@defang-io/pulumi-defang/lib"; const service = new defang.DefangService("my-service", { image: "strm/helloworld-http:latest", ports: [{ target: 80, mode: "ingress", protocol: "http", }], }); ``` -------------------------------- ### Authenticate with AWS CLI Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/setting_up_your_aws_account.mdx Run this command after installing the AWS CLI to authenticate your local machine. It creates a profile with short-lived credentials for Defang. ```bash aws login ``` -------------------------------- ### List All Defang Stacks in a Project Source: https://github.com/defanglabs/defang-docs/blob/main/docs/concepts/stacks.md View a list of all created stacks for the current project, including their provider, region, and mode. ```bash defang stack list ``` -------------------------------- ### Add Defang Skill using Codex Source: https://github.com/defanglabs/defang-docs/blob/main/docs/tutorials/agent-skills.md For Codex, manually add the Defang marketplace entry to your personal marketplace file. Then, install the plugin. ```json { "name": "defang-skills", "owner": { "name": "DefangLabs" }, "plugins": [ { "name": "defang", "source": { "source": "github", "repo": "DefangLabs/defang", "path": "codex-plugin" }, "category": "Infrastructure" } ] } ``` ```shell /plugin install defang@defang-skills ```