version: "3.9"

x-shared-env:
  # Django settings
  &shared_env
  - POSTGRES_USER=${POSTGRES_USER}
  - POSTGRES_PASS=${POSTGRES_PASS}
  - POSTGRES_DBNAME=${POSTGRES_DBNAME}
  - DATABASE=#{DATABASE}
  - PG_HOST=${PG_HOST}
  - PG_PORT=${PG_PORT}
  - GS_VERSION=${GS_VERSION}
  - GEOSERVER_PORT=${GEOSERVER_PORT}
  - GEOSERVER_DATA_DIR=${GEOSERVER_DATA_DIR}
  - GEOWEBCACHE_CACHE_DIR=${GEOWEBCACHE_CACHE_DIR}
  - GEOSERVER_ADMIN_PASSWORD=${GEOSERVER_ADMIN_PASSWORD}
  - GEOSERVER_ADMIN_USER=${GEOSERVER_ADMIN_USER}
  - INITIAL_MEMORY=${INITIAL_MEMORY}
  - MAXIMUM_MEMORY=${MAXIMUM_MEMORY}
  - SECRET_KEY=${SECRET_KEY}
  - DEBUG=${DEBUG}
  - ALLOWED_HOSTS=${ALLOWED_HOSTS}
  - S3_REGION=${S3_REGION}
  - S3_BUCKET_NAME=${S3_BUCKET_NAME}
  - S3_PREFIX=#{S3_PREFIX}
  - AWS_ACCESS_KEY=${AWS_ACCESS_KEY}
  - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
  - AWS_REGION=${AWS_REGION}


services:
   postgres-db:
      image: kartoza/postgis:12.0
      ports:
         - 5432:5432
      volumes:
         - postgres_data:/var/lib/postgresql
         - ./custom-postgresql.conf:/etc/postgresql/12/main/postgresql.conf
         - ./rogaining.sql:/sql/rogaining.sql
      environment: *shared_env 
      restart: "on-failure"
      networks:
         - rog-api

   app:
      build:
         context: .
         dockerfile: Dockerfile.gdal
      command: gunicorn config.wsgi:application --bind 0.0.0.0:8000
      volumes:
         - .:/app
         - static_volume:/app/static
         - media_volume:/app/media 
      environment: *shared_env 
      restart: "on-failure"
      depends_on:
         - postgres-db
      networks:
         - rog-api

   nginx:
      image: nginx:1.19
      volumes:
         - ./nginx.conf:/etc/nginx/nginx.conf
         - static_volume:/app/static
         - media_volume:/app/media 
      ports:
        - 8100:80
      environment: *shared_env 
      depends_on:
         - app
      networks:
         - rog-api

networks:
   rog-api:
      driver: bridge

volumes:
   postgres_data:
   static_volume:
   media_volume:
