How to roll back ecs deploy
Asked by venkatp:

Hi Team,

I'm using aws ecr Atlassian pipe for build and push the image to ecr repo. And using aws ecs deploy Atlassian pipe for deploying the ecs, but my doubt is how to rollback to old image?

Please suggest or share the bitbucketpipeline.


Answers:
author: Theodora Boudale
body: Hi [@venkatp](/t5/user/viewprofilepage/user-id/5335557) and welcome to the community!

First, you need to find the Pipelines build that pushed the old version of the image (the one that you want to roll back to).

If the step that pushes the image is a deployment step, there will be an option **Redeploy** next to the step name. You can select that to redeploy the old version of the image. Alternatively, you can select the **Deployments** page on the Bibtucket repo, select the name of the Deployment environment you use for this step, and you will see a list with all deployments to this environment. If you select the 3 dots next to the older build you want to redeploy, you will see the option **Redeploy**.

If the step that pushes the image is not a deployment step, then you can rerun the whole pipeline by selecting the **Rerun** option.

Kind regards,  
Theodora

comments: author: Venkatkp
body: Thanks for your answer! I don't see the redeploy option and if I click rerun it's building new docker image and updating with new not taking old image.

I could see ecr repo old image tag is dot

Please suggest or provide me the pipeline steps Thank you.


author: Theodora Boudale
body: Hi Venkat,

If you rerun a pipeline (and also if you run Redeploy for a step) the build is going to execute all the commands again.

Are you rerunning an old build (that built the older version of the image you want to roll back to) or the latest build?

If you rerun an older build (the build that built an image you want to roll back to and not the newest build), doesn't it push again the older version of the image you wanted to roll back to?

Kind regards,  
Theodora


author: Venkatkp
body: Hi Thodora,

I want to rollback 1 week ago image.

Please suggest me for image versioning along with above issue, because in json file we have mentioned tag name is latest, so how we can manage image version as well thanks in advance.

Regards,

Venkat


author: Theodora Boudale
body: Hi Venkat,

I don't know if it is possible to tag older versions of the image that do not have a tag already. I would suggest reaching out to AWS ECR support team or to a forum specific to AWS ECR to ask if this is somehow possible e.g. with AWS CLI.

I found the following blog post regarding rolling back to a previous version of a docker image in AWS ECR, however, this assumes that the older versions were also tagged (so you first need to figure out if and how the previous version can be tagged):

* <https://www.piotrnowicki.com/2021/05/2021-05-25-aws-elastic-container-repository-rollback-image.md/>

Did you try rerunning the Pipelines build that first pushed this 1 week old image?

Going forward, you may want to push multiple tags with each image, see the example on the pipes page under the text
> Pushing multiple tags: my-tag and latest. You have to build images with tags first:

* <https://bitbucket.org/atlassian/aws-ecr-push-image/src/master/>

If you push an additional (unique) tag along with the latest, it may be easier to roll back following the blog post I shared.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud