bored-belgium-2184
10/04/2023, 2:43 AM${imageBuildContext}/Dockerfile
, dockerfileContent);
// Use AWS SDK to build and push the Docker image to ECR
const ecrLoginResult = aws.ecr.getAuthorizationToken();
const ecrRegistry = repo.repositoryUrl;
// Use awsx.ecr.Image
instead of aws.ecr.Image
const ecrImage = new awsx.ecr.Image("app-img", {
imageName: pulumi.interpolate`${repo.repositoryName}:latest`,
build: {
context: imageBuildContext,
dockerfile: "Dockerfile",
},
}, { dependsOn: [ecrLoginResult] });
const ecrLoginCommand = pulumi.interpolate`docker login -u AWS -p ${ecrLoginResult.token} ${ecrRegistry}`;
const ecrBuildCommand = pulumi.interpolate`docker build -t ${ecrImage.imageName} ${imageBuildContext}`;
const ecrPushCommand = pulumi.interpolate`docker push ${ecrImage.imageName}`;
const imageNameOutput = ecrImage.imageName;
// Set up task definition for Fargate
const taskDefinition = new aws.ecs.TaskDefinition("taskdefinition", {
family: "ecs1",
networkMode: "awsvpc",
requiresCompatibilities: ["FARGATE"],
executionRoleArn: ecsTaskExecutionRole.arn,
cpu: "256",
memory: "512",
containerDefinitions: pulumi.interpolateJson([{
name: "app",
image: imageNameOutput, // Use the image name here
portMappings: [{
containerPort: 9060,
hostPort: 9060,
}],
}]),
});
// ...
// Use the full image URL when creating the ECS service
const service = new aws.ecs.Service("service", {
cluster: cluster.arn,
taskDefinition: taskDefinition.arn,
launchType: "FARGATE",
desiredCount: numberNodes,
networkConfiguration: {
subnets: aws.ec2.getSubnetIds({ vpcId: "vpc-035bf208713482f29" }).then((subnets) =>
subnets.ids.slice(0, numberNodes)
),
securityGroups: ["sg-0b3fa29117360818c"], // Specify your security groups here
},
platformVersion: "LATEST",
deploymentMaximumPercent: 200, // Adjust as needed
deploymentMinimumHealthyPercent: 100, // Adjust as needed
waitForSteadyState: true, // Wait for the service to stabilize
});
// Create an SSL certificate (replace with your actual ARN or ACM certificate)
const sslCertificateArn = "arnawsacmus east 1458643523960:certificate/5fbd3c7e-12ee-4d42-af20-f97e1ffc5760";
// Create an Application Load Balancer (ALB)
const loadBalancer = new aws.lb.LoadBalancer("loadBalancer", {
internal: false, // Set to true for internal ALB, false for internet-facing ALB
loadBalancerType: "application",
subnets: aws.ec2.getSubnetIds({ vpcId: "vpc-035bf208713482f29" }).then((subnets) =>
subnets.ids.slice(0, numberNodes)
),
enableDeletionProtection: false, // Set to true if you want to enable deletion protection
securityGroups: ["sg-0b3fa29117360818c"], // Specify your security groups here
});
// Create an ALB listener for HTTPS (port 443)
const httpsListener = new aws.lb.Listener("httpsListener", {
loadBalancerArn: loadBalancer.arn,
port: 443,
protocol: "HTTPS",
sslPolicy: "ELBSecurityPolicy-2016-08",
certificateArn: "arnawsacmus east 1458643523960:certificate/5fbd3c7e-12ee-4d42-af20-f97e1ffc5760", // Use your SSL certificate ARN here
defaultActions: [{
type: "fixed-response",
fixedResponse: {
contentType: "text/plain",
statusCode: "200",
},
}],
});
// ...
export const clusterName = cluster.name;