0
votes

I am pushing Docker images to our private registry via Jenkins with the following command:

def dockerImage = docker.build("repo/myapp:${env.BUILD_NUMBER}")

(BUILD_NUMBER increases after every build.)

Because I am new to using Helm, I could not decide how should I give the tag for images in values.yaml.

I would like to deploy my app to multiple environments such as:

  • dev
  • test
  • prod

Let's say I was able to deploy my app via Helm to dev, and the latest BUILD_NUMBER is:

  • 100 for dev
  • 101 for test
  • 102 for prod

What should be the tag value, then?

 image:
  repository: registryt/myrepo/image
  tag: 
3

3 Answers

4
votes

You should put "some" tag into your values.yaml which will act as the default tag. Each Helm Chart has it, you can check the official Helm Charts here.

Now, you have two options on how to act with the different environments.

Option 1: Command line parameters

While installing your Helm Chart, you can specify the tag name dynamically with --set. For example:

$ helm install --set image.tag=12345 <your-chart-name>

Option 2: Separate values.yaml files

You can store separate values.yaml in your repository, like:

values.dev.yaml
values.prod.yaml

Then, update the correct values in your Jenkins pipeline.

1
votes

I just ran into this issue with GitHub Actions. As the other answer already noted, set the image.tag in values.yaml to something as a default. I use latest as the default.

The problem is that the helm upgrade command only upgrades if the image tag is different. So "latest" isn't unique enough for Helm to do the rolling update. I use a SHA in GitHub Actions as my unique version tag. You could tag the image like this:

def dockerImage = docker.build("repo/myapp:${env.NAME}-${env.BUILD_NUMBER}")

Then in your helm command just add a --set:

helm upgrade <helm-app> <helm-chart> --set image.tag=${env.NAME}-${env.BUILD_NUMBER}

This command will override whatever value is in values.yaml. Keep in mind that the --set value must follow the structure of your values.yaml so in this case image is a top level object, with a property named tag:

values.yaml
     image
          name
          tag
          pullPolicy
     port
     replicaCount
0
votes

May be its late, but hope helps someone later with this similar query. I had similar situation and was looking for some options. It was painful as helm3 package doesn't come with --set option, which exists in version 2.

Solution: Implemented with Python jinja packages, along with environment variables, with below steps.

Create values.yaml.j2 file inside your chart directory, with your values file along with templates as per below.

name: {{ APPLICATION | default("SampleApp") }}
labelname: {{ APPLICATION | default("SampleApp") }}
image:
  imageRepo: "SampleApp"
  imageTag: {{ APPLICATION_IMAGE_TAG | default("1.0.27") }}

Dependency packages (in container):

sh 'yum -y install python3'
sh 'yum -y install python3-pip'
sh 'yum -y install python-setuptools'
sh 'python3 -m pip install jinja-cli'

Sample Environment Variables In your Build Pipeline:

APPLICATION= "AppName"
APPLICATION_VERSION= '1.0'
APPLICATION_CHART_VERSION= '1.0'
APPLICATION_IMAGE_TAG= "1.0.${env.BUILD_NUMBER}"

Now in your pipeline, before packaging chart, Apply/Replace the templates with one jinja command as like below.

sh "jinja CHART_DIR/values.yaml.j2 -X APP.* -o CHART_DIR/values.yaml"
helm package CHART_DIR

Done!