Image change triggers allow your build to be automatically invoked when a new version of an upstream image is available. For example, if a build is based on top of a RHEL image, then you can trigger that build to run any time the RHEL image changes. As a result, the application image is always running on the latest RHEL base image.
Note
|
Imagestreams that point to container images in v1 container registries only trigger a build once when the imagestreamtag becomes available and not on subsequent image updates. This is due to the lack of uniquely identifiable images in v1 container registries. |
Configuring an image change trigger requires the following actions:
-
Define an
ImageStream
that points to the upstream image you want to trigger on:kind: "ImageStream" apiVersion: "v1" metadata: name: "ruby-20-centos7"
This defines the imagestream that is tied to a container image repository located at <system-registry>/<namespace>/ruby-20-centos7. The <system-registry> is defined as a service with the name
docker-registry
running in {product-title}. -
If an imagestream is the base image for the build, set the from field in the build strategy to point to the imagestream:
strategy: sourceStrategy: from: kind: "ImageStreamTag" name: "ruby-20-centos7:latest"
In this case, the
sourceStrategy
definition is consuming thelatest
tag of the imagestream namedruby-20-centos7
located within this namespace. -
Define a build with one or more triggers that point to imagestreams:
type: "imageChange" (1) imageChange: {} type: "imageChange" (2) imageChange: from: kind: "ImageStreamTag" name: "custom-image:latest"
-
An image change trigger that monitors the
ImageStream
andTag
as defined by the build strategy’sfrom
field. TheimageChange
object here must be empty. -
An image change trigger that monitors an arbitrary imagestream. The
imageChange
part in this case must include afrom
field that references theImageStreamTag
to monitor.
-
When using an image change trigger for the strategy imagestream, the generated build is supplied with an immutable Docker tag that points to the latest image corresponding to that tag. This new image reference will be used by the strategy when it executes for the build.
For other image change triggers that do not reference the strategy imagestream, a new build will be started, but the build strategy will not be updated with a unique image reference.
Since this example has an image change trigger for the strategy, the resulting build will be:
strategy:
sourceStrategy:
from:
kind: "DockerImage"
name: "172.30.17.3:5001/mynamespace/ruby-20-centos7:<immutableid>"
This ensures that the triggered build uses the new image that was just pushed to the repository, and the build can be re-run any time with the same inputs.
You can pause an image change trigger to allow multiple changes on the referenced
imagestream before a build is started. You can also set the paused
attribute
to true when initially adding an ImageChangeTrigger
to a BuildConfig
to prevent
a build from being immediately triggered.
type: "ImageChange"
imageChange:
from:
kind: "ImageStreamTag"
name: "custom-image:latest"
paused: true
If a build is triggered due to a webhook trigger or manual request,
the build that is created uses the <immutableid>
resolved from the
ImageStream
referenced by the Strategy
. This ensures that builds
are performed using consistent image tags for ease of reproduction.