version: "3.8"
services:
  db:
    image: postgis/postgis:latest
    volumes:
      - postgres_data:/var/lib/postgresql/data
    env_file: .env

    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      - ENGINE=django.contrib.gis.db.backends.postgis
      - POSTGRES_DB=${DB_NAME}
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - PGDATA=/var/lib/postgresql/data/pgdata
  db-migration:
    container_name: db_migration
    build:
      context: . 
      dockerfile: ./docker/Dockerfile
    command: >
      bash -c "python src/manage.py migrate --noinput  && python src/manage.py collectstatic --noinput"


    depends_on:
      db:
        condition: service_healthy

    env_file:
      - .env
  web:
    build:
      context: .
      dockerfile: ./docker/Dockerfile

    command: gunicorn --chdir src future_academie.wsgi --bind 0.0.0.0:8005
    volumes:
      - .:/code
    env_file: .env
    ports:
      - "8005:8005"
    environment:
      - DEBUG=${DEBUG}
      - SECRET_KEY=${SECRET_KEY}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASS=${DB_PASSWORD}
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT}
    depends_on:
      db:
        condition: service_healthy

volumes:
  postgres_data:
