name: Dev-fmb-refixing-v2
# DEVELOPMENT Build and Push Docker Image to ECR...

on:
 push:
   branches:
     - mypropertyqr-dev

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

jobs:
  
  build:
    
    name: Dev-fmb-refixing-v2
    runs-on: ubuntu-latest

    steps:

    - name: Set short git commit SHA
      id: commit
      uses: prompt/actions-commit-hash@v2

    - name: Check out code
      uses: actions/checkout@v2
    
    - 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: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    - name: Log in to AWS ECR
      run: |
         aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.DEVELOPMENT_ECR_REPOSITORY }}

    - name: Build Docker image
      run: |
         docker compose --env-file .env_docker -p "fmb-refixing-v2" build
 
    - name: list Docker image
      run: |
         docker image ls

    - name: Tag Docker image
      run: |
         docker tag fmb-refixing-v2-goapp:latest 048245609775.dkr.ecr.ap-south-1.amazonaws.com/fmb-refixing-v2-goapp-dev:latest
         docker tag fmb-refixing-v2-pymodule:latest 048245609775.dkr.ecr.ap-south-1.amazonaws.com/fmb-refixing-v2-pymodule-dev:latest
         docker tag fmb-refixing-v2-ocr:latest 048245609775.dkr.ecr.ap-south-1.amazonaws.com/fmb-refixing-v2-ocr-dev:latest
         
    - name: Push Docker image to AWS ECR
      run: |
         docker push 048245609775.dkr.ecr.ap-south-1.amazonaws.com/fmb-refixing-v2-goapp-dev:latest
         docker push 048245609775.dkr.ecr.ap-south-1.amazonaws.com/fmb-refixing-v2-pymodule-dev:latest
         docker push 048245609775.dkr.ecr.ap-south-1.amazonaws.com/fmb-refixing-v2-ocr-dev:latest
    
