services:
  postgres:
    image: postgres:16
    container_name: pg_isep_persist
    env_file:
      - .env
    volumes:
      - pg_data:/var/lib/postgresql/data # volume persistant
    ports:
      - "127.0.0.1:${POSTGRES_PORT}:5432" # local uniquement
    networks:
      - isep_net
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
      interval: 10s
      timeout: 5s
      retries: 5

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin_isep_persist
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
    ports:
      - "${PGADMIN_PORT}:80"
    networks:
      - isep_net
    depends_on:
      postgres:
        condition: service_healthy # attend le healthcheck
    restart: unless-stopped

# Volume nomme gere par Docker
volumes:
  pg_data:
    driver: local
  pg_data_restore:
    driver: local

networks:
  isep_net:
    driver: bridge
