Skip to content

Instantly share code, notes, and snippets.

@cgcostume
Last active February 17, 2024 16:26
Show Gist options
  • Save cgcostume/4c4c337272b16fa0451ff8d145e167bc to your computer and use it in GitHub Desktop.
Save cgcostume/4c4c337272b16fa0451ff8d145e167bc to your computer and use it in GitHub Desktop.
Configuration of a firefly-iii server using docker and docker-compose on a Raspberry Pi 4

Firefly III on Raspberry Pi 4

Preparations

The following steps describe the prerequisites for the actual firefly setup:

  1. Flash (e.g., using Etcher) raspbian-buster-lite onto SD card (e.g., 16GB).

  2. Create an empty ssh file on the SD card's boot partition.

  3. Create a wpa_supplicant.conf file (see template provided with this gist) on the SD card's boot partition (link).

  4. Eject SD card properly and start raspi with it (just provide power).

  5. Use a shell/terminal and connect to the raspi with ssh pi@rasperrypi (username pi, hostname raspberrypi, and default password is raspberry).

If your raspi is not found, check (1) whether your WPA config was correct (note that the file gets deleted whenever the raspi boots), (2) that your router allowed your raspi to enter your WAN/LAN, and (3) that you remove your raspi from previous known hosts (.ssh/known_hosts).

Raspberry Setup

  1. Update the raspi:

    1. sudo apt-get -y update && sudo apt-get -y full-upgrade
  2. Change pi user password:

    1. sudo raspi-config
  3. Install Docker:

    1. curl -sSL https://get.docker.com | sh
    2. sudo usermod -aG docker pi
    3. optional: test docker docker run hello-world
  4. Install docker-compose:

    1. sudo apt-get -y install libffi-dev libssl-dev
    2. sudo apt-get -y install python python-pip
    3. sudo apt-get -y remove python-configparser (some fix I had to apply for correct pip-based install)
    4. sudo pip install docker-compose
  5. Configure raspi:

    1. sudo raspi-config
    2. Set hostname to, e.g., firefly (needs to be consistent with all upcomming hostnames). Note that for subsequent ssh connects the new hostname needs to be used: e.g., ssh pi@firefly ...
    3. optional: set timezone, WiFi locale, expand filesystem etc. and reboot sudo reboot.
  6. Create folder structure for firefly and nginx config:

    1. cd /opt/
    2. sudo mkdir docker
    3. cd docker/
    4. sudo mkdir conf.d
    5. cd conf.d/
  7. Create nginx config:

    1. sudo openssl req -x509 -newkey rsa:2048 -keyout firefly.key -out firefly.crt -days 365 -nodes (the hostname needs to be set accordingly, all other settings are optional/can be defaulted)
    2. sudo nano firefly.conf (and paste firefly.conf contents, the proxy_pass needs to be adjusted later)
    3. check: ls should output firefly.conf firefly.crt firefly.key ...
  8. Create firefly config:

    1. cd /opt/docker/
    2. sudo nano firefly.yml (see template provided with this gist and adjust POSTGRES_PASSWORD)
    3. sudo nano firefly.env (see template) and adjust as follows:
...
TZ=<your preferred time zone>
...
APP_URL=https://firefly
...
TRUSTED_PROXIES=**
...
DB_PASSWORD=<pw set for postgres earlier>
...
  1. optional: Make a backup of your SD card.

  2. start docker in order to get proxy_pass for firefly.conf:

    1. docker-compose -f firefly.yml up -d (start firefly)
    2. docker network inspect docker_firefly_iii_net (read out the gateway address, mine is "172.18.0.1")
    3. docker-compose -f firefly.yml stop (stop firefly)
    4. sudo nano conf.d/firefly.conf (adjust the proxy_pass)

Start / Stop Firefly

  1. start: docker-compose -f firefly.yml up -d
  2. stop: docker-compose -f firefly.yml stop
  3. recreate: docker-compose -f firefly.yml up -d --force-recreate
  4. show log while running:
    1. docker container ls -f name=firefly_iii_app (copy CONTAINER ID)
    2. docker container logs -f <containerID>
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/nginx/conf.d/firefly.crt;
ssl_certificate_key /etc/nginx/conf.d/firefly.key;
location / {
proxy_pass http://172.0.0.1:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
---
networks:
firefly_iii_net:
driver: bridge
services:
firefly_iii_app:
image: jc5x/firefly-iii:latest
restart: unless-stopped
depends_on:
- firefly_iii_db
networks:
- firefly_iii_net
ports:
- "80:80"
env_file: firefly.env
volumes:
-
source: firefly_iii_export
target: /var/www/firefly-iii/storage/export
type: volume
-
source: firefly_iii_upload
target: /var/www/firefly-iii/storage/upload
type: volume
firefly_iii_db:
image: "postgres:latest"
restart: unless-stopped
environment:
- POSTGRES_PASSWORD=<Some randomly generated password>
- POSTGRES_USER=firefly
networks:
- firefly_iii_net
volumes:
- firefly_iii_db:/var/lib/postgresql/data
nginx_proxy:
image: nginx:latest
restart: unless-stopped
networks:
- firefly_iii_net
ports:
- "443:443"
volumes:
- /opt/docker/conf.d:/etc/nginx/conf.d:ro
version: "3.2"
volumes:
firefly_iii_db: ~
firefly_iii_export: ~
firefly_iii_upload: ~
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert country code here>
network={
ssid="<Name of your WiFi>"
psk="<Password for your WiFi>"
}
@ricexen
Copy link

ricexen commented Oct 20, 2020

I am getting an 502 :c on https://firefly

@paulmathijs
Copy link

paulmathijs commented Dec 22, 2021

I am also getting an 502 Bad Gateway error message.

@mrtargaryen
Copy link

I am also getting an 502 Bad Gateway error message.

@mrtargaryen
Copy link

I am also getting an 502 Bad Gateway error message.

Did you resolve this issue, I got the same result, however, I edited the firefly.yml and used fireflyiii/core rather than jc5x/firefly-iii

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment