CodePipeline is a powerful tool, it's excellent for automating your ECS deployments if the ECR image is deployed in the same account. You might be saying, but that should be easy. There shouldn't be any problem, you only need to create a CodePipeline with the Source as your Amazon ECR and the Deploy, the ECS Service, right?
Sadly, it won't work. Any image, which is cloned from one account to another is not recognized as a new deployment. This disrupts your entire pipeline. However, you may be also wondering, why would I do this? Let's take an example.
One AWS master account that clones Docker images to others.
Let's say your team handles 30 projects. Each project is located in individual AWS accounts. The "quick" path is to create individual credentials and deploy the images to each account. However, how likely is it that your team will make a mistake when handling 30 different projects? It's quite high. That's why, we decided to create a Master Account that contains the docker images. The master account later distributes the images to each AWS account. However, the catch was that CodePipeline never recognized the newly deployed images.
So, to fix this challenge, we had to make the following changes:
- To create an imagedefinitions.json file.
[
{
"name": "YOUR_APP_NAME",
"imageUri": "YOUR_ECR_REPO:latest"
}
]
Where,
- The name is the name of your project.
- The imageUri is the URL your local ECR gives you, for example, 445154566512.dkr.ecr.eu-west-2.amazonaws.com/myproject-env-prod:latest.
- To zip the file and keep it with the same name, imagedefinitions.zip
- To create an S3 bucket and enable Bucket Versioning.
- To upload the imagedefinitions.zip to your new S3 bucket.
- To create a basic Code PipeLine with your ECR as your Repo and the deploy destination of your ECS service.
- To Edit the Pipeline.
- To Add action.
- To configure the new action with the following values:
- Action name: Get-JSON
- Action provider: Amazon S3
- Bucket: your bucket.
- S3 object key: imagedefinitions.zip
- Output artifacts: imagedefinitions
- To edit the Deploy stage.
It should look this in your final configuration:
- To go to EventBridge.
- To go to the Buses and Rules section.
Where, YOUR_REPO_NAME is your repo's name. It's not the URL, only the name.
Comments
Post a Comment