version: "3.8"

services:
  firefly-iii:
    image: fireflyiii/core:version-6.6.3
    restart: unless-stopped
    depends_on:
      firefly-iii-db:
        condition: service_healthy
    environment:
      APP_KEY: ${APP_KEY}
      APP_URL: ${APP_URL}
      TRUSTED_PROXIES: "**"
      TZ: ${TZ}
      SITE_OWNER: ${SITE_OWNER}
      DEFAULT_LANGUAGE: ${DEFAULT_LANGUAGE}
      DEFAULT_LOCALE: ${DEFAULT_LOCALE}
      DB_CONNECTION: mysql
      DB_HOST: firefly-iii-db
      DB_PORT: 3306
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      STATIC_CRON_TOKEN: ${STATIC_CRON_TOKEN}
    expose:
      - "8080"
    volumes:
      - firefly-iii-upload:/var/www/html/storage/upload

  firefly-iii-db:
    image: mariadb:11.8
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
    volumes:
      - firefly-iii-db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5

  firefly-iii-cron:
    image: alpine:3.22
    restart: unless-stopped
    depends_on:
      - firefly-iii
    environment:
      TZ: ${TZ}
      STATIC_CRON_TOKEN: ${STATIC_CRON_TOKEN}
    command:
      - sh
      - -c
      - |
        apk add --no-cache tzdata wget && \
        (ln -snf /usr/share/zoneinfo/$$TZ /etc/localtime || true) && \
        echo "0 3 * * * wget -qO- http://firefly-iii:8080/api/v1/cron/$$STATIC_CRON_TOKEN; echo" | crontab - && \
        crond -f -L /dev/stdout

volumes:
  firefly-iii-upload: {}
  firefly-iii-db: {}
