services:

  postgres:
    image: postgres:12-alpine
    environment:
      POSTGRES_USER: superx
      POSTGRES_PASSWORD: superx
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  app:
    build: app/
    environment:
      PGDATABASE: superx
      PGUSER: superx
      PGPASSWORD: superx
      PGHOST: postgres
      DB_HOST: postgres
      DB_USER: superx
      DB_PASS: superx
      DB_NAME: superx
      LANG: de_DE.UTF-8
      LC_ALL: de_DE.UTF-8
    volumes:
      - /home/alex/git:/home/superx/git
      - costage_unl:/home/superx/db/module/costage/rohdaten/unl
    ports:
      - "8080:8080"
    depends_on:
      - postgres
    command: >
      bash -c "while !</dev/tcp/postgres/5432; do sleep 1; done;
              source db/bin/SQL_ENV &&
              if [ ! -f /tmp/db_initialized ]; then
                cd db/install/ &&
                echo 'J' | kernmodul_erzeugen.x &&
                cd /home/superx/db/module/costage/ &&
                echo 'J' | module_install.x costage . &&
                touch /tmp/db_initialized;
              fi &&
              cd && webserver/tomcat/bin/catalina.sh run"

volumes:
  postgres_data:
  costage_unl: