version: '2.1'

volumes:
  osm-postgis-data:
  import_done:
  import_queue:
  cache:
  pgadmin_data:

services:
  db:
    image: kartoza/postgis:${POSTGRES_VERSION}
    hostname: db
    container_name: dockerosm_db
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASS=${POSTGRES_PASS}
      - POSTGRES_DBNAME=${POSTGRES_DBNAME}
      - ALLOW_IP_RANGE=${ALLOW_IP_RANGE}
    volumes:
      - osm-postgis-data:/var/lib/postgresql
    ports:
      - ${DB_PORT}:5432
    healthcheck:
      test: "exit 0"


  imposm:
    image: kartoza/docker-osm:imposm-latest
    build: docker-imposm3
    container_name: dockerosm_imposm
    volumes:
      - ./settings:/home/settings
      - import_done:/home/import_done
      - import_queue:/home/import_queue
      - cache:/home/cache
    depends_on:
      db:
        condition: service_healthy
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASS=${POSTGRES_PASS}
      - POSTGRES_DBNAME=${POSTGRES_DBNAME}
      - POSTGRES_PORT=${POSTGRES_PORT}
      - POSTGRES_HOST=${POSTGRES_HOST}
      - TIME=${TIME}
      - SETTINGS=${SETTINGS}
      - CACHE=${CACHE}
      - IMPORT_DONE=${IMPORT_DONE}
      - IMPORT_QUEUE=${IMPORT_QUEUE}
      - SRID=${SRID}
      - OPTIMIZE=${OPTIMIZE}
      - DBSCHEMA_PRODUCTION=${DBSCHEMA_PRODUCTION}
      - DBSCHEMA_IMPORT=${DBSCHEMA_IMPORT}
      - DBSCHEMA_BACKUP=${DBSCHEMA_BACKUP}
      - QGIS_STYLE=${QGIS_STYLE}
      - CLIP=${CLIP}
    command: bash -c "while [ ! -f /home/settings/country.pbf ] ; do sleep 1; done && python3 -u /home/importer.py"

  osmupdate:
    build: docker-osmupdate
    image: kartoza/docker-osm:osmupdate-latest
    container_name: dockerosm_osmupdate
    volumes_from:
      - imposm
    depends_on:
      db:
        condition: service_healthy
    environment:
      - MAX_DAYS=${MAX_DAYS}
      - DIFF=${DIFF}
      - MAX_MERGE=${MAX_MERGE}
      - COMPRESSION_LEVEL=${COMPRESSION_LEVEL}
      - BASE_URL=${BASE_URL}
      - IMPORT_QUEUE=${IMPORT_QUEUE}
      - IMPORT_DONE=${IMPORT_DONE}
      - TIME=${TIME}

  pgadmin4:
    image: dpage/pgadmin4:latest
    hostname: pgadmin4
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    environment:
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
    ports:
      - ${PGDB_PORT}:80
    restart: on-failure
    depends_on:
      db:
        condition: service_healthy

  osmenrich:
    build: docker-osmenrich
    container_name: dockerosm_osmenrich
    volumes_from:
      - imposm
    depends_on:
      db:
        condition: service_healthy
    environment:
      - IMPORT_QUEUE=${IMPORT_QUEUE}
      - IMPORT_DONE=${IMPORT_DONE}
      - TIME=${TIME}
      - DBSCHEMA_PRODUCTION=${DBSCHEMA_PRODUCTION}
