awslabs/ecs-refarch-continuous-deployment

Circular Dependency on ECR artifact

lyoungblood opened this issue · 5 comments

This is such a powerful architectural pattern, @jpignata - especially with Fargate.

I just wanted to make you aware of a circular dependency issue. I couldn't figure out an elegant workaround. Since you are creating a brand new ECR repository that will have zero artifacts until you do a successful build, the ECS service will never complete creation because the task can't move from PENDING to RUNNING state until it can pull the artifact from ECR. And, the Pipeline can't create yet because it needs an ECS service to deploy to.

The workaround I am currently using is to launch the CloudFormation template, then while the ECS Service is attempting to launch, doing a manual "docker build/tag/push" to the newly created ECR repository. Once there is an artifact to pull, the ECS service goes to CREATE_COMPLETE status and the Pipeline gets created.

This probably wouldn't be an issue if you're using a pre-existing ECR repository with at least 1 artifact.

Would you mind pointing out where in the code that workaround is? I actually rewrote this entire architecture pattern into a single template so that I didn't have that issue that others faced if they wanted to update stack (where you lose the ability to change parameters as part of a stack update, or potentially have stack updates override parameters causing unexpected behavior).

I also agree about your second statement (having a CloudFormation template in the pipeline to manage the task definition and service) - it seems somewhat against the "infrastructure as code" paradigm to have a service like CodePipeline updating the task definition for you, as opposed to versioning that in source control like everything else. Perhaps if I have enough free time I'll take a stab at it and create a pull request.

See
#33 for
discussion on this.

Great! That actually looks like a better option, to deploy with DesiredCount 0. By merging all the nested templates into 1, I've already fixed the issue with parameter overrides in the nested templates getting overwritten by stack updates.