x-logging: &default-logging
  driver: json-file
  options:
    max-size: "10m"
    max-file: "5"

services:
  db:
    image: postgres:15-alpine
    container_name: devops-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: devopsdb
      POSTGRES_USER: devopsuser
      POSTGRES_PASSWORD: devopspass
    volumes:
      - db-data:/var/lib/postgresql/data
      - ./postgresql:/docker-entrypoint-initdb.d
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U devopsuser -d devopsdb"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - devops-network
    labels:
      - "com.devops.description=PostgreSQL Database"
      - "com.devops.type=database"
    logging: *default-logging

volumes:
  db-data:
    driver: local

networks:
  devops-network:
    external: true   