# Firefly III - Finance manager
# Port: 8080
# Personal finance manager

services:
  redis:
    image: redis
    container_name: Firefly-REDIS
    hostname: firefly-redis
    mem_limit: 256m
    mem_reservation: 50m
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    read_only: true
    user: 1026:100
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping || exit 1"]
    volumes:
      - /volume1/docker/firefly/redis:/data:rw
    environment:
      TZ: America/Los_Angeles
    restart: on-failure:5

  importer:
    image: fireflyiii/data-importer:latest
    container_name: Firefly-Importer
    hostname: firefly-importer
    security_opt:
      - no-new-privileges:false
    volumes:
      - /volume1/docker/firefly/importer:/var/www/html/storage/upload:rw
    ports:
      - 6192:8080
    restart: on-failure:5
    depends_on:
      firefly:
        condition: service_healthy

  db:
    image: mariadb:11.4-noble #LTS Long Time Support Until May 29, 2029.
    container_name: Firefly-DB
    hostname: firefly-db
    mem_limit: 512m
    mem_reservation: 128m
    cpu_shares: 768
    security_opt:
      - no-new-privileges:false
    volumes:
      - /volume1/docker/firefly/db:/var/lib/mysql:rw
    environment:
      TZ: America/Los_Angeles
      MYSQL_ROOT_PASSWORD: "REDACTED_PASSWORD"
      MYSQL_DATABASE: firefly
      MYSQL_USER: fireflyuser
      MYSQL_PASSWORD: "REDACTED_PASSWORD"
    restart: on-failure:5

  firefly:
    image: fireflyiii/core:latest
    container_name: Firefly
    hostname: firefly
    mem_limit: 1g
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    healthcheck:
      test: curl -f http://localhost:8080/ || exit 1
    env_file:
      - stack.env
    volumes:
      - /volume1/docker/firefly/upload:/var/www/html/storage/upload:rw
    ports:
      - 6182:8080
    restart: on-failure:5
    depends_on:
      db:
        condition: service_started
      redis:
        condition: service_healthy

  cron:
    image: alpine:latest
    command: sh -c "echo \"0 3 * * * wget -qO- http://firefly:8080/api/v1/cron/9610001d2871a8622ea5bf5e65fe25db\" | crontab - && crond -f -L /dev/stdout"
    container_name: Firefly-Cron
    hostname: firefly-cron
    mem_limit: 64m
    cpu_shares: 256
    security_opt:
      - no-new-privileges:true
    environment:
      TZ: America/Los_Angeles
    restart: on-failure:5
    depends_on:
      firefly:
        condition: service_started
