parameters:
  containerRegistry:
  credentials:
  env:

stages:
- stage: build_and_deploy
  jobs:
  - job: build_and_deploy
    timeoutInMinutes: 200
    displayName: 'Publish & Deploy'
    pool:
      vmImage: ubuntu-latest
    steps:
    - task: Docker@2
      displayName: 'Publish'
      inputs:
        containerRegistry: ${{ parameters.containerRegistry }}
        repository: res-${{ parameters.env }}-crm-cdp-dataplatform/loc_stat
        tags: |
          latest
          $(Build.SourceVersion)
        Dockerfile: Dockerfile
    - task: DownloadSecureFile@1
      displayName: 'GCloud Credentials'
      name: credentials
      inputs:
        secureFile: ${{ parameters.credentials }}
    - bash: |
        gcloud auth activate-service-account --key-file=$(credentials.secureFilePath)
        gcloud run deploy res-locstats-${{ parameters.env }}-run01 \
        --project res-${{ parameters.env }}-crm-cdp-dataplatform \
        --region europe-west1 \
        --image eu.gcr.io/res-${{ parameters.env }}-crm-cdp-dataplatform/loc_stat:$(Build.SourceVersion) \
      displayName: 'Deploy'