parameters:
  jdk: 1.8
  extra:

steps:
- task: CacheBeta@0 #we know the very first job will have restored or created this, so this will never write built artifacts to the cache
  inputs:
    key: maven | bom/runtime/pom.xml
    path: $(Pipeline.Workspace)/.m2/repository/
    securityNamespace: cache
  displayName: Restore Maven Cache

- script: docker rm -f $(docker ps -qa) || true
  displayName: 'Docker Cleanup'

- 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'

- script: docker run --rm --publish 8000:8000 --name build-dynamodb -d amazon/dynamodb-local:1.11.477
  displayName: 'start dynamodb'

- script: docker run --rm --publish 7687:7687 --name build-neo4j -e NEO4J_AUTH=neo4j/secret -e NEO4J_dbms_memory_pagecache_size=10M -e NEO4J_dbms_memory_heap_initial__size=10M -d neo4j/neo4j-experimental:4.0.0-rc01
  displayName: 'start neo4j'

- bash: |
    sudo service mysql stop || true
    docker run --rm --publish 3306:3306 --name build-mysql -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_DATABASE=hibernate_orm_test -d mysql:5 --skip-ssl 
  displayName: 'start mysql'

- script: docker run --rm --publish 3308:3306 --name build-mariadb  -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_RANDOM_ROOT_PASSWORD=true -d mariadb:10.4
  displayName: 'start mariadb'

- script: docker run --rm --publish 8180:8080 --name build-keycloak  -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e JAVA_OPTS="-server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Dkeycloak.profile.feature.upload_scripts=enabled" -d quay.io/keycloak/keycloak:9.0.0
  displayName: 'start keycloak'

- script: docker run --rm --publish 1433:1433 --name build-mssql -e ACCEPT_EULA=Y -e SA_PASSWORD=ActuallyRequired11Complexity -d microsoft/mssql-server-linux:2017-CU12
  displayName: 'start microsoft sql server'

- task: Maven@3
  displayName: 'Maven Build'
  inputs:
    goals: 'install'
    mavenOptions: $(MAVEN_OPTS)
    jdkVersionOption: ${{ parameters.jdk }}
    options: '-e -B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-mysql -Dtest-dynamodb -Dtest-vault -Dtest-neo4j -Dtest-keycloak -Dtest-mssql -Dtest-mariadb -Dmariadb.url="jdbc:mariadb://localhost:3308/hibernate_orm_test" -Dno-format ${{ parameters.extra }}'

