DEV Community

Cover image for Container image promotion across environments - YAML

Container image promotion across environments - YAML

Davide 'CoderDave' Benvegnù on January 29, 2020

When you use containers for your application, one of the things you need to think about is how to move (aka promote) the container images you gener...
Collapse
 
dsartain18 profile image
Don Sartain

Thanks so much for writing this! I searched for a couple days trying to find a way to stash the docker image in the artifact so I could use it in the deploy phase after my ARM templates run.

I'm running into a problem though. The save command doesn't work because it says the reference doesn't exist. I know it exists because I can build and push to the Azure Container Registry just fine, but somehow the argument you use doesn't work for me.

Also, I added another Docker step to list the docker images, and that comes back empty.

Any suggestions?

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

That's interesting... Are you trying to save/list the image in a different stage? or on another job or another agent job?

Collapse
 
dsartain18 profile image
Don Sartain

Well, turns out I made a couple of mistakes. I had the command to list docker images as "Docker Images ls" instead of "Docker Images". I'm not sure why. Then because I set the container registry value on the build part (I looked at a couple of different examples sorting this out) it attached the ACR URL to the front of the repository name. I sorted it all out in the end. Usually it was just a matter of asking Google the right question, and in the right tone of voice, apparently. Thanks again for putting this together!

Thread Thread
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Glad you've been able to figure this out.

Always happy to help :)

BTW, not sure you've seen my YouTube channel, where I cover topics on DevOps, Azure DevOps and GitHub... Maybe you can take a look at it 😇youtube.com/CoderDave

Collapse
 
jobinjosem2020 profile image
jobinjosem2020

Very nice explanation! BTW I have a question. Would it be possible to control the CD part based on branch used in CI phase? I need the CI to build image for all commits in all branches, but only the images from master branch to be promoted to UAT/Prod registry.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Thanks! Yes, what you ask is very common. In Classic Release Pipelines you can filter by Build branch in the trigger settings UI (see here docs.microsoft.com/en-us/azure/dev... ), while in YAML you can use a custom condition in the Stage which does the deployment (like this: docs.microsoft.com/en-us/azure/dev... )

Collapse
 
fauresco profile image
Fernando Auresco

First, thank you for the excellent article. I am trying myself to figure out how to migrate from classic Release to this new YAML and mainly worried if this new model is "production/real life ready". My major concern now is how do you "redeploy" to the same environment? Sometime this is necessary and in classic release there is a handy Redeploy button. What about rolling back to a previous version? In classic release you just open the release and click the redeploy for the environment you want and as a plus it warns you that you are rolling back because the current version in that environment is newer. Is that possible in YAML multistage pipeline? Another thing I like in classic release is that we have a very clear indication of what version is currently deployed at each environment by looking at the Releases page you see in green which version is the current for the specific environment. For YAML pipeline is this easy to track using the new Environment feature?

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

First, thank you for the excellent article.

Thanks! Always Happy to help :)

worried if this new model is "production/real life ready"

It sure is, we have thousands of Enterprise clients using YAML rather than classic. That said, you don;t have to forcely use the YAML pipelines if you don't want to... Classic ones will still be available :) But YAML ones have their own benefits.

in classic release there is a handy Redeploy button

You can do the same in YAML. Just expand the "Stage" and you can Re-run it (see below)

in classic release is that we have a very clear indication of what version is currently deployed at each environment by looking at the Releases page you see in green which version is the current for the specific environment. For YAML pipeline is this easy to track using the new Environment feature?

In YAML, as you've mentioned, you can to it in Environments. Take a look at my Environments Deep Dive video for more info on this

Collapse
 
fauresco profile image
Fernando Auresco

Awesome! This is what I was missing! I'll convert one of my deployments today. Thanks again!

Thread Thread
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

No problem! Let me know how it goes 😀

Thread Thread
 
fauresco profile image
Fernando Auresco

Sorry taking so long to answer, it went very well. Actually, now I have already several builds migrated to YAML and working just fine! :)
Once you have the YAML created it is very easy to replicate it to other repos or inherit from common repo with predefined jobs and steps. Thanks a lot!

Collapse
 
nagashekar profile image
NagaShekar

Thank you So much Article..This is very helpful and detailed. I have a quick question. why do we need to re-tag the image? Can you please explain that. Would you be able to cover how do we deploy this image into cluster.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

We need to re-tag the images because when you push an image to a registry, the image full name format must be REGISTRYNAME\IMAGENAME:TAG.
We generate the image with no registry name, so it only has the IMAGENAME:TAG part. When we push to a registry, we need to re-tag it to ad dthe REGISTRYNAME part.

To deploy the image, it would depend on what are you going to deploy to (i.e. Kubernetes, Docker Swarm, OpenShift, CloudFoundry, etc) because each one has it's own way, including different commands, toolsets, etc. And there may even be multiple ways to deploy to the same cluster (in K8S, for example, you can use the yaml definitions, the kubectl command, or yet something like helm) :)

Collapse
 
nagashekar profile image
NagaShekar

Thank you Davide for the response. One thing I noticed when I initially built the image is..Image name is appended with container registry name. Example in my case would be quay.apps.ocp.com/cmdiscovery. Looks like this is happening when I login to container registry before building the image. Is this intended behavior or as I am missing something?

Thread Thread
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Uhm, not sure… never seen that happening 😅 perhaps they may have changed the way the task work.. I will try to reproduce that behavior

Collapse
 
ayang920 profile image
AYang

Thank you for your post. It works well, but I have a question about the last step 'Push Image to ACR' (containerRegistry: MyProjectACRdev). Can I use modify this step by using the same push task to deploy the Docker image to an on-prem cluster? If not, what task can I use to achieve that?

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

When you work with container images, you still need to push them to a container registry anyway before you can “deploy” them to a cluster. So you can change registry on that command (for example push it to docker hub or another service rather than ACR) but you still have to do it before you can actually have it on the clister

Collapse
 
romina2001 profile image
romina2001 • Edited

Hi,

First of all thank you for this great article.
I tried to see your entire yaml file "You can download the complete YAML Pipeline definition file here.", but the link is broken. Can you please share the correct one.
Many thanks.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Sorry for the long wait. It is available now.

Collapse
 
gustavgahm profile image
Gustav Gahm

Another great article! This descripts more och less the pipeline I already setup in my project. Awesome to get feedback that I was on the right track.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Thank you man, happy to know you've found it helpful.

Btw, I will soon have a video-explanation of it on my new YouTube channel, maybe you can take a look at it ;) youtube.com/channel/UCtiFg7r8WBBzC...

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Not sure you've seen it already, but now the video with the explanation is out. Check it out here: youtube.com/watch?v=tG0O8vsO1LE

Collapse
 
nagashekar profile image
NagaShekar

Hi Davide. Can we templatize these steps so that they can re-used across projects? I think that will be an awesome addition to what you have out here.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Definitely. I actually mention that at the end of the post, but I've forgotten to write the post about templates... Thanks for reminding me haha :D