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

version: '3.7'

networks:
  internal:
    external: false

services:
  firefly:
    container_name: firefly
    image: fireflyiii/core:latest
    ports:
      - 6182:8080
    volumes:
      - /volume1/docker/fireflyup:/var/www/html/storage/upload
    restart: unless-stopped
    env_file:
      - stack.env
    depends_on:
      - firefly-db
    networks:
      - internal

  firefly-db:
    container_name: firefly-db
    image: postgres
    volumes:
      - /volume1/docker/fireflydb:/var/lib/postgresql/data
    restart: unless-stopped
    environment:
      POSTGRES_DB: firefly
      POSTGRES_USER: firefly
      POSTGRES_PASSWORD: "REDACTED_PASSWORD"  # pragma: allowlist secret
    networks:
      - internal

  firefly-db-backup:
    container_name: firefly-db-backup
    image: postgres
    volumes:
      - /volume1/docker/fireflydb:/dump
      - /etc/localtime:/etc/localtime:ro
    environment:
      PGHOST: firefly-db
      PGDATABASE: firefly
      PGUSER: firefly
      PGPASSWORD: "REDACTED_PASSWORD"  # pragma: allowlist secret
      BACKUP_NUM_KEEP: 10
      BACKUP_FREQUENCY: 7d
    entrypoint: |
      bash -c 'bash -s < /dump/dump_\`date +%d-%m-%Y"_"%H_%M_%S\`.psql
        (ls -t /dump/dump*.psql|head -n $$BACKUP_NUM_KEEP;ls /dump/dump*.psql)|sort|uniq -u|xargs rm -- {}
        sleep $$BACKUP_FREQUENCY
      done
      EOF'
    networks:
      - internal

  firefly-redis:
    container_name: firefly-redis
    image: redis
    networks:
      - internal
