https://pulumi.com logo
#general
Title
# general
f

future-refrigerator-88869

08/26/2021, 5:54 PM
Hi everyone 🙂 I have a question regarding the ECR. Assuming that I have a repository that sets up the infrastructure (including the aws ECR), how can I now create and push images to it from a different repo. I was looking at the
awsx.ecr.Repository
which has a function
buildAndPushImage
but it does not allow a lot of configuration for the image. What is the standard for creating images and pushing them to an ECR. Appreciate if someone can point me in the right direction 🙂
if possible without the docker cli 😄
b

bumpy-grass-54508

08/26/2021, 6:14 PM
pulumi.Docker
can do what you want - it does require the docker cli to be installed on the machine but you don't have to run the cli yourself https://www.pulumi.com/docs/reference/pkg/docker/image/
yeah awsx is pretty opinionated which can be fine sometimes, but if you want to do it yourself you're better off just using the base aws and docker resources directly
and i only have a c# example to give, but here is how you can create an AWS ECR repo and obtain credentials to pass to the pulumi.Docker.Image resource:
Copy code
var ecrRepo = new Pulumi.Aws.Ecr.Repository(...)

var ecrCreds = ecrRepo.RegistryId.Apply(registryId => Pulumi.Aws.Ecr.GetCredentials.InvokeAsync(
    new PulumiAws.Ecr.GetCredentialsArgs
    {
        RegistryId = registryId,
    },
    invokeOptions));

var registry = ecrCreds.Apply(creds =>
{
    var decodedCredentials = Encoding.UTF8.GetString(Convert.FromBase64String(creds.AuthorizationToken)).Split(':');
    return new Pulumi.Docker.ImageRegistry
    {
        Server = creds.ProxyEndpoint,
        Username = decodedCredentials[0],
        Password = decodedCredentials[1],
    };
});

var dockerImage = new Pulumi.Docker.Image("image", new Pulumi.Docker.ImageArgs
{
    ImageName = Output.Format($"{ecrRepo.RepositoryUrl}:{your-tag-or-build-id}"),
    Registry = registry,
    Build = dockerContext (path to dockerfile or other options)
});
then you can stick
dockerImage.BaseImageName
in your ECS task definition
re-reading your original question, it looks like you are creating the ECR Repo in a different process - so you might just need to modify what i have above to take in the ECR registry id / arn as an input or something and start from there
f

future-refrigerator-88869

08/26/2021, 6:55 PM
Hey @bumpy-grass-54508 thanks a lot for the answer. It looks like what I'd like to do yes. The only difference i see is that i need to export the
registryId
from the repository creating the ecrs. Then use that to get the credentials i guess
b

bumpy-grass-54508

08/26/2021, 7:13 PM
no problem! and yeah that should do the trick 👍