Skip to content

Commit b90319f

Browse files
committed
Enhance deployment workflow by dynamically discovering ECS cluster and service names, improving stability checks, and ensuring accurate task definition retrieval for database migrations.
1 parent 22dc5e6 commit b90319f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

.github/workflows/deploy.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,45 @@ jobs:
4646
run: |
4747
echo "🚀 Running database migrations..."
4848
49+
# Discover the actual cluster and service names
50+
echo "Discovering ECS cluster and service names..."
51+
CLUSTER_NAME=$(aws ecs list-clusters --query 'clusterArns[?contains(@, `pathfinder-cluster`)]' --output text | head -1 | awk -F'/' '{print $NF}')
52+
SERVICE_NAME=$(aws ecs list-services --cluster $CLUSTER_NAME --query 'serviceArns[?contains(@, `pathfinder-service`)]' --output text | head -1 | awk -F'/' '{print $NF}')
53+
54+
echo "Using cluster: $CLUSTER_NAME"
55+
echo "Using service: $SERVICE_NAME"
56+
4957
# Wait for service to be stable after deployment
5058
echo "Waiting for ECS service to be stable..."
51-
aws ecs wait services-stable --cluster pathfinder-cluster --services pathfinder-service
59+
aws ecs wait services-stable --cluster $CLUSTER_NAME --services $SERVICE_NAME
5260
5361
# Get the latest task definition ARN
5462
TASK_DEF_ARN=$(aws ecs describe-services \
55-
--cluster pathfinder-cluster \
56-
--services pathfinder-service \
63+
--cluster $CLUSTER_NAME \
64+
--services $SERVICE_NAME \
5765
--query 'services[0].taskDefinition' \
5866
--output text)
5967
6068
echo "Using task definition: $TASK_DEF_ARN"
6169
6270
# Run the migration task
6371
TASK_ARN=$(aws ecs run-task \
64-
--cluster pathfinder-cluster \
72+
--cluster $CLUSTER_NAME \
6573
--task-definition $TASK_DEF_ARN \
6674
--launch-type FARGATE \
67-
--network-configuration "awsvpcConfiguration={subnets=[$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=*pathfinder-vpc-private*" --query 'Subnets[*].SubnetId' --output text | tr '\t' ',')],securityGroups=[$(aws ec2 describe-security-groups --filters "Name=tag:Name,Values=pathfinder-service-sg" --query 'SecurityGroups[0].GroupId' --output text)],assignPublicIp=ENABLED}" \
75+
--network-configuration "awsvpcConfiguration={subnets=[$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=*pathfinder-vpc-private*" --query 'Subnets[*].SubnetId' --output text | tr '\t' ',')],securityGroups=[$(aws ec2 describe-security-groups --filters "Name=tag:Name,Values=*pathfinder-service-sg*" --query 'SecurityGroups[0].GroupId' --output text)],assignPublicIp=ENABLED}" \
6876
--overrides '{"containerOverrides":[{"name":"pathfinder-app","command":["bun","run","db:migrate"]}]}' \
6977
--query 'tasks[0].taskArn' \
7078
--output text)
7179
7280
echo "Migration task started: $TASK_ARN"
7381
7482
# Wait for migration to complete
75-
aws ecs wait tasks-stopped --cluster pathfinder-cluster --tasks $TASK_ARN
83+
aws ecs wait tasks-stopped --cluster $CLUSTER_NAME --tasks $TASK_ARN
7684
7785
# Check if migration succeeded
7886
EXIT_CODE=$(aws ecs describe-tasks \
79-
--cluster pathfinder-cluster \
87+
--cluster $CLUSTER_NAME \
8088
--tasks $TASK_ARN \
8189
--query 'tasks[0].containers[0].exitCode' \
8290
--output text)

0 commit comments

Comments
 (0)