Search code examples
amazon-web-servicesamazon-ecsaws-codepipelineaws-code-deployamazon-ecr

How to make CodePipeline work with Git, ECR, CodeBuild and CodeDeploy?


I'm trying to implement some sort of CI/CD for my application. What we currently have :

  • An ECS Cluster, that contain one or multiple instances (auto scaling), each instance have one task, and this task in an API.

  • CodeBuild, that we launch currently manually, we use it to build an image for the API located on ECR

After the CodeBuild execution, we need to stop tasks manually so that the new image is used by each task that will be then restarted automatically by the associated service.

To make it more CI/CD like, i chose to use CodePipeline

In the Source step, i choose Bitbucket (which is the platform we use to host our code), so that when a push is detected on a specific branch, it triggers the CodePipeline execution

In the Build step, i choose CodeBuild, that will just build Docker Image after receiving Bitbucket webhook.

And in the Deploy step, i choose CodeDeploy, that already have inside it an application that was created by selecting Blue / Green deployment for my ECS service.

What i currently don't understand is that :

  • Where can i include the ECR step ? If I include it in the Source step, the image will still not be build because CodeBuild is in the Build step which occurs after. According to my test, i can't include ECR in any other step, even if i create my own like Post-Build or something. So i don't know what to do on this one

  • What is precisely an Artifact ? After CodeBuild execution, it seems to save something on S3, and i can link the artifact to the CodeDeploy step. But i don't see the point of it in my case.


Solution

  • The docker image needs to be updated into ECR in the build stage.

    In the deploy stage you need to access the ECR image for your ECS cluster.

    Artifacts are outcome/results of a stage generally it'll be compiled source codes. But in your the artifact is the docker image and it can't be stored in S3 instead upload it to ECR.