Using Garden to run Unit test on CI
# 🌱|help-and-getting-started
b
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
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
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
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
Oh I see those env vars are provided by Gitlab CI, let's see if Cloudbuild supports those, neat
c
Thanks @orange-ability-1812 for your detailed answer (and the tip about GCR). 🙂