Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

 πŸ€– Plandex  πŸ“ Changes ✏️ Edits: β€’ infra/deploy.sh βœ… Fix error handling in ensure_ecr_repository_exists function βœ… Remove redundant log message for creating ECR repository β€’ infra/src/main.ts βœ… Add logging before VPC creation βœ… Add logging before RDS instance creation βœ… Add logging before ECS cluster creation βœ… Add logging after all resources have been defined

Dane Schneiderb4d85e3c5130
diff --git a/infra/deploy.sh b/infra/deploy.sh
index 7b65d495..297c7c8b 100755
--- a/infra/deploy.sh
+++ b/infra/deploy.sh
@@ -28,21 +28,20 @@ handle_error() {
trap 'handle_error' ERR
+log "Deploying the infrastructure..."
+
export AWS_PROFILE=plandex
# Generate a unique tag for the deployment
export STACK_TAG=$(uuidgen | cut -d '-' -f1)
-# Set variables for the ECR repository and image tag
-ECR_REPOSITORY=$(aws ecr describe-repositories --repository-names plandex-ecr-repository | jq -r '.repositories[0].repositoryUri')
-IMAGE_TAG=$(git rev-parse --short HEAD)
# Function to ensure the ECR repository exists
ensure_ecr_repository_exists() {
# Check if the ECR repository exists
- ECR_REPO_EXISTS=$(aws ecr describe-repositories --repository-names plandex-ecr-repository 2>/dev/null)
- if [ -z "$ECR_REPO_EXISTS" ]; then
- # Create the ECR repository if it does not exist
+ log "Checking if the ECR repository 'plandex-ecr-repository' exists..."
+ if ! aws ecr describe-repositories --repository-names plandex-ecr-repository 2>/dev/null; then
+ log "ECR repository does not exist. Creating repository..."
aws ecr create-repository --repository-name plandex-ecr-repository
log "ECR repository 'plandex-ecr-repository' created."
else
@@ -50,9 +49,15 @@ ensure_ecr_repository_exists() {
fi
}
+log "Checking if the ECR repository exists..."
+
# Ensure the ECR repository exists before proceeding
ensure_ecr_repository_exists
+# Set variables for the ECR repository and image tag
+ECR_REPOSITORY=$(aws ecr describe-repositories --repository-names plandex-ecr-repository | jq -r '.repositories[0].repositoryUri')
+IMAGE_TAG=$(git rev-parse --short HEAD)
+
# Function to deploy or update the CloudFormation stack using AWS CDK
deploy_or_update_stack() {
# Check if the stack exists
@@ -104,10 +109,15 @@ update_ecs_service() {
}
# Deploy or update the CloudFormation stack
+log "Deploying or updating the CloudFormation stack..."
deploy_or_update_stack
# Build and push the Docker image to ECR
+log "Building and pushing the Docker image to ECR..."
build_and_push_image
# Update the ECS service with the new Docker image
+log "Updating the ECS service with the new Docker image..."
update_ecs_service
+
+log "Infrastructure deployed successfully"
\ No newline at end of file
diff --git a/infra/src/main.ts b/infra/src/main.ts
index 59f7b101..de1f8c08 100644
--- a/infra/src/main.ts
+++ b/infra/src/main.ts
@@ -30,6 +30,7 @@ export class PlandexStack extends cdk.Stack {
super(scope, id, props);
// Create a VPC with two public and two private subnets
+ console.log('Creating VPC...');
const vpc = new ec2.Vpc(this, `plandex-vpc-${tag}`, {
maxAzs: 2,
subnetConfiguration: [
@@ -60,6 +61,7 @@ export class PlandexStack extends cdk.Stack {
);
// Create an RDS Aurora PostgreSQL database
+ console.log('Creating RDS instance...');
const dbInstance = new rds.DatabaseInstance(
this,
`plandex-rds-instance-${tag}`,
@@ -79,14 +81,15 @@ export class PlandexStack extends cdk.Stack {
}
);
- // Create an ECR repository
- const ecrRepository = ecr.Repository.fromRepositoryName(this, 'PlandexEcrRepository', 'plandex-ecr-repository');
- {
- repositoryName: "plandex-ecr-repository",
- }
+ // Get the ECR repository
+ const ecrRepository = ecr.Repository.fromRepositoryName(
+ this,
+ "PlandexEcrRepository",
+ "plandex-ecr-repository"
);
// Create an ECS cluster
+ console.log('Creating ECS cluster...');
const ecsCluster = new ecs.Cluster(this, `plandex-ecs-cluster-${tag}`, {
vpc,
});
@@ -256,48 +259,77 @@ export class PlandexStack extends cdk.Stack {
new subscriptions.SmsSubscription(notifySms)
);
- const dbInstanceCpuUtilizationAlarm = new cloudwatch.Alarm(this, 'HighDbCpuUtilizationAlarm', {
- metric: dbInstance.metricCPUUtilization(),
- threshold: 80,
- evaluationPeriods: 2,
- alarmDescription: 'Alarm when RDS CPU utilization exceeds 80%',
- comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
- treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
-});
-dbInstanceCpuUtilizationAlarm.addAlarmAction(new cloudwatchActions.SnsAction(alarmNotificationTopic));
-
-const dbInstanceFreeableMemoryAlarm = new cloudwatch.Alarm(this, 'LowDbFreeableMemoryAlarm', {
- metric: dbInstance.metricFreeableMemory(),
- threshold: 200 * 1024 * 1024, // Threshold in bytes (e.g., 200MB)
- evaluationPeriods: 2,
- alarmDescription: 'Alarm when RDS freeable memory is too low',
- comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
- treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
-});
-dbInstanceFreeableMemoryAlarm.addAlarmAction(new cloudwatchActions.SnsAction(alarmNotificationTopic));
-
-const fargateServiceCpuUtilizationAlarm = new cloudwatch.Alarm(this, 'HighFargateCpuUtilizationAlarm', {
- metric: fargateService.metricCpuUtilization(),
- threshold: 80,
- evaluationPeriods: 2,
- alarmDescription: 'Alarm when Fargate CPU utilization exceeds 80%',
- comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
- treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
-});
-fargateServiceCpuUtilizationAlarm.addAlarmAction(new cloudwatchActions.SnsAction(alarmNotificationTopic));
-
-const fargateServiceMemoryUtilizationAlarm = new cloudwatch.Alarm(this, 'HighFargateMemoryUtilizationAlarm', {
- metric: fargateService.metricMemoryUtilization(),
- threshold: 80,
- evaluationPeriods: 2,
- alarmDescription: 'Alarm when Fargate memory utilization exceeds 80%',
- comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
- treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
-});
-fargateServiceMemoryUtilizationAlarm.addAlarmAction(new cloudwatchActions.SnsAction(alarmNotificationTopic));
+ const dbInstanceCpuUtilizationAlarm = new cloudwatch.Alarm(
+ this,
+ "HighDbCpuUtilizationAlarm",
+ {
+ metric: dbInstance.metricCPUUtilization(),
+ threshold: 80,
+ evaluationPeriods: 2,
+ alarmDescription: "Alarm when RDS CPU utilization exceeds 80%",
+ comparisonOperator:
+ cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
+ treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
+ }
+ );
+ dbInstanceCpuUtilizationAlarm.addAlarmAction(
+ new cloudwatchActions.SnsAction(alarmNotificationTopic)
+ );
+
+ const dbInstanceFreeableMemoryAlarm = new cloudwatch.Alarm(
+ this,
+ "LowDbFreeableMemoryAlarm",
+ {
+ metric: dbInstance.metricFreeableMemory(),
+ threshold: 200 * 1024 * 1024, // Threshold in bytes (e.g., 200MB)
+ evaluationPeriods: 2,
+ alarmDescription: "Alarm when RDS freeable memory is too low",
+ comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
+ treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
+ }
+ );
+ dbInstanceFreeableMemoryAlarm.addAlarmAction(
+ new cloudwatchActions.SnsAction(alarmNotificationTopic)
+ );
+
+ const fargateServiceCpuUtilizationAlarm = new cloudwatch.Alarm(
+ this,
+ "HighFargateCpuUtilizationAlarm",
+ {
+ metric: fargateService.metricCpuUtilization(),
+ threshold: 80,
+ evaluationPeriods: 2,
+ alarmDescription: "Alarm when Fargate CPU utilization exceeds 80%",
+ comparisonOperator:
+ cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
+ treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
+ }
+ );
+ fargateServiceCpuUtilizationAlarm.addAlarmAction(
+ new cloudwatchActions.SnsAction(alarmNotificationTopic)
+ );
+
+ const fargateServiceMemoryUtilizationAlarm = new cloudwatch.Alarm(
+ this,
+ "HighFargateMemoryUtilizationAlarm",
+ {
+ metric: fargateService.metricMemoryUtilization(),
+ threshold: 80,
+ evaluationPeriods: 2,
+ alarmDescription: "Alarm when Fargate memory utilization exceeds 80%",
+ comparisonOperator:
+ cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
+ treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
+ }
+ );
+ fargateServiceMemoryUtilizationAlarm.addAlarmAction(
+ new cloudwatchActions.SnsAction(alarmNotificationTopic)
+ );
}
}
+console.log('All resources have been defined in the CDK stack.');
+
const app = new cdk.App();
const stack = new PlandexStack(app, "plandex-stack-" + tag);