Local Scripts

You can run scripts locally on the host (e.g. your laptop or your CI runner) with the exec action.

A common use case is running auth scripts as well as executing various scaffolding scripts that need to run "locally".

It can also be used to start applications locally (e.g. by executing commands like npm run 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.

Provider Configuration

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

However, it can be used to run init scripts ahead of other Garden execution. This is 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
apiVersion: garden.io/v1
kind: Project
name: my-project

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

The log output of the initScript can be accessed via "${providers.exec.outputs.initScript.log}" template string.

Actions

Build

A Build action which executes a build command "locally" on the host.

This is commonly used together with exec Deploy actions when a local build step needs to be executed first.

Note that by default, Garden will "stage" the build to the ./garden directory and execute the build there. This is to ensure that the command doesn't mess with your local project files. You can disable that by setting buildAtSource: true.

For example:

Another common use case is to prepare a set of files, say, manifests ahead of a deployment. In this case we choose to execute the script in the ./garden directory so that it doesn't affect our version controlled source code.

That's why we also need to set the build field on the Deploy action.

Deploy

A Deploy action which executes a deploy command "locally" on the host.

This is commonly used for hybrid environments where you e.g. deploy your backend services to a remote Kubernetes cluster but run your web service locally.

If you're starting a long running local process, you need to set persistent: true. Note that you can also specify a statusCommand that tells Garden when the command should be considered ready and a cleanupCommand that's executed when running the Garden cleanup command.

For example:

You'll find a complete example of this in our local-service example project.

Run and Test

Similar to the Build action, the Run and Test actions can also be used to run one-off local commands.

Following are some example exec Run actions for executing various scripts:

Other actions can depend on these Runs:

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

Next Steps

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

Last updated

Was this helpful?