Refactor Todo app structure by moving main functionality to a new Tod… #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to AWS | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: # Allow manual trigger | |
| env: | |
| AWS_REGION: us-east-1 | |
| PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }} | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| # Login to ECR (needed for Docker push) | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| # Deploy everything through Pulumi (handles Docker building and infrastructure) | |
| - name: Deploy with Pulumi | |
| run: | | |
| cd apps/infra | |
| bun install | |
| pulumi stack select compai/placeholder-dev --create | |
| pulumi up --yes | |
| # Run migrations after deployment | |
| - name: Run database migrations | |
| run: | | |
| echo "🚀 Running database migrations..." | |
| # Wait for service to be stable after deployment | |
| echo "Waiting for ECS service to be stable..." | |
| aws ecs wait services-stable --cluster pathfinder-cluster --services pathfinder-service | |
| # Get the latest task definition ARN | |
| TASK_DEF_ARN=$(aws ecs describe-services \ | |
| --cluster pathfinder-cluster \ | |
| --services pathfinder-service \ | |
| --query 'services[0].taskDefinition' \ | |
| --output text) | |
| echo "Using task definition: $TASK_DEF_ARN" | |
| # Run the migration task | |
| TASK_ARN=$(aws ecs run-task \ | |
| --cluster pathfinder-cluster \ | |
| --task-definition $TASK_DEF_ARN \ | |
| --launch-type FARGATE \ | |
| --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}" \ | |
| --overrides '{"containerOverrides":[{"name":"pathfinder-app","command":["bun","run","db:migrate"]}]}' \ | |
| --query 'tasks[0].taskArn' \ | |
| --output text) | |
| echo "Migration task started: $TASK_ARN" | |
| # Wait for migration to complete | |
| aws ecs wait tasks-stopped --cluster pathfinder-cluster --tasks $TASK_ARN | |
| # Check if migration succeeded | |
| EXIT_CODE=$(aws ecs describe-tasks \ | |
| --cluster pathfinder-cluster \ | |
| --tasks $TASK_ARN \ | |
| --query 'tasks[0].containers[0].exitCode' \ | |
| --output text) | |
| if [ "$EXIT_CODE" != "0" ]; then | |
| echo "❌ Migration failed with exit code: $EXIT_CODE" | |
| exit 1 | |
| fi | |
| echo "✅ Migrations completed successfully!" | |
| - name: Deployment complete | |
| run: | | |
| echo "✅ Deployment completed successfully!" | |
| echo "🎯 Pulumi handled Docker building and infrastructure deployment" |