LogoLogo
Bonsai (0.13) DocsGitHubDiscord CommunityGarden Enterprise
Acorn (0.12)
Acorn (0.12)
  • Welcome!
  • 🌳Basics
    • How Garden Works
    • Quickstart Guide
    • The Stack Graph (Terminology)
  • 🌻Tutorials
    • Your First Project
      • 1. Initialize a Project
      • 2. Connect to a Cluster
      • 3. Deploy and Test
      • 4. Configure Your Project
  • 💐Using Garden
    • Configuration Overview
    • Projects
    • Modules
    • Services
    • Tests
    • Tasks
    • Workflows
    • Variables and templating
    • Module Templates
    • Using the CLI
  • 🌿Kubernetes Plugins
    • About
    • Remote K8s Plugin Configuration
      • 1. Create a Cluster
        • AWS
        • GCP
        • Azure
      • 2. Configure Container Registry (Optional)
        • AWS
        • GCP
        • Azure
      • 3. Set Up Ingress, TLS and DNS
      • 4. Configure the Provider
    • Local K8s Plugin Configuration
      • 1. Install Local Kubernetes
      • 2. Configure the Provider
    • Module Configuration
      • Container
      • Kubernetes
      • Helm
      • PersistentVolumeClaim
      • ConfigMap
    • Advanced
      • In-Cluster Building
      • Minimal RBAC Configuration for Development Clusters
      • Deploying to Production
  • 🌺Terraform Plugin
    • About
    • Provider Configuration
    • Module Configuration
  • ☘️Pulumi Plugin
    • About
    • Provider Configuration
    • Module Configuration
  • 🌹Other Plugins
    • Container
    • Exec (local scripts)
  • 🌼Guides
    • Installing Garden
    • Adopting Garden
    • Code Synchronization (Dev Mode)
    • Connecting a local service to a K8s cluster (Local Mode)
    • Environments and namespaces
    • Hot Reload
    • Migrating from Docker Compose to Garden
    • Using Garden in CI
  • 🌷Advanced
    • cert-manager Integration
    • Using Remote Sources
    • Custom Commands
  • 🪷Reference
    • Providers
      • conftest-container
      • conftest-kubernetes
      • conftest
      • container
      • exec
      • hadolint
      • jib
      • kubernetes
      • local-kubernetes
      • maven-container
      • octant
      • openfaas
      • pulumi
      • terraform
    • Module Types
      • configmap
      • conftest
      • container
      • exec
      • hadolint
      • helm
      • jib-container
      • kubernetes
      • maven-container
      • openfaas
      • persistentvolumeclaim
      • pulumi
      • templated
      • terraform
    • Template Strings
      • Project configuration context
      • Environment configuration context
      • Provider configuration context
      • Module configuration context
      • Remote Source configuration context
      • Project Output configuration context
      • Custom Command configuration context
      • Workflow configuration context
      • Template Helper Functions
    • Glossary
    • Commands
    • Project Configuration
    • Module Template Configuration
    • Workflow Configuration
  • 🎋Misc
    • FAQ
    • Troubleshooting
    • Telemetry
Powered by GitBook
On this page
  • CLI introduction
  • Common option flags
  • Services
  • Deploying all services in a project
  • Deploying all services in a project to a non-default environment and namespace
  • Deploying a single service
  • Deploying more than one specific service
  • Deploying a service and watching for changes
  • Deploying a service in hot-reload mode
  • Running a single ad-hoc service and attaching
  • Executing a command in a running service container
  • Executing an interactive shell in a running service container
  • Getting the status of your services
  • Getting the status of your services in JSON format
  • Stopping all running services
  • Stopping a single running service
  • Tests
  • Running all tests in a project
  • Running all tests for a specific module, and watching for changes
  • Running a specific test for a module, and watching for changes
  • Running a specific test and attaching
  • Tasks
  • Running a specific task
  • Building
  • Building all modules
  • Building all modules, forcing a rebuild
  • Building a specific module
  • Building a specific module, and watching for changes
  • Workflows
  • Running a workflow
  • Logs
  • Retrieving the latest logs for all services
  • Retrieving the latest logs for a service
  • Stream logs for a service
  • garden dev
  • Running garden dev
  • Running garden dev but skipping tests
  • Running garden dev with hot reloading enabled for all supported services
  • Running garden dev with hot reloading enabled for a specific service
  • The dashboard
  • Hot reloading
  • Project outputs
  • Printing project outputs
  • Getting project outputs in JSON format
  • Creating new configs
  • Creating a new project
  • Creating a module
  • Remote sources
  • Plugin commands
  • Initializing a Kubernetes cluster for in-cluster building
  • Cleaning up the in-cluster builder and registry
  • Planning and applying Terraform stacks
  • Plugin tools
  • Running a plugin tool
  • Getting the path of a plugin tool
  • Next Steps

