https://garden.io logo
#🌱|help-and-getting-started
Using Garden to run Unit test on CI
# 🌱|help-and-getting-started
b

bright-policeman-43626

03/04/2024, 6:14 AM
Hey! I'm working on setting up Garden to run unit test on a CI environment for this I need to be able to do a couple of things: - Create namespaces dynamically (perhaps using the branch name of the PR or PR number). - Connect to Kubernetes in GCP. - Don't push images built in this workflow to the registry as this is going to be 100% ephemeral. Do y'all have any examples that are similar to this use case? 😄
o

orange-ability-1812

03/04/2024, 3:18 PM
Oh yeah we do this all the time. The only thing is that you should be pushing images so that you get caching, but they won't be named anything useful. We have a GCP Artifact Registry (GAR) for each project.
b

bright-policeman-43626

03/04/2024, 4:04 PM
I was able to do this specifying a folder in GCR so all my meaningless images are in a single folder (easy to clean up tbh)
do you mind sharing how do you do the namespaces dynamically @orange-ability-1812 ?
o

orange-ability-1812

03/04/2024, 5:39 PM
GCR is going to get killed by GCP at some point. I would migrate to GAR if you are starting a new project.
For Gitlab CI/CD
Copy code
environments:
  # environments for running integration tests in
  - name: ci
    defaultNamespace: proj-ci-branch-${replace(local.env.CI_COMMIT_REF_NAME, "_", "-")}

  # need a different namespace for tagged releases
  - name: ci-release
    defaultNamespace: proj-ci-release-${replace(local.env.CI_COMMIT_TAG, ".", "-")}

[...]
providers:
  - name: kubernetes

    namespace:
      name: ${environment.namespace}
[...]
You could switch to using PR number if you want. This uses either the branch or tag name, and then in Gitlab CI/CD I control what runs on a PR vs branch vs default pipeline
b

bright-policeman-43626

03/05/2024, 1:28 AM
Oh I see those env vars are provided by Gitlab CI, let's see if Cloudbuild supports those, neat
c

chilly-gigabyte-83853

03/05/2024, 1:07 PM
Thanks @orange-ability-1812 for your detailed answer (and the tip about GCR). 🙂