can i configure garden to run a script prior to ru...
# 🤖|ask-kapa
r
@microscopic-river-74022 can i configure garden to run a script prior to running
garden deploy
?
m
Please stand by @rich-helicopter-7653 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
---------------------- Yes, you can configure Garden to run a script prior to running
garden deploy
by using the
exec
plugin and defining an
initScript
in your project configuration. This script will be run in the project root when initializing providers. Here's an example:
Copy code
yaml
# 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.
    # ...
In this example, a script
auth.sh
is run to authenticate against a Kubernetes cluster before initializing the Kubernetes plugin. The
exec
plugin is built-in, so you don't need to specify it in your project configuration. You can simply add
exec
actions right away. You can also define custom commands as part of your Garden project. These custom commands can be run before the Garden command starts. Here's an example:
Copy code
yaml
kind: Command
name: api-dev
description:
  short: Start garden with preconfigured options for API development
exec:
  command:
    - sh
    - -c
    - git submodule update --recursive --remote  # Because we keep forgetting to update these, amirite?
gardenCommand:
  - deploy
  - --sync
  - api,worker
  - --log-level
  - debug
  - $concat: ${args.$all}  # Allow any arguments/options on top of the fixed ones above
In this example, before the Garden command starts, the submodules in the repo are updated, and then
garden deploy
is started with some parameters.
Sources: - Exec Plugin () - Custom Commands () - Providers () ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
4 Views