-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
89 lines (80 loc) · 2.82 KB
/
index.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2024, Pulumi Corporation. All rights reserved.
// Import required libraries
import * as aws from "@pulumi/aws"; // Required for ECS
import * as awsx from "@pulumi/awsx";
import * as dockerBuild from "@pulumi/docker-build";
import * as pulumi from "@pulumi/pulumi"; // Required for Config and interpolation
// Read the current stack configuration, see Pulumi.<STACK>.yaml file
// Configuration values can be set with the pulumi config set command
// OR by editing the Pulumi.<STACK>.yaml file.
// OR during the pulumi new wizard.
const config = new pulumi.Config();
// An ECS cluster to deploy into.
const cluster = new aws.ecs.Cluster("cluster", {});
// An ALB to serve the container endpoint to the internet.
const loadbalancer = new awsx.lb.ApplicationLoadBalancer("loadbalancer", {});
// An ECR repository to store our application's container image.
const ecr = new awsx.ecr.Repository("repo", {
forceDelete: true,
});
// Grab auth credentials for ECR.
const auth = aws.ecr.getAuthorizationTokenOutput({
registryId: ecr.repository.registryId,
});
// Build and publish our application's container image from ./app to the ECR repository.
const image = new dockerBuild.Image("image", {
// Use the pushed image as a cache source.
cacheFrom: [{
registry: {
ref: pulumi.interpolate`${ecr.repository.repositoryUrl}:cache`,
},
}],
cacheTo: [{
registry: {
imageManifest: true,
ociMediaTypes: true,
ref: pulumi.interpolate`${ecr.repository.repositoryUrl}:cache`,
},
}],
// Build multi-platforms
platforms: [
dockerBuild.Platform.Linux_amd64,
// add more as needed
],
push: true,
// Provide our ECR credentials.
registries: [{
address: ecr.repository.repositoryUrl,
password: auth.password,
username: auth.userName,
}],
//
// Other parameters
//
// Tag our image with our ECR repository's address.
tags: [pulumi.interpolate`${ecr.repository.repositoryUrl}:latest`],
// The Dockerfile resides in the app directory for this example.
context: {
location: "app",
},
});
// Deploy an ECS Service on Fargate to host the application container.
const service = new awsx.ecs.FargateService("service", {
cluster: cluster.arn,
assignPublicIp: true,
taskDefinitionArgs: {
container: {
name: "service-container",
image: image.ref,
cpu: 128,
memory: 512,
essential: true,
portMappings: [{
containerPort: 80,
targetGroup: loadbalancer.defaultTargetGroup,
}],
},
},
});
// The URL at which the container's HTTP endpoint will be available.
export const url = pulumi.interpolate`http://${loadbalancer.loadBalancer.dnsName}`;