stale-park-1622
09/27/2019, 2:08 PMexport function createApiImage(name: string, port: number, contextDir: string): {repositoryUrl: pulumi.Output<string>, image: awsx.ecr.RepositoryImage} {
const gitCommit = 'e0e5162';
// set up ECR Lifecycle Policies (<https://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html>)
// remove any images that are older than one week that are untagged
const repository = new awsx.ecr.Repository(`pulumi-${pulumi.getStack()}-repository`, {
lifeCyclePolicyArgs: {
rules: [{
selection: "untagged",
maximumAgeLimit: 7,
}],
}
});
// And publish its URL, so we can push to it if we'd like.
const repositoryUrl = repository.repository.repositoryUrl;
const build: docker.DockerBuild = {
context: contextDir, // context is a path to a directory to use for the Docker build context
dockerfile: path.join(contextDir, './docker/api.v2.Dockerfile'), // dockerfile may be used to override the default Dockerfile name and/or location
args: {
EXPOSE_PORT: String(port),
},
};
// Invoke 'docker' to actually build the DockerFile that is in the folder relative to
// this program. Once built, push that image up to the ECR repo.
//const image = repository.buildAndPushImage(build);
const image = awsx.ecr.buildAndPushImage(
`${name}:${gitCommit}`,
build,
{
repository: repository.repository,
}
);
return {repositoryUrl, image};
}
→ pulumi up
Previewing update (dev):
Type Name Plan
+ pulumi:pulumi:Stack dev create
+ ├─ awsx:ecr:Repository dev-api-image:e0e5162 create
+ │ └─ aws:ecr:LifecyclePolicy dev-api-image:e0e5162 create
+ └─ awsx:ecr:Repository pulumi-dev-repository create
+ ├─ aws:ecr:Repository pulumi-dev-repository create
+ └─ aws:ecr:LifecyclePolicy pulumi-dev-repository create
Resources:
+ 6 to create
Do you want to perform this update?
yes
> no
details
tall-librarian-49374
09/27/2019, 2:13 PMhandsome-actor-1155
09/27/2019, 5:14 PMstale-park-1622
09/27/2019, 5:38 PMtall-librarian-49374
09/27/2019, 6:51 PMstale-park-1622
10/15/2019, 10:05 AMtall-librarian-49374
10/15/2019, 8:39 PM