services:
  postgres:
    image: postgres:16-alpine
    container_name: work-db
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    restart: unless-stopped
    env_file:
      - path: ./.env.example
        required: false
      - path: ./.env
        required: false
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - '${POSTGRES_PORT:-5432}:5432'
    volumes:
      - work-db-data:/var/lib/postgresql/data
    networks:
      - work-backend
    healthcheck:
      test:
        [
          'CMD-SHELL',
          'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB'
        ]
      interval: 10s
      timeout: 5s
      retries: 10

volumes:
  work-db-data:

networks:
  work-backend:
    name: work-backend
