# documentation: https://www.kimai.org/
# slogan: Open source time-tracking app.
# category: productivity
# tags: time-tracking, open-source
# logo: svgs/kimai.svg
# port: 8001

services:
  mysql:
    image: mysql:8
    volumes:
      - kimai-mysql-data:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=${MYSQL_DATABASE:-kimai}
      - MYSQL_USER=${SERVICE_USER_MYSQL}
      - MYSQL_PASSWORD=${SERVICE_PASSWORD_MYSQL}
      - MYSQL_ROOT_PASSWORD=${SERVICE_PASSWORD_ROOT}
    command: --default-storage-engine innodb
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
      interval: 5s
      timeout: 20s
      retries: 10
  kimai:
    image: kimai/kimai2:apache
    container_name: kimai
    depends_on:
      mysql:
        condition: service_healthy
    volumes:
      - kimai-data:/opt/kimai/var/data
    environment:
      - SERVICE_URL_KIMAI_8001
      - APP_SECRET=${SERVICE_PASSWORD_APPSECRET}
      - MAILER_FROM=${MAILER_FROM:-kimai@example.com}
      - MAILER_URL=${MAILER_URL:-null://null}
      - ADMINMAIL=${ADMINMAIL:-admin@kimai.local}
      - ADMINPASS=${SERVICE_PASSWORD_ADMINPASS}
      - DATABASE_URL=mysql://${SERVICE_USER_MYSQL}:${SERVICE_PASSWORD_MYSQL}@mysql/${MYSQL_DATABASE}?charset=utf8mb4&serverVersion=8.3.0
      - 'TRUSTED_HOSTS=${TRUSTED_HOSTS}|localhost|127.0.0.1'
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8001"]
      interval: 2s
      timeout: 10s
      retries: 15