Was this helpful?

  1. Using Garden

Using the CLI

PreviousModule TemplatesNextAbout

Last updated 1 year ago

Was this helpful?

Here, we'll describe at a high level the common day-to-day usage of the Garden CLI, with specific examples.

CLI introduction

The garden CLI is how you work with Garden in most scenarios, during development and in CI pipelines. It features a fairly large number of commands, so we'll list the most common ones below. You can run garden --help to list them, and use garden <command> --help to learn more about individual commands, arguments, option flags, usage examples etc. You can also find a full reference .

If you've not installed the CLI yet, please check out the .

Most of the examples below assume that you've already defined a Garden project.

The command, as well as the , and commands (when run with the --watch flag) all start a web dashboard that you can open in a browser. See for more on that.

It is currently not advisable to run multiple dev, build, deploy or test commands in parallel, especially with --watch because they may interfere with each other. It is fine, however, to run one of those and then run other commands to the side, such as garden logs. We plan on improving this in the future.

Common option flags

Every Garden command supports a common set of option flags. The full reference can be found , but here are the most important ones:

  • --env sets the environment (and optionally namespace) that the command should act on. Most Garden commands only act on a specific environment, so in most cases you'll specify this, unless you're working on the default environment for the project. See for more about environments and namespaces.

  • --log-level / -l sets the log level. Use e.g. -l=debug to get debug logs for the command.

  • --logger-type=basic disables the fancy log output (with spinners etc.) and just prints a simple line-by-line output. Setting GARDEN_LOGGER_TYPE=basic does the same thing. You should set that environment variable in CI and other automated environments.

  • --output / -o sets the output format. Use this to get structured output from the commands. --output=json outputs JSON, and --output=yaml outputs YAML. The structure of the outputs is documented in for most commands.

All option flags can be specified with a space or a = between the flag and the value.

Services

Deploying all services in a project

This deploys all your services to the default environment and namespace.

garden deploy

Deploying all services in a project to a non-default environment and namespace

This deploys your services to my-namespace in the dev environment.

garden deploy --env my-namespace.dev

Deploying a single service

garden deploy my-service

Deploying more than one specific service

When arguments accept one or more services, modules etc. we comma-separate the names.

garden deploy service-a,service-b

Deploying a service and watching for changes

garden deploy my-service --watch  # or -w for short

Deploying a service in hot-reload mode

garden deploy my-service --hot-reload=*  # or --hot for short

Running a single ad-hoc service and attaching

garden run service my-service --interactive  # or -i for short

Executing a command in a running service container

garden exec my-service <command>

Executing an interactive shell in a running service container

Note: This assumes that sh is available in the container.

garden exec my-service -i sh

Getting the status of your services

garden get status

Getting the status of your services in JSON format

This is suitable for parsing with e.g. the jq utility.

garden get status --output=json  # or `-o json` for short

Stopping all running services

This removes all running services in my-namespace in the dev environment.

garden delete env --env=my-namespace.dev

Stopping a single running service

garden delete service my-service

Tests

Running all tests in a project

garden test

Running all tests for a specific module, and watching for changes

garden test my-module --watch

Running a specific test for a module, and watching for changes

This runs the integ test, defined in my-module, and watches for changes (including changes in modules and services that the test depends on).

garden test my-module --name integ -w

Running a specific test and attaching

This is handy for running a single test and streaming the log outputs (garden test, in comparison, is more meant to run multiple ones or watch for changes, and is less suitable for getting log output).

garden run test my-module my-test -i

Tasks

Running a specific task

garden run task my-task

Building

Building all modules

garden build

Building all modules, forcing a rebuild

garden build --force  # or -f for short

Building a specific module

garden build my-module

Building a specific module, and watching for changes

garden build my-module -w

This will start a dashboard as well.

Workflows

Running a workflow

Runs my-workflow in my-namespace in the dev environment.

garden run workflow my-workflow --env=my-namespace.dev

Logs

Retrieving the latest logs for all services

garden logs

Retrieving the latest logs for a service

garden logs my-service

Stream logs for a service

garden logs my-service --follow  # or -f for short

garden dev

The garden dev command builds, deploys and tests all parts of your project, and also runs any tasks that are listed as dependencies for your services and tests. It then waits for any code changes, and automatically re-builds, re-deploys and re-runs any parts affected by your code changes.

