Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crorodriguezro/a6afcebcc5a382b5cdc8b678820cc62c to your computer and use it in GitHub Desktop.
Save crorodriguezro/a6afcebcc5a382b5cdc8b678820cc62c to your computer and use it in GitHub Desktop.
Firefly-iii docker on raspberry with backups

Installing firefly on a raspberry with backups

Installing firefly on a raspberry can be done with a LAMP stack, but to have less configuration to worry about, I use docker. This is a bit tricker than 'normal', as raspberry uses the ARM architecture. Luckily, most official images are ready for this. We do need to install docker and docker-compose.

The OS I was running when writing this was Raspbian Stretch Lite (Version:November 2018)

Installing docker and docker-compose

Docker

This is the easy part. Long story short: I'm a trusting fellow and I use the installscript provided by docker:

curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

If you want to be safe, don't run it in one go, but check the contents of that .sh file for tampering.

Docker-compose

There are several options to install compose. You can use pip for instance, but you can also grab it from the source and build it yourself. Which is what I did.

This means getting the source (you do need git installed and I don't remember if that comes out of the box. You might want to do something like apt-get install git).

git clone https://github.com/docker/compose.git
git checkout release

Now we can build for arm and copy the install

docker build -t docker-compose:armhf -f Dockerfile.armhf .
docker run --rm --entrypoint="script/build/linux-entrypoint" -v $(pwd)/dist:/code/dist -v $(pwd)/.git:/code/.git "docker-compose:armhf"
sudo cp dist/docker-compose-Linux-armv7l /usr/local/bin/docker-compose
sudo chown root:root /usr/local/bin/docker-compose
sudo chmod 0755 /usr/local/bin/docker-compose

check if it works:

docker-compose version

Installing firefly

Please also check out the manual

While installing with only the docker-compose file is possible in normal circumstances, we need to build our own image (again, as we are on ARM) instead of using the one from github. So this means checking out the repository, changing the docker-compose file and the docker file, and then building. Don't forget to run the migrations etc (see the manual linked above) to get a working system!

Take some extra inspiration from my recovery script down below if you need.

manual changes

The changes I made to the dockerfiles are mostely for speed. I do not need the new CURL (for bunq) so I uncommented them. See my repository (rapsi branch) for the file.

More important are the changes to the Dockerfile. I've added a service called backup that has all the volumes:

backup:
  image: ubuntu
  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:/var/lib/postgresql/data"

AND I have changed the app key for encryption. So should you. It's this line

FF_APP_KEY=<PUT SOMETHING HERE>

This is also the line that makes you need to backup your compose file, and restore it. You need this key!

Install commands

We need to build the image as it should be made ready for ARM (and also because I have changed the dockerfile). A simple command will do this

docker build -t nh/firefly:latest .

The tag should be the same as the changed line for 'image' in the compose file. You are changing that one or otherwise you will be retreiving your image from the standard location, which does not contain an ARM image. If you get an error later on that your tag cannot be found in the repository, it is probably because this build step didn't work, and so there is no local tagged image (and therefore it tries to retrieve it).

After we have done this, start the contianers:

docker-compose up -d

then wait a bit, as you want the database etc to have started fully. Now we can start to set up the system.

I'm using a slightly different syntax than the manual. If you use this you can use the names of the services in the docker-compose file, rather then the actual names of the containers. I like that better, feels more robust. This does mean that you need to be running your app (docker-compose up) for it to work, but you needed to have run that anyway so there's that.

These are the standard laravel commands you'd run after updating, with the addition of the --seed. ONLY run that the first time! Also, you don't want to run that if you are doing a recovery (see below) as it will copy your database anyway.

docker-compose exec -T firefly_iii_app php artisan migrate --seed
docker-compose exec -T firefly_iii_app php artisan firefly:upgrade-database
docker-compose exec -T firefly_iii_app php artisan firefly:verify
docker-compose exec -T firefly_iii_app php artisan passport:install
docker-compose exec -T firefly_iii_app php artisan cache:clear

While below is not strictly neccessary, this is a "fix all" line for issues that sometimes pop-up. Mostly after updates and stuff, but I'm including it to remember that this is a thing. It might help you with issues

docker-compose exec -T firefly_iii_app chown -R www-data:www-data \
  -R /var/www/firefly-iii/storage/export \
  -R /var/www/firefly-iii/storage/upload \
  -R /var/www/firefly-iii/storage/logs \
  -R /var/www/firefly-iii/storage/framework/cache

Backing up firefly

The firefly docker-compose uses volumes to save the information. This is the official docker way to persist data, but it can be tricky to do backups. At time of writing the method described in the manual is to use a vanilla container (e.g. ubuntu), inlcude the volume(s) you want to backup and also mount a directory from your host. Then you just tar the contents to that mounted dir, and now you have "a backup".

backup script

Check out this gist for the backup script

It does take your firefly install down for a bit, to be able to copy the database files without anyone touching them. You can use postgress commands to make an sql-file of a running system, but this is more straightforward. It copies the composer file so you save your changed file (it has a backup-service added, and you app-key) and the dockerfile. That last part is not strictly neccessary, as that's in the repo as well, but it gives me a warm and fuzzy secure feeling, so....

cron job

I've added 2 cron jobs: one to create the files (using the pi user), and one to sync the backup dir (that's on the raspi-sd card, not the savest place) to my NAS. You can fiddle around with that obviously, you could mount a backup system and do this in one step etc etc.

33 02 * * * pi /home/pi/firefly/bin/backup.sh >> /var/log/cronlog 2>&1
18 04 * * * root rsync -a /home/pi/backups admin@<NAS-IP>:/share/backup/auto_backup/firefly/

For that last line I have added keys for root to my nas so you can actually do this passwordless. Probably not the best idea in a less local/separate environment.

recovery

Check out this gist for the recovery script

It assumes you have an empty directory where you want to install firefly, a backup directory with the 3 tar.gz files for the volumes, and the docker-compose.yml with you app-key and the backup service definition.

It checks out my own repo that has the changed Dockerfile, you can change that if you want.

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