version: '3.1'

services:
  web:
    image: fraunhoferiosb/frost-server:latest
    environment:
      - serviceRootUrl=http://localhost:8080/FROST-Server
      - http_cors_enable=true
      - http_cors_allowed.origins=*
      - mqtt.WebsocketPort=9876
      - persistence_db_driver=org.postgresql.Driver
      - persistence_db_url=jdbc:postgresql://database:5432/sensorThing
      - persistence_db_username=sensorThing
      - persistence_db_password=sensorThing
      - persistence_autoUpdateDatabase=true
      - plugins.openApi.enable=true
      - persistence.idGenerationMode=ServerAndClientGenerated
      - persistence.persistenceManagerImplementationClass=de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.imp.PostgresPersistenceManagerString
    ports:
      - 8080:8080
      - 1883:1883
      - 9876:9876
    depends_on:
      - database_setup

  database:
    image: postgis/postgis:11-2.5-alpine
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=sensorThing
      - POSTGRES_USER=sensorThing
      - POSTGRES_PASSWORD=sensorThing
    volumes:
      - postgis_volume:/var/lib/postgresql/data

  database_setup:
    image: postgis/postgis:11-2.5-alpine
    environment:
      - PGPASSWORD=sensorThing
    command:
      - /bin/bash
      - -c
      - |
        sleep 5
        echo 'CREATE EXTENSION "uuid-ossp";' | psql -h database -p 5432 -U sensorThing
    links:
      - database

volumes:
  postgis_volume:
