Use Pulumi Crosswalk to automate container image builds
How to use Pulumi infrastructure as code SDK to automate building a container image
Pulumi is an infrastructure as code framework for software engineers. Instead of writing YAML to define your infrastructure you can use higher level SDK commands, in a familiar programming language, and Pulumi will create the necessary resources for you automatically.
Build a container image and push it to Elastic Container Registry
Pulumi can automate conatiner image builds so that you no longer have to run
a private Elastic Container Registry, build your container image, and push it to the registry.
docker build anddocker push manually as part of the deploy process. Instead Pulumi will automatically createa private Elastic Container Registry, build your container image, and push it to the registry.
Then you can use the built image in a load balanced service like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// File: build-image.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
const repository = new awsx.ecr.Repository("repository", {});
const image = new awsx.ecr.Image("image", {
repositoryUrl: repository.url,
path: "./app",
});
const cluster = new aws.ecs.Cluster("cluster", {});
const lb = new awsx.lb.ApplicationLoadBalancer("lb", {});
const service = new awsx.ecs.FargateService("service", {
cluster: cluster.arn,
assignPublicIp: true,
taskDefinitionArgs: {
container: {
image: image.imageUri,
cpu: 512,
memory: 128,
essential: true,
portMappings: [{
targetGroup: lb.defaultTargetGroup,
}],
},
},
});
export const url = lb.loadBalancer.dnsName;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// File: build-image.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
const repository = new awsx.ecr.Repository("repository", {});
const image = new awsx.ecr.Image("image", {
repositoryUrl: repository.url,
path: "./app",
});
const cluster = new aws.ecs.Cluster("cluster", {});
const lb = new awsx.lb.ApplicationLoadBalancer("lb", {});
const service = new awsx.ecs.FargateService("service", {
cluster: cluster.arn,
assignPublicIp: true,
taskDefinitionArgs: {
container: {
image: image.imageUri,
cpu: 512,
memory: 128,
essential: true,
portMappings: [{
targetGroup: lb.defaultTargetGroup,
}],
},
},
});
export const url = lb.loadBalancer.dnsName;See Also
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article