1

I am doing CI/CD using openshift buildconfig. I am able to fetch the source code from git and successfully build the docker image and push to internal registry. I want to tag the image built with with build numbers based on Openshift Build config output labels are annotations. How to do that in the YAML, I am using docker build strategy.

output:
    to:
      kind: DockerImage
      name: 'internal.registry.com/app_name/sample_app:<BUILD_NUMBER/NAME>'

Also once this is done, i want to update the image in deployment to get new version of app. Have anyone done such setup, Can anyone help me on this.

2 Answers2

1

The yaml file is resolved when the buildConfig is created, it can't have references to environment variables or build number information. If you are doing this from a CI/CD pipeline, you could create a different buildConfig in the same CI/CD pipeline, run it, and delete it. But you may have permissions issue to create the buildConfig every time.

Another option I would prefer is to use ImageStreams. With ImageStream a single object keeps track of all versions of the image via sha codes, therefore there is no need to update the yaml every time.

ddorsogna
  • 116
  • 5
0

YOU CAN HAVE DYNAMIC TAG -- But it's NOT as PER YOUR naming conventions:

As per Openshift 4.11, i can see that it's possible to get dynamic tag with DockerImage output by not specifying a tag explicitly. You need to read the new tag from the yaml of the Build (which is an execution of a BuildConfig) under status.output.to.imageDigest

example:

kind: BuildConfig
spec:
  output:
    to:
      kind: DockerImage
      name: registry.company.lan/myproject/myapp

Summarizing: You can get the full name of an image which generated with a dynamic tag using this jsonpaths:

kubectl get build mybuild-N -o jsonpath='{.spec.output.to.name}{"@"}{.status.output.t
o.imageDigest}'
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254