Self-Host Maybe Finance Web App

Last updated on October 9, 2024 am

Self-Host Maybe Finance Web App

Maybe is an open-source personal finance web app that helps you track your income, expenses, and investments. It is built with Ruby on Rails.

In this post, I will show you how to host Maybe on your own Linux server using Docker and Nginx.

0. Environment

Software Version
Ubuntu 22.04.4 LTS
Nginx 1.18.0
Snap 2.63
Docker 27.2.0 (install later)
Certbot 2.11.0 (install later)

1. Install Docker

This section is cherry-picked from the official Docker documentation: Install Docker Engine on Ubuntu | Docker Docs

1.1. Set up Docker APT repository:

1
2
3
4
5
6
7
8
9
10
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

1.2. Install Docker:

1
2
sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

1.3. Check the installation:

1
sudo docker run hello-world

2. Setup Docker Compose

The main doc is located at maybe/docs/hosting/docker.md at main of Maybe’s GitHub repository, but some details are modified here.+

2.1. One-click Setup

1
2
3
4
5
mkdir -p ~/app/maybe_bookkeeping
cd ~/app/maybe_bookkeeping
curl -o compose.yml https://raw.githubusercontent.com/maybe-finance/maybe/main/docker-compose.example.yml
touch .env
openssl rand -hex 64 > .env

Now the .env file is created with a random secret key. Update the .env file as follows:

1
2
SECRET_KEY="your_secret_key"
POSTGRES_PASSWORD="your_postgres_password"

2.2. Optional Configuration

Update the image value of the maybe service in compose.yml to the stable version:

1
2
3
services:
app:
image: ghcr.io/maybe-finance/maybe:stable

By default, docker compose will put the data in /var/lib/docker/volumes/ directory on Linux. You can change it by updating the volumes section of each service in compose.yml, and comment out the top-level volumes section.

for example, to put the data in /var/app/maybe/postgres-data/ directory:

1
2
3
4
5
6
7
8
services:
postgres:
...
volumes:
- /var/app/maybe/postgres-data:/var/lib/postgresql/data

volume:
# postgres-data: # REMEMBER TO COMMENT OUT THIS LINE

Similarly for app service:

1
2
3
4
5
6
7
8
services:
app:
...
volumes:
- /var/app/maybe/app-data:/rails/storage

volume:
# app-data: # REMEMBER TO COMMENT OUT THIS LINE

2.3. Start the Services

Start the services in the background:

1
docker compose up -d

Now it is available at http://localhost:3000/ or <your_pub_ip>:3000. (Don’t forget to open the port of the server in the firewall.)

3. Setup SSL Certificates

At the moment, when you access to your bookkeeping app, the web browser will warn you that the connection is not secure. To fix this, we need to install SSL certificates.

3.1. Install Certbot

Certbot is a free, open-source software for manually-administrated websites to enable HTTPS by using Let’s Encrypt certificates.

This section is mainly based on the official Certbot documentation: Certbot Instructions | Certbot

The snap is pre-installed on Ubuntu 20.04.

1
snap --version

Replace yourdomain.com with your actual domain name.

1
2
3
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot certonly --nginx -d yourdomain.com

The certificates are stored in /etc/letsencrypt/live/yourdomain.com/.

3.2. Configure nginx to use the certificates

Update /etc/nginx/sites-available/yourdomain.com as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {
listen 80;
server_name yourdomain.com;

location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
server_name yourdomain.com;

ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

location / {
proxy_pass http://localhost:3000;
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-Proto $scheme;
}
}

Then save and check the configuration:

1
2
3
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Don’t forget to add respective A DNS records (Or AAAA for IPv6) on your domain registrar.

4. Disable default nginx site

At the moment, the default nginx site is still enabled on port 80 (accessible at http://your_pub_ip/ or http://your_pub_ip:80) with default Nginx welcome page.

To disable it:

Update /etc/nginx/sites-available/default as follows:

1
2
3
4
5
6
7
8
server {
listen 80 default_server;
listen [::]:80 default_server;

location / {
return 403;
}
}
1
2
sudo nginx -t
sudo systemctl reload nginx

5. Setup Invitation Registration

For a self-hosted finance app, you may not want to allow anyone to register. Luckily, Maybe has an optional config to require an invite code to register.

Stop current services first:

1
2
cd ~/app/maybe_bookkeeping
docker compose stop

Add REQUIRE_INVITE_CODE: "true" to the app service in compose.yml:

1
2
3
4
5
services:
app:
...
environment:
- REQUIRE_INVITE_CODE="true"

Restart the services:

1
docker compose up -d

Now you can see that new registration will require an invite code.

You can run rake invites:create to create an invite code. Rake is a GNU Make-like program for Ruby-related tasks, so you probably need to have Ruby toolchain installed on your server.

6. Update for Future Versions

The latest version always have new features and bug fixes. To update the Maybe app to the latest version:

1
2
3
4
5
cd ~/app/maybe_bookkeeping
docker compose stop # Stop the current services
docker compose pull # Pull the latest images
docker compose build app # Rebuild the app service
docker compose up -d # Start the services

7. References

  1. Maybe: The OS for your personal finances
  2. maybe-finance/maybe: The OS for your personal finances
  3. Docker Compose | Docker Docs
  4. Certbot
  5. nginx
  6. How to get invite codes? · Issue #1138 · maybe-finance/maybe
  7. Rake – Ruby Make

Self-Host Maybe Finance Web App
https://lingkang.dev/2024/08/29/host-maybe/
Author
Lingkang
Posted on
August 29, 2024
Licensed under