From d09338b2e5535d32d42148c64481ec6ec2fdf6de Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Thu, 23 Sep 2021 11:04:11 +0200 Subject: [PATCH] Feat/fireflyiii (#344) * Adding Firefly-iii opt fragment * Adding environment variable to force creation of db * Instructing postgres to create database * Switching exposing default port, running create db command * Remove grep command for postgres container * Removing database creation on postgres container start * Adding required App Key env variable * Updating nginx rewriting * Updating firefly nginx confugration traying to make it work with subdirectory https://github.com/firefly-iii/firefly-iii/issues/2848#issuecomment-557845301 * Trying to rewrite * Reconfiguring nginx to pass headers * Updating docker fragment * Last try * Allowing firefly iii to be hosted on other domain * Fixing docker compose env variables * Exposing ports for external communication * Ports exposing * Updating firefly host reference * Matching service name and VIRTUAL_HOST_NAME * Getting nginx to redirect to port 8080 * update and adapt * Adapt firefly to be with dedicated domain * Adapt Docker file builder to support non github builds * Make firefly init create db only if not exists + run full recommended upgrade procedure Co-authored-by: rockstardev --- README.md | 3 ++ Tools/fireflyiii/init.sh | 11 +++++++ btcpay-setup.sh | 2 ++ contrib/DockerFileBuildHelper/DockerInfo.cs | 4 +-- contrib/DockerFileBuildHelper/Program.cs | 9 ++++++ contrib/build-all-images.sh | 16 ++++++++++ .../docker-fragments/opt-add-fireflyiii.yml | 32 +++++++++++++++++++ docs/fireflyiii.md | 18 +++++++++++ helpers.sh | 3 +- 9 files changed, 95 insertions(+), 3 deletions(-) create mode 100755 Tools/fireflyiii/init.sh create mode 100644 docker-compose-generator/docker-fragments/opt-add-fireflyiii.yml create mode 100644 docs/fireflyiii.md diff --git a/README.md b/README.md index aa63ed6..2f3e321 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ Additionally, there are specific environment variables for some addons: * `EPS_XPUB`: If Electrum Personal Server (EPS) is activated with [opt-add-electrum-ps](docker-compose-generator/docker-fragments/opt-add-electrum-ps.yml), you must set the Extended Public Key (XPUB, YPUB or ZPUB) of the wallet you want to use, before first run of the EPS server. If you accidently start EPS without this, it will not work properly as the model of EPS is to monitor only specified wallets. * If Bitcoin Wallet Tracker is activated with [opt-add-bwt](docker-compose-generator/docker-fragments/opt-add-bwt.yml), you can use `BWT_XPUB`/`BWT_XPUB_*` (to set your XPUB/YPUB/ZPUB), `BWT_DESCRIPTOR`/`BWT_DESCRIPTOR_*` (for script descriptors), `BWT_RESCAN_SINCE` (set to the wallet creation date in YYYY-MM-DD to speed up the rescan), `BWT_BITCOIND_WALLET` and `BWT_GAP_LIMIT`. * `LND_WTCLIENT_SWEEP_FEE`: If LND watchtower is activated with [opt-lnd-wtclient](docker-compose-generator/docker-fragments/opt-lnd-wtclient.yml), you can use `LND_WTCLIENT_SWEEP_FEE` to change the sweep fee used in constructing the justice transaction (default is 10 sat/byte) +* `FIREFLY_HOST`: If fireflyiii is activated with [opt-add-fireflyiii](docker-compose-generator/docker-fragments/opt-add-fireflyiii.yml), the hostname of your fireflyiii website (eg. `firefly.example.com`) # Tooling A wide variety of useful scripts are available once BTCPay is installed: @@ -181,6 +182,7 @@ Available `BTCPAYGEN_ADDITIONAL_FRAGMENTS` currently are: * [opt-add-teos](docker-compose-generator/docker-fragments/opt-add-teos.yml) for [The Eye Of Satoshi](https://github.com/talaia-labs/python-teos), a BOLT13 Lightning Watchtower. Use port 9814 on your server or Tor to connect. * [opt-add-zammad](docker-compose-generator/docker-fragments/opt-add-zammad.yml) for [Zammad](https://zammad.com/features), a web based open source helpdesk/customer support system with many features to manage customer communication via several channels like telephone, facebook, twitter, chat and e-mails * [opt-monero-expose](docker-compose-generator/docker-fragments/opt-monero-expose.yml) to expose monero node's RPC port at 127.0.0.1:18081 to connect your own wallet. Use f.e. ssh port forwarding to forward to your own computer. +* [opt-add-fireflyiii](docker-compose-generator/docker-fragments/opt-add-fireflyiii.yml) ([See the documentation](docs/fireflyiii.md)) You can also create your own [custom fragments](#how-can-i-customize-the-generated-docker-compose-file). @@ -372,6 +374,7 @@ We are trying to update our dependencies to run on `arm32v7` and `x64` boards. H | jvandrew/btcqbo | 0.3.36 | [✔️](https://raw.githubusercontent.com/JeffVandrewJr/btcqbo/v0.3.36/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/JeffVandrewJr/btcqbo) - [DockerHub](https://hub.docker.com/r/jvandrew/btcqbo) | | shesek/bwt | 0.2.2-electrum | [✔️](https://raw.githubusercontent.com/bwt-dev/bwt/v0.2.2/docker/Dockerfile) | [✔️](https://raw.githubusercontent.com/bwt-dev/bwt/v0.2.2/docker/arm32v7.Dockerfile) | [✔️](https://raw.githubusercontent.com/bwt-dev/bwt/v0.2.2/docker/arm64v8.Dockerfile) | [Github](https://github.com/bwt-dev/bwt) - [DockerHub](https://hub.docker.com/r/shesek/bwt) | | lukechilds/electrumx | latest | [✔️](https://raw.githubusercontent.com/lukechilds/docker-electrumx/master/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/lukechilds/docker-electrumx) - [DockerHub](https://hub.docker.com/r/lukechilds/electrumx) | +| fireflyiii/core | latest | [✔️](https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true) | [✔️](https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true) | [✔️](https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true) | [Github](https://dev.azure.com/Firefly-III/_git/MainImage) - [DockerHub](https://hub.docker.com/r/fireflyiii/core) | | jvandrew/librepatron | 0.7.39 | [✔️](https://raw.githubusercontent.com/JeffVandrewJr/patron/v0.7.39/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/JeffVandrewJr/patron) - [DockerHub](https://hub.docker.com/r/jvandrew/librepatron) | | jvandrew/isso | atron.22 | [✔️](https://raw.githubusercontent.com/JeffVandrewJr/isso/patron.22/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/JeffVandrewJr/isso) - [DockerHub](https://hub.docker.com/r/jvandrew/isso) | | sphinxlightning/sphinx-relay | v2.2.0 | [✔️](https://raw.githubusercontent.com/stakwork/sphinx-relay/v2.2.0/Dockerfile) | ️❌ | [✔️](https://raw.githubusercontent.com/stakwork/sphinx-relay/v2.2.0/Dockerfile) | [Github](https://github.com/stakwork/sphinx-relay) - [DockerHub](https://hub.docker.com/r/sphinxlightning/sphinx-relay) | diff --git a/Tools/fireflyiii/init.sh b/Tools/fireflyiii/init.sh new file mode 100755 index 0000000..ae29266 --- /dev/null +++ b/Tools/fireflyiii/init.sh @@ -0,0 +1,11 @@ +#!/bin/bash + + +[[ $(docker exec $(docker ps -a -q -f "name=postgres_1") psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'fireflyiii'") =~ "1" ]] || docker exec $(docker ps -a -q -f "name=postgres_1") psql -U postgres -c "CREATE DATABASE fireflyiii" +docker exec generated_fireflyiii_1 php artisan migrate --seed +docker exec generated_fireflyiii_1 php artisan firefly-iii:decrypt-all +docker exec generated_fireflyiii_1 php artisan cache:clear +docker exec generated_fireflyiii_1 php artisan firefly-iii:upgrade-database +docker exec generated_fireflyiii_1 php artisan passport:install +docker exec generated_fireflyiii_1 php artisan cache:clear +exit 0 \ No newline at end of file diff --git a/btcpay-setup.sh b/btcpay-setup.sh index 059759f..10198e5 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -107,6 +107,7 @@ Add-on specific variables: BTCTRANSMUTER_HOST: If btc transmuter is activated with opt-add-btctransmuter, the hostname of your btc transmuter website (eg. store.example.com) TOR_RELAY_NICKNAME: If tor relay is activated with opt-add-tor-relay, the relay nickname TOR_RELAY_EMAIL: If tor relay is activated with opt-add-tor-relay, the email for Tor to contact you regarding your relay + FIREFLY_HOST: If fireflyiii is activated with opt-add-fireflyiii, the hostname of your libre patron website (eg. firefly.example.com) END } START="" @@ -309,6 +310,7 @@ ACME_CA_URI:$ACME_CA_URI TOR_RELAY_NICKNAME: $TOR_RELAY_NICKNAME TOR_RELAY_EMAIL: $TOR_RELAY_EMAIL PIHOLE_SERVERIP: $PIHOLE_SERVERIP +FIREFLY_HOST: $FIREFLY_HOST ---------------------- Additional exported variables: BTCPAY_DOCKER_COMPOSE=$BTCPAY_DOCKER_COMPOSE diff --git a/contrib/DockerFileBuildHelper/DockerInfo.cs b/contrib/DockerFileBuildHelper/DockerInfo.cs index 02d3367..16f3b62 100644 --- a/contrib/DockerFileBuildHelper/DockerInfo.cs +++ b/contrib/DockerFileBuildHelper/DockerInfo.cs @@ -14,10 +14,10 @@ namespace DockerFileBuildHelper public string GitRef { get; set; } public bool SupportedByUs { get; set; } public Image Image { get; internal set; } - + public string RawLink { get; set; } public string GetGithubLinkOf(string path) { - return $"https://raw.githubusercontent.com/{GitLink.Substring("https://github.com/".Length)}/{GitRef}/{path}"; + return RawLink ?? $"https://raw.githubusercontent.com/{GitLink.Substring("https://github.com/".Length)}{(GitRef is null ? string.Empty : ("/" + GitRef))}/{path}"; } } } diff --git a/contrib/DockerFileBuildHelper/Program.cs b/contrib/DockerFileBuildHelper/Program.cs index 5c48422..647a5f8 100644 --- a/contrib/DockerFileBuildHelper/Program.cs +++ b/contrib/DockerFileBuildHelper/Program.cs @@ -636,6 +636,15 @@ namespace DockerFileBuildHelper dockerInfo.GitLink = "https://github.com/BlueWallet/LndHub"; dockerInfo.GitRef = $"{image.Tag.Split("@")[0]}"; break; + case "fireflyiii/core": + dockerInfo.DockerFilePath = $"Dockerfile"; + dockerInfo.DockerFilePathARM32v7 = $"Dockerfile"; + dockerInfo.DockerFilePathARM64v8 = $"Dockerfile"; + dockerInfo.GitLink = "https://dev.azure.com/Firefly-III/_git/MainImage"; + dockerInfo.RawLink = "https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true"; + + dockerInfo.GitRef = null; + break; default: if (firstTry) { diff --git a/contrib/build-all-images.sh b/contrib/build-all-images.sh index e9f84a7..f6e8891 100644 --- a/contrib/build-all-images.sh +++ b/contrib/build-all-images.sh @@ -673,6 +673,22 @@ docker build -f "$DOCKERFILE" -t "lukechilds/electrumx:latest" . cd - && cd .. +# Build core +# https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true +DOCKERFILE="Dockerfile" +# https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true +[[ "$(uname -m)" == "armv7l" ]] && DOCKERFILE="Dockerfile" +# https://dev.azure.com/Firefly-III/66fb773b-063e-42d7-b6a5-e7729a22e8b3/_apis/git/repositories/e9c3dcf8-4533-4ef1-83cc-75527cab3377/items?path=%2FDockerfile&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=main&resolveLfs=true&%24format=octetStream&api-version=5.0&download=true +[[ "$(uname -m)" == "aarch64" ]] && DOCKERFILE="Dockerfile" +echo "Building fireflyiii/core:latest" +git clone https://dev.azure.com/Firefly-III/_git/MainImage core +cd core +git checkout +cd "$(dirname $DOCKERFILE)" +docker build -f "$DOCKERFILE" -t "fireflyiii/core:latest" . +cd - && cd .. + + # Build librepatron # https://raw.githubusercontent.com/JeffVandrewJr/patron/v0.7.39/Dockerfile DOCKERFILE="Dockerfile" diff --git a/docker-compose-generator/docker-fragments/opt-add-fireflyiii.yml b/docker-compose-generator/docker-fragments/opt-add-fireflyiii.yml new file mode 100644 index 0000000..c7df0c5 --- /dev/null +++ b/docker-compose-generator/docker-fragments/opt-add-fireflyiii.yml @@ -0,0 +1,32 @@ +version: '3' + +services: + fireflyiii: + image: fireflyiii/core:latest + environment: + - APP_ENV=local + - APP_KEY=MustBe32DropDbAndChangeItIfUWant + - APP_URL=http://${FIREFLY_HOST} + - TRUSTED_PROXIES=** + - DB_CONNECTION=pgsql + - DB_HOST=postgres + - DB_PORT=5432 + - DB_DATABASE=fireflyiii + - DB_USERNAME=postgres + - DB_PASSWORD= + - VIRTUAL_HOST_NAME=fireflyiii + - VIRTUAL_HOST=${FIREFLY_HOST} + - VIRTUAL_PORT=8080 + - LETSENCRYPT_HOST=${FIREFLY_HOST} + - LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL:-} + expose: + - 8080 + volumes: + - firefly_iii_export:/var/www/firefly-iii/storage/export + - firefly_iii_upload:/var/www/firefly-iii/storage/upload + depends_on: + - postgres + +volumes: + firefly_iii_export: + firefly_iii_upload: \ No newline at end of file diff --git a/docs/fireflyiii.md b/docs/fireflyiii.md new file mode 100644 index 0000000..f05efcd --- /dev/null +++ b/docs/fireflyiii.md @@ -0,0 +1,18 @@ +# Firefly III support + +[Firefly III](https://pi-hole.net/) is a self-hosted financial manager. +It can help you keep track of expenses, income, budgets and everything in between. It supports credit cards, shared household accounts and savings accounts. It’s pretty fancy. You should use it to save and organise money. + +## How to use + +1. Connect as root to your server +2. Configure a domain's DNS to point to your server ip. e.g. `firefly.yourserver.org` +3. Add fireflyiii as an option to your docker deployment + +```bash +BTCPAYGEN_ADDITIONAL_FRAGMENTS="$BTCPAYGEN_ADDITIONAL_FRAGMENTS;opt-add-fireflyiii" +FIREFLY_HOST="firefly.yourserver.org" +. btcpay-setup.sh -i +. ./Tools/fireflyiii/init.sh +``` +4. Access Firefly III at `firefly.yourserver.org` and create your admin account. diff --git a/helpers.sh b/helpers.sh index b4d7e83..f175f2d 100755 --- a/helpers.sh +++ b/helpers.sh @@ -105,7 +105,8 @@ WOOCOMMERCE_HOST=$WOOCOMMERCE_HOST TOR_RELAY_NICKNAME=$TOR_RELAY_NICKNAME TOR_RELAY_EMAIL=$TOR_RELAY_EMAIL EPS_XPUB=$EPS_XPUB -LND_WTCLIENT_SWEEP_FEE=$LND_WTCLIENT_SWEEP_FEE" > $BTCPAY_ENV_FILE +LND_WTCLIENT_SWEEP_FEE=$LND_WTCLIENT_SWEEP_FEE +FIREFLY_HOST=$FIREFLY_HOST" > $BTCPAY_ENV_FILE env | grep ^BWT_ >> $BTCPAY_ENV_FILE || true }