name: Prod-Deployment
on:
  push:
    branches:
      - astrovidhi-prod
  workflow_dispatch:     # Allows manual trigger

env:
  ECR_REPOSITORY: fmb-refixing-v2-goapp-prod
  EKS_CLUSTER_NAME: mypropertyqr-backend-eks 
  AWS_REGION: ap-south-1

jobs:
  
  build:
    
    name: Prod-Deployment
    runs-on: ubuntu-latest

    steps:
    
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: ${{env.AWS_REGION}}
      
    - name: Update kube config
      run: aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region $AWS_REGION

    - name: Deploy to EKS.
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}        
        IMAGE_TAG: ${{ steps.commit.outputs.short }}
      run: |
        kubectl get pods -A
        kubectl rollout restart deployment mypropertyqr-fmb-refixing-v2 -n mypropertyqr-prod
        kubectl get pods -A
        echo "https://dev-api.sreeragu.com/api/v2/test/dbtestor" AWS EKS development application sucessfully deployed. 
        
