2

I created a project on OpenShift 4.2 with an ImageStream that is pulling an Image from Quay.io:

oc new-project xxx-imagestream
oc import-image is:1.0 --from quay.io/xxx/myimage:latest --confirm --reference-policy local 

Now I create a new project to host an app based on that ImageStream

oc new-project xxx-app
oc new-app --name myapp -i xxx-imagestream/is:1.0

The app is built and I can use it by exposing it. (But no Build or BuildConfig is created. Why???)

Now I update the image on Quay.io with a new version, and import the new version into the xxx-imagestream project:

oc import-image is:2.0 --from quay.io/xxx/myimage:latest --confirm --reference-policy local

The question is: how do I update my app (myapp)? In other words, how can I launch a new build of "myapp" based on the updated ImageStream?

blong
  • 2,815
  • 8
  • 44
  • 110
Guildenstern70
  • 1,715
  • 18
  • 18

3 Answers3

2

(But no Build or BuildConfig is created. Why???)

A BuildConfig is only created when you use the "Source to Image" (S2I) functionality and is only needed when you want to create a container image from source. In your case, the image already exists, so there is no need to build anything. The only thing that oc new-app will do is deploy your existing image, there is no build necessary.

The question is: how do I update my app (myapp)? In other words, how can I launch a new build of "myapp" based on the updated ImageStream?

You are looking for "Deployment triggers", specifically the "ImageChange deployment trigger". The ImageChange trigger results in a new ReplicationController whenever the content of an imagestreamtag changes (when a new version of the image is pushed).

On a side-note, you can also periodically automate the importing of new image versions in your ImageStreams (see documentation).

Simon
  • 4,251
  • 2
  • 24
  • 34
  • Thank you so much, Simon. I understood triggers are something to "automate" the deployment. What if I want to deploy and updated image now? "oc rollout"? – Guildenstern70 Sep 18 '20 at 07:31
  • 1
    @Guildenstern70 Yes, you can use `oc rollout` to re-run the deployment. Note that this will simply rollout the current definition of your `Deployment`, meaning if you specified the "old" image tag, it will still rollout the old image tag. So you may need to update the tag used by the Deployment and then use `oc rollout`. Of course, if you use `latest` or similar as a tag, this will work as expected. – Simon Sep 18 '20 at 09:27
0

The build starts automatically if your image stream has

--reference-policy source

In that case, it is correct to update the image stream using

oc -import-image [...]

To update a "local" ImageStream, instead of

oc import-image is:2.0 --from quay.io/xxx/myimage:latest --confirm --reference-policy local

you should update the existing local ImageStream tag

oc tag quay.io/xxx/myimage:latest is:2.0 --reference-policy local 

This command automatically triggers a new deployment of your app.

Guildenstern70
  • 1,715
  • 18
  • 18
0

Add this to your deploymentConfig

triggers:
- type: ConfigChange
- imageChangeParams:
    automatic: true
    containerNames:
      - <your-container-name>
    from:
      kind: ImageStreamTag
      name: '<image_name>:latest'
      namespace: <your-namespace>
  type: ImageChange
Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42
  • Thank you. As far as I understand, with this configuration I get automatic deployment on image change. But I would like to decide when to deploy. – Guildenstern70 Sep 25 '20 at 15:02