Heroku CLI

repository·main·Indexed 21 days ago

https://github.com/heroku/cli

A Node.js-based command-line interface built with oclif for managing the Heroku platform lifecycle. It enables application deployment, scaling, monitoring, database management (Postgres and Redis), CI/CD pipelines, add-on provisioning, and team collaboration. The CLI features an extensible plugin architecture and includes comprehensive command groups for authentication, resource management, and observability.

Tokens
106.8K
Snippets
669
Records
693
Agent score
72%

What's inside heroku-cli

  1. Overview of Autocomplete Scripts

    main
    The autocomplete-scripts directory contains the scripts responsible for directing shell environments to the correct autocomplete caches used by the Heroku CLI. These scripts ensure that shell completion (e.g., tab-completion for commands and flags) functions correctly by pointing to the appropriate cache locations.
  2. Overview of the Heroku CLI

    main

    The Heroku CLI is a command-line interface built with Node.js and oclif for managing Heroku applications and services. It features an extensible architecture via a plugin ecosystem and allows users to perform tasks such as:

    • App management: Deploy, scale, and monitor applications.
    • Database management: Manage Heroku Postgres (backup, restore) and Redis instances.
    • CI/CD: Run automated tests and manage review apps via pipelines.
    • Add-ons: Provision and manage tools from the marketplace.
    • Networking: Configure custom domains, SSL/TLS certificates, and Private Spaces.
    • Monitoring: Stream logs and forward them to external services.
    • Team Management: Manage organization access and permissions.
  3. Configure automatic query execution plan logging with `auto-explain`

    main

    The auto-explain module allows you to automatically log execution plans of queries without manually running EXPLAIN.

    Note: The module is loaded at session-time. Existing connections will not be logged; you must restart your Heroku app or restart existing connections for logging to take effect.

    Subcommands:

    • pg:settings:auto-explain [DATABASE] [VALUE]: Enables or disables logging (boolean).
    • pg:settings:auto-explain:log-analyze [DATABASE] [VALUE]: Enables EXPLAIN ANALYZE behavior, showing actual run times. Warning: This can significantly impact database performance as it runs on ALL queries.
    • pg:settings:auto-explain:log-buffers [DATABASE] [VALUE]: Includes buffer usage statistics. This requires log-analyze to be enabled.
    • pg:settings:auto-explain:log-format [DATABASE] [VALUE]: Sets the output format. Options: text (default), json, yaml, xml.
    • pg:settings:auto-explain:log-min-duration [DATABASE] [VALUE]: Sets the minimum execution time in milliseconds for a plan to be logged. Use 0 to log all queries or -1 to disable logging.
  4. Install autocomplete for a specific shell

    main

    Use the heroku autocomplete command to display installation instructions for shell completion. You can specify the shell type as an argument to get instructions tailored to that environment.

    Supported shell arguments include bash and zsh.

    # Get general installation instructions
    $ heroku autocomplete
    
    # Get instructions specifically for bash
    $ heroku autocomplete bash
    
    # Get instructions specifically for zsh
    $ heroku autocomplete zsh
  5. Use the Heroku CLI Interactive Prompt

    main

    The interactive prompt allows you to run Heroku CLI commands by guiding you through required and optional inputs. This is useful when you are unsure of the specific flags or arguments a command requires, as it provides descriptions for each input and validates them before execution.

    To use it, append the --prompt flag to any Heroku CLI command.

    $ heroku COMMAND --prompt
  6. Start the Heroku platform MCP server

    main

    You can start the Heroku platform Model Context Protocol (MCP) server in stdio mode using the heroku mcp:start command. This allows AI agents or tools that support the MCP standard to interact with the Heroku platform via the CLI.

    $ heroku mcp:start
  7. Configure IPSec VPN connections for Private Spaces

    main

    Private Spaces can connect to other private networks via an IPSec VPN connection. This allows dynos to communicate with hosts on your private networks and vice versa. Traffic is encrypted over the public Internet.

    Create a VPN connection

    Use heroku spaces:vpn:connect to establish a connection. You must provide the public IP of your customer gateway and a comma-separated list of routable CIDRs.

    Retrieve VPN configuration

    To establish the connection, you must configure your VPN Gateway using the information from heroku spaces:vpn:config.

    • VPN Gateway values: Use the IP addresses of the Private Space Tunnels provided.
    • Customer Gateway value: Use the Public IP of your VPN Gateway.
    • Authentication: Use the provided IKE Version and Pre-shared Keys.

    Manage existing connections

    • List connections: heroku spaces:vpn:connections -s <space-name>
    • Get info: heroku spaces:vpn:info <connection-name> -s <space-name>
    • Update CIDRs: heroku spaces:vpn:update <connection-name> -c <comma-separated-cidrs> -s <space-name>
    • Destroy connection: heroku spaces:vpn:destroy <connection-name> -s <space-name>
    # Create a VPN connection
    heroku spaces:vpn:connect vpn-connection-name --ip 35.161.69.30 --cidrs 172.16.0.0/16,10.0.0.0/24 --space my-space
    
    # Get configuration details for your gateway setup
    heroku spaces:vpn:config vpn-connection-name --space my-space
  8. Create a new Heroku app

    main

    You can create a new Heroku application using the CLI or by providing a configuration file.

    Using the CLI: Run heroku apps:create [APP] to create an app with a specific name. If you omit [APP], Heroku will generate a random name for you.

    Using a manifest: Alternatively, you can use a heroku.yml manifest file to define your application configuration.

    Common creation options:

    • Specify a buildpack: Define which buildpack to use during creation.
    • Specify a name: Use the [APP] argument to set a custom name.
    • Create a staging app: Create an application intended for staging environments.
    • Create an app in the EU region: Specify the region during the creation process.
    $ heroku apps:create my-custom-app-name
  9. Get help for Heroku CLI commands

    main

    Use the heroku help command to display usage information, available arguments, and flags for the CLI or specific subcommands. To see help for a specific command and all of its nested subcommands, use the -n or --nested-commands flag.

    # Display general help
    $ heroku help
    
    # Display help for a specific command
    $ heroku help [COMMAND]
    
    # Display help for a command including all nested subcommands
    $ heroku help [COMMAND] -n
  10. Open a psql shell to a Heroku database

    main

    Use the heroku psql command to open an interactive PostgreSQL shell connected to your Heroku application's database. By default, it connects to the primary database of the specified app. You can also pass specific SQL commands or files to execute directly without entering the interactive shell.

    # Open an interactive shell for the app 'my-app'
    $ heroku psql -a my-app
    
    # Run a specific SQL command and exit
    $ heroku psql -a my-app -c "SELECT * FROM users;"
    
    # Run commands from a SQL file
    $ heroku psql -a my-app -f schema.sql
  11. Develop the Heroku CLI locally

    main

    To develop and test changes to the Heroku CLI locally, follow these steps after cloning the repository:

    1. Install dependencies: npm install
    2. Build the CLI: npm run build. You must re-run this command whenever you make changes that you want to test locally.
    3. Execute commands: Use the ./bin/run script to execute commands using your local build instead of the installed global CLI.

    Example: To run the heroku apps command using your local code, run:

    ./bin/run apps
    npm install
    npm run build
    ./bin/run apps
  12. Update the Heroku CLI

    main

    Use the heroku update command to upgrade your Heroku CLI installation. You can update to a specific release channel (like stable), install a specific version, or use an interactive mode to select which version to install.

    # Update to the stable channel
    $ heroku update stable
    
    # Update to a specific version
    $ heroku update --version 1.0.0
    
    # Interactively select version to install
    $ heroku update --interactive
    
    # See available versions
    $ heroku update --available