|
| 1 | +name: Deploy Prod (ECS) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "prod-*" |
| 7 | + |
| 8 | +env: |
| 9 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 10 | + AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} |
| 11 | + ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-push: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + id-token: write |
| 18 | + contents: read |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + service: |
| 23 | + - { name: api-gateway, path: . } # Ajusta si API tiene Dockerfile propio en raíz/otra ruta |
| 24 | + - { name: ingestion, path: trading_ai_system/ingestion_service } |
| 25 | + - { name: inference, path: trading_ai_system/inference_service } |
| 26 | + - { name: control, path: trading_ai_system/control_service } |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Configure AWS credentials (OIDC) |
| 31 | + uses: aws-actions/configure-aws-credentials@v4 |
| 32 | + with: |
| 33 | + role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} # IAM Role con trust para GitHub |
| 34 | + aws-region: ${{ env.AWS_REGION }} |
| 35 | + |
| 36 | + - name: Login to ECR |
| 37 | + id: ecr |
| 38 | + uses: aws-actions/amazon-ecr-login@v2 |
| 39 | + |
| 40 | + - name: Build & Push ${{ matrix.service.name }} |
| 41 | + run: | |
| 42 | + IMAGE=${{ env.ECR_REGISTRY }}/neurobank/${{ matrix.service.name }}:${{ github.ref_name }} |
| 43 | + docker build -t "$IMAGE" ${{ matrix.service.path }} |
| 44 | + docker push "$IMAGE" |
| 45 | +
|
| 46 | + deploy-ecs: |
| 47 | + needs: build-and-push |
| 48 | + runs-on: ubuntu-latest |
| 49 | + permissions: |
| 50 | + id-token: write |
| 51 | + contents: read |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + svc: |
| 56 | + - { ecs_service: api-gateway-svc, taskdef: trading_ai_system/ecs/api-gateway-task.json, container: api-gateway, image_repo: neurobank/api-gateway } |
| 57 | + - { ecs_service: ingestion-svc, taskdef: trading_ai_system/ecs/ingestion-service-task.json, container: ingestion, image_repo: neurobank/ingestion } |
| 58 | + - { ecs_service: inference-svc, taskdef: trading_ai_system/ecs/inference-service-task.json, container: inference, image_repo: neurobank/inference } |
| 59 | + - { ecs_service: control-svc, taskdef: trading_ai_system/ecs/control-service-task.json, container: control, image_repo: neurobank/control } |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Configure AWS credentials (OIDC) |
| 64 | + uses: aws-actions/configure-aws-credentials@v4 |
| 65 | + with: |
| 66 | + role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} |
| 67 | + aws-region: ${{ env.AWS_REGION }} |
| 68 | + |
| 69 | + - name: Render Task Definition |
| 70 | + id: taskdef |
| 71 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 72 | + with: |
| 73 | + task-definition: ${{ matrix.svc.taskdef }} |
| 74 | + container-name: ${{ matrix.svc.container }} |
| 75 | + image: ${{ env.ECR_REGISTRY }}/${{ matrix.svc.image_repo }}:${{ github.ref_name }} |
| 76 | + |
| 77 | + - name: Deploy to ECS |
| 78 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
| 79 | + with: |
| 80 | + task-definition: ${{ steps.taskdef.outputs.task-definition }} |
| 81 | + service: ${{ matrix.svc.ecs_service }} |
| 82 | + cluster: neurobank-prod |
| 83 | + wait-for-service-stability: true |
| 84 | + |
0 commit comments