parameters:
  image: ''
  branch: ''
  registry: 'eshop'
  registryEndpoint: ''

jobs:
- job: manifest
  condition: and(succeeded(),ne('${{ variables['Build.Reason'] }}', 'PullRequest'))
  dependsOn:
    # - BuildWindows
    - BuildLinux  
  pool: 
    vmImage: 'Ubuntu 16.04'
  steps:
  - task: Docker@1
    displayName: Docker Login
    inputs:
      command: login
      containerregistrytype: 'Container Registry'
      dockerRegistryEndpoint: ${{ parameters.registryEndpoint }}
      # Disabled windows deploy
      # docker --config ~/.docker manifest create ${{ parameters.registry }}/${{ parameters.image }}:${{ parameters.branch }} ${{ parameters.registry }}/${{ parameters.image }}:linux-${{ parameters.branch }} ${{ parameters.registry }}/${{ parameters.image }}:win-${{ parameters.branch }}
      # docker --config ~/.docker manifest create ${{ parameters.registry }}/${{ parameters.image }}:latest ${{ parameters.registry }}/${{ parameters.image }}:linux-latest ${{ parameters.registry }}/${{ parameters.image }}:win-latest
  - bash: |
      mkdir -p ~/.docker
      sed '$ s/.$//' $DOCKER_CONFIG/config.json > ~/.docker/config.json
      echo ',"experimental": "enabled" }' >> ~/.docker/config.json
      docker --config ~/.docker manifest create ${{ parameters.registry }}/${{ parameters.image }}:${{ parameters.branch }} ${{ parameters.registry }}/${{ parameters.image }}:linux-${{ parameters.branch }}
      docker --config ~/.docker manifest create ${{ parameters.registry }}/${{ parameters.image }}:latest ${{ parameters.registry }}/${{ parameters.image }}:linux-latest
      docker --config ~/.docker manifest push ${{ parameters.registry }}/${{ parameters.image }}:${{ parameters.branch }}
      docker --config ~/.docker manifest push ${{ parameters.registry }}/${{ parameters.image }}:latest
    displayName: Create multiarch manifest
