This message was deleted.
# aws
s
This message was deleted.
s
Hey Pooyan, yes it should be possible to do that.
If you use
docker.buildAndPushImage()
to biuld the image before pushing to the registry, the first parameter is your image name
This is a function I wrote in TS
Copy code
private computeImageFromAsset(appPath: string, repositoryUrl: string, registryId: string, parent: pulumi.Resource): pulumi.Output<string> {

        let imageName = this.args.imageName;

        let dockerBuildArgs: any = {};

        let _dockerBuild: docker.DockerBuild = {
            args: dockerBuildArgs,
            context: appPath,
            dockerfile: `${appPath}/Dockerfile`,
            cacheFrom: {},
        };

        const uniqueImageName = docker.buildAndPushImage(imageName, _dockerBuild, repositoryUrl, parent, async () => {

            let credentials = await aws.ecr.getCredentials({
                registryId: registryId
            }, {
                parent, async: true
            });

            let decodedCredentials = Buffer.from(credentials.authorizationToken, "base64").toString();
            let [username, password] = decodedCredentials.split(":");
            if (!password || !username) {
                throw new Error("Invalid credentials");
            }

            return {
                registry: credentials.proxyEndpoint,
                username: username,
                password: password,
            };
        });

        uniqueImageName.apply(d => pulumi.log.debug(`    build complete: ${imageName} (${d})`, parent));
        return uniqueImageName;
    }
❤️ 1
w
Thanks @steep-sunset-89396 I was not aware that
aws.ecr.getCredentials
method exits and that was very helpful.
s
Glad to hear. Have you seen our repo full of examples? That's how I found this function.
❤️ 1
w
Yes, the Pulumi example repository is great :)
👍 1