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
  • Plugin Configuration
  • Module Configuration
  • Exec tasks
  • Local services
  • Next Steps

Was this helpful?

  1. Other Plugins

Exec (local scripts)

The exec plugin and corresponding exec module type allow you to run commands locally on the host (e.g. your laptop or on your CI runner).

It's built-in which means you don't need to specify it in the project level configuration and you can simply add exec modules right away.

It's great for running auth scripts as well as executing various scaffolding scripts that need to run "locally".

It can also be used to start services locally (e.g. by executing commands like yarn dev).

This can be very useful for hybrid environments where you have, say, your backend running in a remote production-like environment but your frontend running locally.

Plugin Configuration

Usually you don't need to configure the exec plugin because it's built-in and you can use exec modules directly.

However, it can be used to run init scripts ahead of other Garden execution. This is e.g. useful if you need to authenticate against a remote environment before Garden initializes other plugins.

Here's an example where we run a script to authenticate against a Kubernetes cluster before initializing the Kubernetes plugin:

# In your project level Garden config file
kind: Project
name: my-project

providers:
  - name: exec
    initScript: [./scripts/auth.sh]
  - name: kubernetes
    dependencies: [exec] # <--- This ensures the init script runs before the K8s plugin is initialized.
    # ...

Module Configuration

Exec tasks

Here's an example configuration for an exec module that's used for running various scripts:

kind: Module
name: scripts
type: exec
local: true # <--- Run the script relative to the source dir (don't worry about this)
include: [] # <--- No source files are needed
tasks: # <--- The scripts are defined as exec tasks
  - name: authenticate
    command: [./scripts/auth.sh]
  - name: prepare-data
    command: [./scripts/prepare-data-locally.sh]

Other actions can depend on these tasks:

kind: Module
name: api
type: kubernetes

dependencies: [authenticate]
tasks:
  - name: db-init
    command: [yarn, run, db-init]
    dependencies: [prepare-data]

It's also possible to reference the output from exec module tasks:

kind: Module
name: api
type: container
services:
  env:
    AUTH_KEY: ${runtime.tasks.authenticate.outputs.log}

Local services

The exec module can also be used to start long running services like so:

kind: Module
name: web-local
type: exec 
local: true
include: []
services:
  - name: web-local
    devMode:
      command: ["yarn", "run", "dev"] # <--- This is the command Garden runs to start the process in dev mode
      statusCommand: [./check-local-status.sh] # <--- Optionally set a status command that checks whether the local service is ready
    deployCommand: [] # <--- A no op since we only want to deploy it when we're in dev mode
    env: ${modules.frontend.env} # <--- Reference the env variable defined above

Next Steps

PreviousContainerNextInstalling Garden

Last updated 1 year ago

Was this helpful?

See also this .

For some advanced exec use cases, check out of our community office hours on the topic.

🌹
example project
this recording