services:
  db:
    image: postgres:13
    container_name: postgres
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - app-network
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}

  backend:
    build:
      context: .
      dockerfile: Dockerfile
    image: backend
    container_name: backend
      #command:  python -m venv myenv && \
      #        source myenv/bin/activate && \
      #        pip3 install -r requirements.txt && \
      #tail -f /dev/null

      #command: sh -c "python3 manage.py migrate --noinput && \
      #              python3 manage.py collectstatic --noinput && \
      #              python manage.py runserver 0.0.0.0:8000"

    restart: always
    volumes:
        - .:/ft_transcendence
    ports:
      - "8000:8000"
    depends_on:
      - db
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8000 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - app-network
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      DB_HOST: ${DB_HOST}
      DB_PORT: ${DB_PORT}

volumes:
  postgres_data:
    driver: local
    driver_opts:
      type: none
      device: /home/motoko/data/ft_transcendence/db
      o: bind

networks:
  app-network:
    driver: bridge
