version: '3.9'

services:

  db:
    image: postgres:15
    container_name: fiscad-db
    restart: always
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - "5432:5432"
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: fiscad-app
    depends_on:
      - db
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/${POSTGRES_DB}
      SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER}
      SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
      SERVER_PORT: 8282
      IO_GMSS_FISCAD_PROFILE: abomey
      SPRING_PROFILES_ACTIVE: abomey
    ports:
      - "8282:8282"
    volumes:
      - ./uploads:/app/uploads
      - ./jasperReport:/app/jasperReport
    restart: on-failure

volumes:
  db-data: