parameters:
  language: ''
  repo_address: $(IOTHUB-E2E-REPO-ADDRESS)
  repo_user: $(IOTHUB-E2E-REPO-USER)
  repo_password: $(IOTHUB-E2E-REPO-PASSWORD)
  image_edgeHub: mcr.microsoft.com/azureiotedge-hub:1.4
  image_edgeAgent: mcr.microsoft.com/azureiotedge-agent:1.4
  image_friendMod: $(IOTHUB-E2E-REPO-ADDRESS)/default-friend-module:$(Architecture)-v2
  image_testMod: ''
  test_image_tag: ''
  deployment_type: ''
  
steps:
- bash: ${HORTON_FRAMEWORKROOT}/scripts/new/install-prereqs.sh
  displayName: 'Install prerequisites'
  condition: and(succeeded(), ne(variables['skipTest'],'yes'), eq(variables['deploymentType'], 'iotedge'))

- bash: |
    docker login -u ${{ parameters.repo_user }} -p ${{ parameters.repo_password }} ${{ parameters.repo_address }} 
    if [ $(which sudo) ]; then 
      sudo docker login -u ${{ parameters.repo_user }} -p ${{ parameters.repo_password }} ${{ parameters.repo_address }} 
    fi
  displayName: 'docker login'
  condition: and(succeeded(), ne(variables['skipTest'],'yes'), eq(variables['usesDocker'], 'yes'))

- bash: 
    ${HORTON_FRAMEWORKROOT}/bin/horton deploy ${{ parameters.deployment_type }} image ${{ parameters.image_testMod }}
  displayName: 'Create new identites and deploy containers (docker)'
  env:
    IOTHUB_E2E_REPO_ADDRESS: $(IOTHUB-E2E-REPO-ADDRESS)
    IOTHUB_E2E_REPO_USER: $(IOTHUB-E2E-REPO-USER)
    IOTHUB_E2E_REPO_PASSWORD: $(IOTHUB-E2E-REPO-PASSWORD)
    IOTHUB_E2E_CONNECTION_STRING: $(IOTHUB-E2E-CONNECTION-STRING)
    IOTEDGE_DEBUG_LOG: $(IOTEDGE_DEBUG_LOG)
  condition: and(succeeded(), ne(variables['skipTest'],'yes'), eq(variables['usesDocker'],'yes'))

- bash: |
    cd ${HORTON_FRAMEWORKROOT}/scripts/new/ &&
    ./wait-for-container.sh edgeHub &&
    ./wait-for-container.sh edgeAgent &&
    ./wait-for-container.sh friendMod 
  displayName: 'wait for iot edge containers'
  condition: and(succeeded(), ne(variables['skipTest'],'yes'), eq(variables['deploymentType'], 'iotedge'))

- bash: |
    cd ${HORTON_FRAMEWORKROOT}/scripts/new/ &&
    ./wait-for-container.sh testMod
  displayName: 'wait for testMod container'
  condition: and(succeeded(), ne(variables['skipTest'],'yes'), eq(variables['usesDocker'],'yes'))

- bash: sleep 30
  displayName: '30 seconds to start up'
  condition: and(succeeded(), ne(variables['skipTest'],'yes'))

- bash: 
    ${HORTON_FRAMEWORKROOT}/bin/horton get_credentials
  displayName: 'Get credentials'
  condition: and(succeeded(), ne(variables['skipTest'],'yes'))

