version: '3.9'
services:
  app:
    image: app:latest
    build:
        context: allocine-exemple-webb-app
        dockerfile: allocine-exemple-webb-app/Dockerfile
    depends_on:
      database:
        condition: service_healthy
    environment:
      POSTGRES_USER: ${DB_USERNAME:-root}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-toor}
      POSTGRES_DB: ${DB_NAME:-defaultdb}
    networks:
      - db
    restart: unless-stopped
    ports:
      - "8080:8080"

  database:
    container_name: api_database
    image: postgres:15.2-alpine
    restart: always
    networks:
      - db
    environment:
      POSTGRES_USER : ${DB_USERNAME:-root}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-toor}
      POSTGRES_DB: ${DB_NAME:-defaultdb}
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "sh -c 'pg_isready -U ${DB_USERNAME:-root} -d ${DB_NAME:-defaultdb}'",
        ]
      interval: 10s
      timeout: 3s
      retries: 3

networks:
  db:
volumes:
  db-data:
