FraunhoferIOSB / FROST-Server

A Complete Server implementation of the OGC SensorThings API
https://fraunhoferiosb.github.io/FROST-Server/
GNU Lesser General Public License v3.0
199 stars 74 forks source link

override setting: persistence_db_url #65

Closed image357 closed 6 years ago

image357 commented 6 years ago

Hey,

I just tried if I can override the settings of persistence_db_url=jdbc:postgresql://database:5432/sensorthings via environment variables in my docker-compose file.

In my context.xml I have url="jdbc:postgresql://localhost:5432/sensorthings" for debugging and coding on my local machine. However, for the containers I want to reference the postgres/postgis container (database).

Can I do that with the first line in my docker-compose file? Is it supposed to override the settings in context.xml? Currently it does not override it, I think.

My docker-compose.yml:

version: '2'

services:
  web:
    build:
        context: .
        dockerfile: Dockerfile
        args:
            GITHASH: ce95c9f22a4b5c238743558ef470692db9de5363
    environment:
        - serviceRootUrl=http://smartaqnet.teco.edu:8080/FROST-Server
        - persistence_persistenceManagerImplementationClass=de.fraunhofer.iosb.ilt.sta.persistence.postgres.stringid.PostgresPersistenceManagerString
        - persistence_idGenerationMode=ServerAndClientGenerated
        - persistence_db_driver=org.postgresql.Driver
        - persistence_db_url=jdbc:postgresql://database:5432/sensorthings
        - persistence_db_username=sensorthings
        - persistence_db_password=ChangeMe
    ports:
      - 8080:8080
      - 1883:1883
    depends_on:
      - database

  database:
    image: mdillon/postgis:latest
    environment:
      - POSTGRES_DB=sensorthings
      - POSTGRES_USER=sensorthings
      - POSTGRES_PASSWORD=ChangeMe
    ports:
        - 5432:5432
    volumes:
      - postgis_volume:/var/lib/postgresql/data

volumes:
    postgis_volume:

On the database init page i get Failed to initialise database: Cannot create PoolableConnectionFactory (Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)

Which is also strange because, I have the container port 5432 wired to localhost 5432 and it accepts TCP connections on it (tested via "nc -z localhost 5432").

Cheers, Marcel Köpke

hylkevds commented 6 years ago

You have to add an empty persistence_db_jndi_datasource environment variable. The reason is that the WebApp has to choose which of the two database connections to use, the Tomcat provided datasource, or a self-connected database connection. Since the persistence_db_jndi_datasource variable is always set from the context.xml, it will automatically choose that, unless you explicitly override the value of that variable, by setting it to empty.

I've recently updated the example docker-compose files with this empty variable.

image357 commented 6 years ago

Ah yes, now it works. I wasn't quite sure what this empty variable did. Thanks for the explanation!