This is handy for small projects, and when your code changes don't tend to trigger a lot of heavy operations, but may be too "busy" to run for large projects or when you're making big changes to your code.

Running garden dev

garden dev

Running garden dev but skipping tests

garden dev --skip-tests

Running garden dev with hot reloading enabled for all supported services

garden dev --hot-reload=*

Running garden dev with hot reloading enabled for a specific service

garden dev --hot-reload=my-service

The dashboard

The CLI will print a URL which you can copy or click (or Cmd/Ctrl-click, depending on your terminal). The dashboard stays open while the command is running.

The dashboard gives you:

  • An overview of all the parts of your project, including links to any configured ingresses on your services.

  • A visualization of your Stack Graph, where you can see the status of each node, and click them to get the most recent status or logs.

  • A log viewer, which you can use to fetch the latest logs for your services.

Hot reloading

Project outputs

Printing project outputs

garden get outputs

Getting project outputs in JSON format

This you can use to parse in scripts, e.g. using jq.

garden get outputs --output=json  # or `-o json` for short

You can also output in YAML with --output=yaml.

Creating new configs

Creating a new project

This bootstraps a boilerplate garden.yml with a project definition in the current directory, and a .gardenignore file.

garden create project

Creating a module

This bootstraps a boilerplate garden.yml with a module definition in the current directory. You'll get an interactive menu to select a module type. You may get suggestions for appropriate module types, depending on which files are found in the directory (such as a container module when a Dockerfile is found).

garden create module

Remote sources

Plugin commands

Individual plugins (currently referred to as providers in your project configuration) may include specific commands that help with their usage and operation. The available commands will depend on which providers are configured in your project.

You can run garden plugins without arguments to list the available commands.

Initializing a Kubernetes cluster for in-cluster building

Here we initialize the cluster configured for the dev environment:

garden plugins kubernetes cluster-init --env=dev

Cleaning up the in-cluster builder and registry

When you use in-cluster building, the image caches build up over time and need to be cleaned up periodically. Use this command for that:

garden plugins kubernetes cleanup-cluster-registry --env=dev

Planning and applying Terraform stacks

Plugin tools

Garden plugins generally define their external tool dependencies, such that Garden can automatically fetch them ahead of use. The garden tools command exposes these tools, so that you can use them without having to install them separately. You can also use these to ensure that you're using the exact same versions as the Garden plugins.

Note that this command currently only works when run within a Garden project root.

If you use this frequently, we recommend defining the following helper function for quick access:

# Note: This is made to work in bash and zsh, other shells may need a different syntax
function gt() {
  garden tools $1 -- "${@:2}"
}

You can then type e.g. gt docker build . to run docker build . using the Garden-provided version of the docker CLI.

Run garden tools to get a full list of available tools, and garden tools --help for more usage information.

Running a plugin tool

Note that the -- is necessary to distinguish between Garden options, and kubectl arguments. See above for a shorthand function you can put in your shell profile.

garden tools kubectl -- <args>

Getting the path of a plugin tool

This prints the absolute path to the kubectl binary defined by the kubernetes provider, downloading it first if necessary.

garden tools kubectl --get-path

Next Steps

See the for more information on how to configure and use hot reloading for rapid iteration on services. Enabling --hot-reload implicitly sets --watch=true.

See the for more information on how to configure and use hot reloading for rapid iteration on services.

The command, as well as the , and commands when run with the --watch flag all start a web dashboard that you can open in a browser. See for more on that.

For rapid iteration on a running service, you can use an advanced feature called hot reloading. See the for details on how to configure and use that feature.

are a handy way to extract generated values from your project.

Remote sources are a mechanism to connect multiple git repositories in a single Garden project. See the for more information, including how to use the CLI to manage these sources.

When using a remote Kubernetes cluster and in-cluster building, the cluster needs to be set up with some shared services when you first start using it, when you update the provider configuration, or sometimes when you update to a new Garden version. See the for more information.

The terraform provider includes several commands that facilitate interaction with the Terraform stacks in your project. See the for more information.

Take a look at our for in-depth guides on specific use cases and setups, or keep exploring other sections under to learn more about Garden concepts and configuration.

💐
Hot reload guide
Hot reload guide
Hot reload guide
remote sources guide
remote kubernetes guide
Terraform guide
Guides section
Using Garden
garden dev
build
deploy
test
the dashboard section
here
installation guide
the reference
garden dev
build
deploy
test
the dashboard section
The Stack Graph
Project outputs
here
here