wide-whale-78548
11/28/2021, 5:58 PMtag
option does not exist in buildAndPushImage
method:
const repo = new awsx.ecr.Repository(....);
const img = repo.buildAndPushImage( {
context: "path/to/app",
tag: "some-app/v.some-version",
});
When I check the command it generates, it adds an auto generated tag, so then I cannot overwrite it even using extraOptions
if I use DockerBuild
in it.
I want to use the hash value of a folder as the value of the tag, so then I can check if anything in it that folder has actually changed before building a new image and pushing it again to ECR and then making ECS to go through it’s lengthy life-cycle even for non relevant pushes 😄
I can build the Docker image locally in the pipeline and push the image, but I’m looking for a way to do it all in Pulumi, also without having to manually provide repository details/credentials using docker.Image(…)
🤔steep-sunset-89396
11/28/2021, 11:32 PMdocker.buildAndPushImage()
to biuld the image before pushing to the registry, the first parameter is your image nameprivate 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;
}
wide-whale-78548
11/29/2021, 8:44 AMaws.ecr.getCredentials
method exits and that was very helpful.steep-sunset-89396
11/29/2021, 8:51 AMwide-whale-78548
11/29/2021, 8:58 AM