How to add rollback functionality to a basic S3 CodeBuild deploy

此生再无相见时 提交于 2019-12-07 06:45:57

问题


I have followed this instruction to get a very basic ci workflow in aws. It works flawless but I want to have a extra functionality, rollback. First i though it would work "out-of-the-box", but not in my case, if I select the the previous job in CodeBuild that i want to rollback to and hit "Retry" i get this error message: "Error ArtifactsOverride must be set when using artifacts type CodePipelines". I have also tried to rerun the whole pipeline again with pipeline history page, but it's just a list of builds without any functionality.

My questions is: how to add a rollback function to my workflow. It doesn't have to be in the same pipeline etc. But it should not touch git.


回答1:


AWS CloudFormation now supports rolling back based in a CloudWatch alarm.

I'd put a CloudFront distribution in front of your S3 bucket with the origin path set to a folder within that bucket. Every time you deploy to S3 from CodeBuild you deploy to a random new S3 folder.

You then pass the folder name in a JSON file as an output artifact from your CodeBuild step. You can use this artifact as a parameter to a CloudFormation template updated by a CloudFormation action in your pipeline.

The CloudFormation template would update the OriginPath field of your CloudFront distribution to the folder containing your new deployment.

If the alarm fires then the CloudFormation template would roll back and flip back to the old folder.

There are several advantages to this approach:

  • Customers should only see either the new or old version while the deployment is happening rather than seeing potentially mixed files while the deployment is running.
  • The deployment logic is simpler because you're uploading a fresh set of files every time, rather than figuring out which files are new and which need to be deleted.
  • The rollback is pretty simple because you're flipping back to files which are still there rather than re-deploying the old files.

Your pipeline would need to contain both the CodeBuild and a sequential CloudFormation action.



来源:https://stackoverflow.com/questions/46025844/how-to-add-rollback-functionality-to-a-basic-s3-codebuild-deploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!