version: '3'

services:
  mssql:
    image: microsoft/mssql-server-linux:2017-latest
    ports:
      - '21433:1433'
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=S0meVeryHardPassword
    healthcheck:
      test: /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P 'S0meVeryHardPassword' -Q 'select 1'
  initmssqlknexdb:
    image: microsoft/mssql-server-linux:2017-latest
    links:
      - mssql
    depends_on:
      - mssql
    entrypoint:
      - bash
      - -c
      - 'until /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P S0meVeryHardPassword -d master -Q "CREATE DATABASE knex_test"; do sleep 5; done'

  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - '23306:3306'
    environment:
      - MYSQL_ROOT_PASSWORD=testrootpassword
      - MYSQL_DATABASE=knex_test
      - MYSQL_USER=testuser
      - MYSQL_PASSWORD=testpassword
    healthcheck:
      test:
        [
          'CMD',
          '/usr/bin/mysql',
          '-hlocalhost',
          '-utestuser',
          '-ptestpassword',
          '-e',
          'SELECT 1',
        ]
      interval: 30s
      timeout: 5s
      retries: 3
    restart: always
  waitmysql:
    image: mysql
    links:
      - mysql
    depends_on:
      - mysql
    entrypoint:
      - bash
      - -c
      - 'until /usr/bin/mysql -hmysql -utestuser -ptestpassword -e "SELECT 1"; do sleep 5; done'

  postgres:
    image: postgres:alpine
    ports:
      - '25432:5432'
    environment:
      - POSTGRES_USER=testuser
      - POSTGRES_PASSWORD=knextest
      - POSTGRES_DB=knex_test
  waitpostgres:
    image: postgres:alpine
    links:
      - postgres
    depends_on:
      - postgres
    entrypoint:
      - bash
      - -c
      - 'until /usr/local/bin/psql postgres://testuser:knextest@postgres/knex_test -c "SELECT 1"; do sleep 5; done'

  oracledbxe:
    image: quillbuilduser/oracle-18-xe
    container_name: oracledbxe_container
    ports:
      - '21521:1521'
    environment:
      - ORACLE_ALLOW_REMOTE=true
  waitoracledbxe:
    image: quillbuilduser/oracle-18-xe
    links:
      - oracledbxe
    depends_on:
      - oracledbxe
    environment:
      - ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
    entrypoint:
      - bash
      - -c
      - 'until /opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@oracledbxe/XE as sysdba <<< "SELECT 13376411 FROM DUAL; exit;" | grep "13376411"; do echo "Could not connect to oracle... sleep for a while"; sleep 5; done'
