0

My team developing a kubernetes app in Gitlab using Helm. As part of our review process we deploy an instance of our app into a namespace on MR. Docker images are built and tagged either as latest (for current master stable) or with the branch of the changes.

I would like for the review app to automatically use the latest of the branch if it exists else use latest, hopefully without needing intervention to modify the image tags by hand.

What is the cleanest way to do this? I've looked a number of places

VV1
  • 1
  • 1

1 Answers1

1

You can pass docker image tag value when deploying helm using --set. So for different branches - master and non-master - in a pipeline you can have different stages where in one you'll pass --set dockerImageTag=latest and for MR branches it'll be --set dockerImageTag=<branch-name>.

mr-build-deploy:
  only:
    - merge_requests
  script:
    - docker build ...
    - docker tag <docker-tag-name>
    - helm install --set dockerImageTag=<docker-tag-name> ...
 ...

master-build-deploy:
  only:
    - master
  script:
    - docker build ...
    - docker tag latest
    - helm install --set dockerImageTag=latest ...
 ...

Or in values.yaml for the lem chart you can set default value of dockerImageTag to latest so for master step you won't need to specify it.

Speaking of best practices it's not recommended to use latest tag, rather use version number (for example in a form of SemVer) it so you're sure which changes in docker image broke the app if it happens.

Anna Slastnikova
  • 1,260
  • 9
  • 9
  • I appreciate the advice but I'm trying not to have to manually set in the ci/cd pipe using the set as it's not automatic. I would like it to use an image who's tag matches the branch name (as any changes made in the branch are made into their own separate containers and tagged as such) and if no such tag exists, default to the 'latest' or specific default version. I would like to not have to set anything manually (ie including a 'set') as this would be different as different branches might modify different micro services. – VV1 Sep 13 '20 at 18:23