version: '3'

services:
  ifcbdb:
    image: ${IFCBDB_IMAGE:-whoi/ifcb-dashboard:4.2.1}
    environment:
      - NGINX_HOST=${HOST:-localhost}
      - NGINX_HTTP_PORT=${HTTP_PORT:-80}
      - NGINX_HTTPS_PORT=${HTTPS_PORT:-443}
      - DEFAULT_DATASET=${DEFAULT_DATASET:-}
      - DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY:-changeme}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-ifcb}
    volumes:
      - nginx-static:/static
      - ${PRIMARY_DATA_DIR:-./ifcb_data}:/data
      - ${LOCAL_SETTINGS:-/dev/null}:/ifcbdb/ifcbdb/local_settings.py
    networks:
      - nginx_network
      - postgres_network
      - memcached_network
      - redis_network
    depends_on:
      - postgres
      - memcached
      - redis

  celery:
    image: ${IFCBDB_IMAGE:-whoi/ifcb-dashboard:4.2.1}
    command: celery -A ifcbdb worker -l info
    environment:
      - DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY:-changeme}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-ifcb}
    volumes:
      - ${PRIMARY_DATA_DIR:-./ifcb_data}:/data
      - ${LOCAL_SETTINGS:-/dev/null}:/ifcbdb/ifcbdb/local_settings.py
    depends_on:
      - postgres
      - memcached
      - redis
    networks:
      - redis_network
      - postgres_network
      - memcached_network

  nginx:
    image: ${NGINX_IMAGE:-nginx:1.25}
    environment:
      - NGINX_HOST=${HOST:-localhost}
      - NGINX_HTTP_PORT=${HTTP_PORT:-80}
      - NGINX_HTTPS_PORT=${HTTPS_PORT:-443}
    ports:
      - ${HTTP_PORT:-80}:80
      - ${HTTPS_PORT:-443}:443
    volumes:
      - ${NGINX_TEMPLATE:-./nginx-ssl.conf.template}:/etc/nginx/templates/default.conf.template
      - nginx-static:/static
      - ${SSL_KEY}:/ssl/ssl.key:ro
      - ${SSL_CERT}:/ssl/ssl.cer:ro
    depends_on:
      - ifcbdb
    networks:
      - nginx_network

  postgres:
    image: ${POSTGIS_IMAGE:-postgis/postgis:16-3.4}
    environment:
      - POSTGRES_USER=ifcb
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-ifcb}
      - POSTGRES_DB=ifcb
    volumes:
      - postgis-data:/var/lib/postgresql/data
    networks:
      - postgres_network

  memcached:
    image: ${MEMCACHED_IMAGE:-memcached:1.6}
    command: ["-m", "64m"]
    networks:
      - memcached_network

  redis:
    image: ${REDIS_IMAGE:-redis:7.2}
    networks:
      - redis_network

networks:
  nginx_network:
    driver: bridge
  postgres_network:
    driver: bridge
  memcached_network:
    driver: bridge
  redis_network:
    driver: bridge

volumes:
  postgis-data:
  nginx-static:
