Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
[44;97;1m π€ Plandex [0;0;22m π 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.shindex 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 deploymentexport 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 existsensure_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-repositorylog "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 proceedingensure_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 CDKdeploy_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 filediff --git a/infra/src/main.ts b/infra/src/main.tsindex 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);