parameters:
  modules: []
  name: ''
  postgres: false
  dynamodb: false
  keycloak: false
  mysql: false
  timeoutInMinutes: 80


jobs:
  - job: ${{ parameters.name }}
    displayName: ${{ join(', ', parameters.modules) }}
    timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
    pool:
      vmImage: 'Ubuntu 16.04'
    variables:
      imageName: 'quarkus:$(build.buildId)'
    steps:
    - task: DownloadPipelineArtifact@2
      inputs:
        artifact: BuiltMavenRepo
        path: $(Pipeline.Workspace)/.m2/repository/

    - ${{ if eq(parameters.postgres, 'true') }}:
      - script: docker run --rm --publish 5432:5432 --name build-postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -d postgres:10.5
        displayName: 'start postgres'
    - ${{ if eq(parameters.dynamodb, 'true') }}:
      - script: docker run --rm --publish 8000:8000 --name build-dynamodb -d amazon/dynamodb-local:1.11.477
        displayName: 'start dynamodb'
    - ${{ if eq(parameters.keycloak, 'true') }}:
        - script: docker run --rm --publish 8180:8080 --name build-keycloak  -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -d quay.io/keycloak/keycloak
          displayName: 'start keycloak'
    - ${{ if eq(parameters.mysql, 'true') }}:
        - bash: |
            sudo apt-get update &&
            sudo apt-get -y install mysql-server libmysqlclient-dev &&
            mysql -e "create user 'hibernate_orm_test'@'localhost' identified by 'hibernate_orm_test';" -uroot -proot &&
            mysql -e "create database hibernate_orm_test; grant all on hibernate_orm_test.* to 'hibernate_orm_test'@'localhost';" -uroot -proot
          displayName: 'install mysql'

    - task: Maven@3
      displayName: 'Maven Build'
      inputs:
        goals: 'install'
        mavenOptions: $(MAVEN_OPTS)
        options: '-pl integration-tests/${{ join('',integration-tests/'', parameters.modules) }} -B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-keycloak -Ddocker-keycloak -Dtest-dynamodb -Dtest-mysql -Dnative-image.xmx=6g -Dnative -Dno-format'
