I use codebuild & codepipeline successfully for continuous deployment onto ECS for several projects but have came up with a problem. In this project I need to deploy the same build to four different ECS containers.
The default way I use codebuild and codepipeline CD is as shown in aws docs - I create imagedefinitions.json file at the end of the build process. As far as I can see this file can contain the definition of only one ECS container.
You have to provide the name of the container:
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"hello-world","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json
For this task defintion:
{
"taskDefinition": {
"family": "hello-world",
"containerDefinitions": [
{
"name": "hello-world",
"image": "012345678910.dkr.ecr.us-west-2.amazonaws.com/hello-world:6a57b99",
"cpu": 100,
"portMappings": [
{
"protocol": "tcp",
"containerPort": 80,
"hostPort": 80
}
],
"memory": 128,
"essential": true
}
]
It could work if I change the names of all four containers in the different services to the same name. for example that specific image name. But I can't tell if this is a good idea.
Now I wonder if I can use codepipeline to ECS in this project at all or should I deploy in a different way.