# This version must match the MAKE_DC_VERSION value below
version: "2.3"

volumes:
  pgdata:

networks:
  postgres_conn:
    driver: bridge

services:

  postgres:
    image: "${POSTGIS_IMAGE:-openmaptiles/postgis}:${TOOLS_VERSION}"
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - postgres_conn
    ports:
      - "5432"
    env_file: .env

  import-data:
    image: "openmaptiles/import-data:${TOOLS_VERSION}"
    env_file: .env
    networks:
      - postgres_conn

  import-osm:
    image: "openmaptiles/import-osm:${TOOLS_VERSION}"
    env_file: .env
    environment:
      DIFF_MODE: ${DIFF_MODE}
    networks:
      - postgres_conn
    volumes:
      - ./data:/import
      - ./build:/mapping
      - ./cache:/cache

  import-osm-diff:
    image: "openmaptiles/import-osm:${TOOLS_VERSION}"
    env_file: .env
    command: ./import_diff.sh
    environment:
      DIFF_MODE: ${DIFF_MODE}
    networks:
      - postgres_conn
    volumes:
      - ./data:/import
      - ./build:/mapping
      - ./cache:/cache

  update-osm:
    image: "openmaptiles/import-osm:${TOOLS_VERSION}"
    env_file: .env
    environment:
      DIFF_MODE: ${DIFF_MODE}
    command: ./import_update.sh
    networks:
      - postgres_conn
    volumes:
      - ./data:/import
      - ./build:/mapping
      - ./cache:/cache

  openmaptiles-tools:
    image: "openmaptiles/openmaptiles-tools:${TOOLS_VERSION}"
    env_file: .env
    environment:
      # Must match the version of this file (first line)
      # download-osm will use it when generating a composer file
      MAKE_DC_VERSION: "2.3"
      # Allow DIFF_MODE to be overwritten from shell
      DIFF_MODE: ${DIFF_MODE}
    networks:
      - postgres_conn
    volumes:
      - .:/tileset
      - ./data:/import
      - ./build:/sql
      - ./build:/mapping
      - ./cache:/cache

  generate-changed-vectortiles:
    image: "openmaptiles/generate-vectortiles:${TOOLS_VERSION}"
    command: ./export-list.sh
    volumes:
      - ./data:/export
      - ./build/openmaptiles.tm2source:/tm2source
    networks:
      - postgres_conn
    env_file: .env

  generate-vectortiles:
    image: "openmaptiles/generate-vectortiles:${TOOLS_VERSION}"
    volumes:
      - ./data:/export
      - ./build/openmaptiles.tm2source:/tm2source
    networks:
      - postgres_conn
    env_file: .env
    environment:
      BBOX: ${BBOX}
      MIN_ZOOM: ${MIN_ZOOM}
      MAX_ZOOM: ${MAX_ZOOM}

  postserve:
    image: "openmaptiles/openmaptiles-tools:${TOOLS_VERSION}"
    command: postserve openmaptiles.yaml --verbose
    env_file: .env
    networks:
      - postgres_conn
    ports:
      - "8090:8090"
    volumes:
      - .:/tileset
