Exec (local scripts)
The exec
plugin and corresponding exec
actions allow you to run commands locally on the host (e.g. your laptop or your CI runner).
This plugin is built-in which means you don't need to specify it in your project configuration. You can simply add exec
actions 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 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.
Plugin Configuration
Usually you don't need to configure the exec
plugin 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:
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.
If you need your local service to receive traffic from the remote parts of your system you can use Garden's local mode functionality.
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