-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ECR assets: referencing outside of the CDK #5971
Comments
@caruso-billfire can you please provide a bit more details about your use case for consuming CDK docker assets outside the CDK? Generally, we design assets to be consumable from CDK constructs. If you are looking for a way to publish docker images to ECR, you should be able to do this with any supporting CI/CD tool. |
@EduardTheThird wrote: Previously when creating an ECS service and using the ECR asset functionality, an ECR repo was created for that service. Having the service have it's own ECR repo allows us to easier manage it as it was linked to a service. With the shared repository, tags such as latest, qa, dev now conflict. Ideally when using ECS.ContainerImage.fromAsset to create the Docker image, we would like to specify what the ECR repo and tag it should create for it. The central ECR repo could be retained, however, we would appreciate the option to retain the old or similar workflow. Reproduction Steps Ideally, we would like to be able to specify what ECR repo and image tag it should create. |
Even in the case of using |
Hi @eladb I'm a huge fan of the CDK and we have been using it since your first very early versions last year. As you mentioned in #5976, the intent of assets might be different from our use-case, which I will try to explain as best as possible. When deploying new services to our AWS environments, we copy the application's build artifact into a folder within our AWS CDK TypeScript solution. This application's artifact contains a Dockerfile and is configured for the environment. The workflow:
Caveats and possible improvements on the process:
Should you need more clarification on any of this, or more examples, I'd be more than happy to assist in any way possible. If it was possible for us to create, name and assign ECR repositories to ECS EC2 and ECS Fargate Services, and seed them with a locally built docker image, it would simplify and cleanup our workflow greatly! 🚀 🎉🎉 |
@EduardTheThird I must say that I still can't fully understand your use case. What do you mean by:
Can you elaborate? I feel this is where you guys are doing something that's outside of what we considered initially. |
In that case, I would argue that you don't need to use docker image assets at all. Just define an ECR repository (with or without an explicit physical name) and use Sketch: const repo = new ecr.Repository(this, 'MyRepo', { repositoryName: 'repository-for-my-service' });
const image = ContainerImage.fromEcrRepository(repo); Then, have your CI/CD pipeline push to What am I missing? |
That is almost exactly what we need, the only missing piece of the puzzle is the option to reference an image that's constructed directly from sources on disk. ContainerImage.fromAsset is able to reference our artifact folder in the solution: ContainerImage.fromEcrRepository has no directory option, if it could be added, we will be golden : Note: This was tested on AWS CDK 1.21.1 |
@EduardTheThird wrote:
Something still doesn’t add up for me... you mentioned that at runtime you actually want to reference the image pushed to ECR from your CI/CD pipeline, not the one built from disk. |
Aah, let me clarify. Let us consider service "sometestservice" again as our example. After the AWS CDK has deployed the ECS service, a repository, cdk/sometestservice4b11af with an image cdk/sometestservice4b11af@sha:1234353543 is created. This image is built from disk, by the AWS CDK. At this stage, inside our newly created ECS service's task definition, cdk/sometestservice4b11af@sha:1234353543 is used. This is where the AWS CDK stops and the manual labor begins 😄 In Azure DevOps, we now update our CI/CD pipeline for "sometestservice". We continue to use cdk/sometestservice4b11af as the service's main repository for the environment. On each new release, a new image is pushed to it and the service updated. We could potentially bypass many of the manual processes by being able to use ContainerImage.fromEcrRepository, should it be able to build images from disk. 🥇 |
@EduardTheThird Why does the first image come from disk and the rest come from the CI/CD pipeline? What makes this first image special and what value to you get from actually consuming it as an asset ("from disk")? Another question: why not let the CDK always build & push the image to ECR? If you invoke |
Excellent question, I've noticed that Cloudformation would sometimes get stuck if the newly created ECS service does not pass health checks. It seems to wait for the service to reach a steady state. Which it never will as it is referencing an empty newly created repository. The first image is only needed to allow the service to pass health checks, reach a steady-state and allow Cloudformation to complete. Regarding the coupling of the infrastructure code and app code in our CI/CD pipeline, I love the idea, it is certainly something that we will aim to implement as soon as we worked out all the kinks 😺 |
I am closing this for now. Please feel free to reopen if you wish to continue the discussion or provide more use cases. |
I am trying to accomplish something very similar. When the stack is first deployed, I would like to pass the |
Hi all, @djheru I am currently trying to achieve the exact same thing you want to do, and I assume there's something I'm not getting here as this seems a pretty common need. @eladb I actually tried to implement it the way you mentioned (as it seemed logic to me) but the thing is that when doing it, as @EduardTheThird noted, the service created doesn't pass the health checks anymore, because of the ECS part ( I mean, we are actually saying to the newly created ECS to use an image from a repository newly created, which doesn't contains any image for now, so it just waits there... @eladb I think I will do this by doing exactly what you suggested here, but I'm kind of anxious there, because I can't think about it as a production ready workflow Anyway, I'm kinda stuck in here, so any help would be awesome (idk, almost a year since last comment, maybe someone found a way :-D). |
Thanks for the info, @eladb, but AWS advise against using hardcoded names and we have faced many problems updating the stack when |
Originally posted by @caruso-billfire in #5733 (comment)
How would you reference the image outside of the CDK? Is that use case supposed to even be supported? What would the best practices for that be?
The text was updated successfully, but these errors were encountered: