little-army-47606
05/15/2024, 6:03 PMgit rev-parse HEAD
or equivalent and passing that on to the image being deployed.
I'm not seeing a crystal clear path on doing that in just the garden.yml
files, and wondering if anybody has a method of achieving that you wouldn't mind sharing.big-spring-14945
05/16/2024, 11:40 AM${git.commitHash}
https://docs.garden.io/reference/template-strings/environments#usd-git.commithash
Is this what you were looking for?little-army-47606
05/16/2024, 2:11 PMlittle-army-47606
05/16/2024, 8:05 PMproject.garden.yml
file that builds out the required cluster specifications, and then 3 linked-repos that each have their own garden.yml
file for Build and Deploy , specific to the requirements of each deployment's stack. We run the deploy action from the overall product directory, with each of the linked repos nested in ./services/project-name/
, each with their own individual commit hashes. It's those 3 commit hashes that I want to have environment variables for, each on their individual pods. So, for example, api
has its own commit hash, frontend
has its own commit hash, and dashboard
has its own...brief-restaurant-63679
05/21/2024, 12:57 PMgit.commitHash
field is actually intentionally set to show the commit hash of the "parent" repo and changing that would be a breaking change.
That being said, there is a workaround but it's a little hacky.
But you can create an exec
action (i.e. a simple action that just runs on the host) that gets the commit hash and then reference the output of that action. For explanation purposes, here's how you can create an exec action that gets the hash and another one that references it:
kind: Run
type: exec
name: get-hash
spec:
command: [git, rev-parse, HEAD]
---
kind: Run
type: exec
name: print-hash
dependencies: [run.get-hash]
spec:
command: [echo, "hash is: ${actions.run.get-hash.outputs.log}"]
Now if you run garden run print-hash
you should see the correct hash.
For your specific use case it would looke something like:
# In the API repo
kind: Run
type: exec
name: get-api-hash
spec:
command: [git, rev-parse, HEAD]
---
kind: Deploy
type: container
name: api
dependencies: [run.get-api-hash]
spec:
# ...
env:
COMMIT_HASH: ${actions.run.get-api-hash.outputs.log}
Note that each run action needs to have a unique name (i.e. get-api-hash
, get-dashboard-hash
etc) to prevent naming collision.
Note also that this only works with remote sources, not remote actions (see [distinction here](https://docs.garden.io/advanced/using-remote-sources))brief-restaurant-63679
05/21/2024, 12:57 PMexec
actionslittle-army-47606
05/21/2024, 2:39 PMlittle-army-47606
05/21/2024, 9:15 PMkey "env" is not allowed at path spec[env]. Available keys: files, kustomize, manifests, patchResources, namespace, portForwards, timeout, waitForJobs, defaultTarget, sync, localMode)
little-army-47606
05/21/2024, 9:22 PMDeploy
types are all kubernetes
, though, not container
little-army-47606
05/22/2024, 8:33 PMbrief-restaurant-63679
05/28/2024, 11:58 AMcontainer
action.
For the kubernetes
action there's no env field and instead the environment varialbles are typically set in the manifest themselves but can be then overwritten via the patchResources
field in the Garden spec.
Here's an example of that: https://github.com/garden-io/garden/tree/main/examples/k8s-deploy-patch-resourcesbrief-restaurant-63679
05/28/2024, 11:58 AMbrief-restaurant-63679
05/28/2024, 11:59 AM