How can I run a script using garden.yml?
# 🤖|ask-kapa
l
@microscopic-river-74022 How can I run a script using garden.yml?
m
Please stand by @little-army-47606 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
---------------------- You can run a script in Garden by defining it in a workflow or as a run action in your
garden.yml
configuration file. For workflows, you can define a script step like this:
Copy code
yaml
kind: Workflow
name: my-workflow
steps:
 - script: |
 echo "Hello there!"
Scripts in workflows can also be templated:
Copy code
yaml
kind: Workflow
name: my-workflow
steps:
 - script: |
 echo "Hello ${project.name}!"
You can run a workflow by running
garden workflow <name>
, or have it trigger automatically via Garden Cloud. For more details, refer to the Workflows section () in the Garden documentation. For run actions, the configuration looks like this:
Copy code
yaml
# garden.yml
kind: Run
name: db-migrate
type: container
build: backend
spec:
 command: ["rake", "db:migrate"]
You can run a Run manually with the
garden run <run-name>
command. This will run the Run regardless of whether or not the result is cached. For more details, refer to the Runs section () in the Garden documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
l
how can I run an external shell script by its filename?
@microscopic-river-74022 how can I run an external shell script by its filename?
m
Let me check the knowledge base for you. One moment! :books:
---------------------- You can run an external shell script by its filename using the
exec
command in Garden. This can be done either in a running
Deploy
container or as a
Run
action. To execute a shell script in a running
Deploy
container, you can use the
garden exec
command followed by the name of your deployment and the shell script command. This assumes that
sh
is available in the container. Here's an example:
Copy code
bash
garden exec my-deploy -- sh /path/to/your/script.sh
Source () To run a shell script as a
Run
action, you can define it in your
garden.yml
configuration file and then use the
garden run
command to execute it. Here's an example:
Copy code
yaml
kind: Run
name: my-run-action
type: container
build: backend
spec:
 command: ["sh", "/path/to/your/script.sh"]
You can then run this action with:
Copy code
bash
garden run my-run-action
Source () Please replace
/path/to/your/script.sh
with the actual path to your shell script. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
l
@microscopic-river-74022 how can I get the latest git hash from my project and set it as an environment variable?
m
Let me check the knowledge base for you. One moment! :books:
---------------------- In Garden, you can use the
${git.commitHash}
template string to get the current Git commit hash. This value can be set as an environment variable in your
garden.yml
configuration file. Here's an example:
Copy code
yaml
kind: Module
type: container
name: my-module
services:
  - name: my-service
    env:
      MY_VARIABLE: ${git.commitHash}
In this example,
MY_VARIABLE
is an environment variable that will be set to the current Git commit hash when the service is run. Please replace
my-module
and
my-service
with the actual names of your module and service. Note that the commit hash is resolved at the start of the Garden command's execution and is not updated if the current commit changes during the command's execution. For more information, refer to the Garden documentation on template strings (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
l
@microscopic-river-74022 , are modules deprecated?
m
Let me check the knowledge base for you. One moment! :books:
---------------------- Yes, modules in Garden are deprecated and will be removed in version
0.14
. It's recommended to use action-based configuration instead. For more details on migrating from modules to actions, you can refer to the 0.12 to Bonsai migration guide (). Please note that while modules still work with Garden Bonsai, they are not documented. For module related documentation, you can refer to the Garden 0.12 documentation (). Source 1 () Source 2 () Source 3 () Source 4 () ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
4 Views