parameters:
  services: ''
  registryEndpoint: ''
  helmfrom: ''
  helmto: ''

jobs:
- job: BuildContainersForPR_Linux
  condition: eq('${{ variables['Build.Reason'] }}', 'PullRequest')
  pool:
    vmImage: 'ubuntu-16.04'
  steps:
  - bash: docker-compose -f src/docker-compose.yml build ${{ parameters.services }}
    displayName: Compose build ${{ parameters.services }}
    env:
      TAG: ${{ variables['Build.SourceBranchName'] }}
- job: BuildContainersForPR_Windows
  condition: False
  # condition: eq('${{ variables['Build.Reason'] }}', 'PullRequest')
  pool:
    vmImage: 'windows-2019'
  steps:
  - bash: docker-compose f src/docker-compose.yml build ${{ parameters.services }}
    displayName: Compose build ${{ parameters.services }}
    env:
      TAG: ${{ variables['Build.SourceBranchName'] }}
      PLATFORM: win
      NODE_IMAGE: stefanscherer/node-windows:10
- job: BuildLinux
  condition: ne('${{ variables['Build.Reason'] }}', 'PullRequest')
  pool:
    vmImage: 'ubuntu-16.04'
  steps:
  - task: DockerCompose@0
    displayName: Compose build ${{ parameters.services }}
    inputs:
      dockerComposeCommand: 'build ${{ parameters.services }}'
      containerregistrytype: Container Registry
      dockerRegistryEndpoint: ${{ parameters.registryEndpoint }}
      dockerComposeFile: src/docker-compose.yml
      qualifyImageNames: true
      projectName: ""
      dockerComposeFileArgs: |
        TAG=${{ variables['Build.SourceBranchName'] }}
  - task: DockerCompose@0
    displayName: Compose push ${{ parameters.images }}
    inputs:
      dockerComposeCommand: 'push ${{ parameters.services }}'
      containerregistrytype: Container Registry
      dockerRegistryEndpoint: ${{ parameters.registryEndpoint }}
      dockerComposeFile: src/docker-compose.yml
      qualifyImageNames: true
      projectName: ""
      dockerComposeFileArgs: |
        TAG=${{ variables['Build.SourceBranchName'] }}
  - task: CopyFiles@2
    inputs:
      sourceFolder: ${{ parameters.helmfrom }}
      targetFolder: ${{ parameters.helmto }}
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: ${{ parameters.helmto }}
      artifactName: helm
- job: BuildWindows
  condition: False
  # condition: ne('${{ variables['Build.Reason'] }}', 'PullRequest')
  pool:
    vmImage: 'windows-2019'
  steps:
  - task: DockerCompose@0
    displayName: Compose build ${{ parameters.services }}
    inputs:
      dockerComposeCommand: 'build ${{ parameters.services }}'
      containerregistrytype: Container Registry
      dockerRegistryEndpoint: ${{ parameters.registryEndpoint }}
      dockerComposeFile: src/docker-compose.yml
      qualifyImageNames: true
      projectName: ""
      dockerComposeFileArgs: |
        TAG=${{ variables['Build.SourceBranchName'] }}
        PLATFORM=win
        NODE_IMAGE=stefanscherer/node-windows:10
  - task: DockerCompose@0
    displayName: Compose push ${{ parameters.services }}
    inputs:
      dockerComposeCommand: 'push ${{ parameters.services }}'
      containerregistrytype: Container Registry
      dockerRegistryEndpoint: ${{ parameters.registryEndpoint }}
      dockerComposeFile: src/docker-compose.yml
      qualifyImageNames: true
      projectName: ""
      dockerComposeFileArgs: |
        TAG=${{ variables['Build.SourceBranchName'] }}
        PLATFORM=win
