Personal project. Running since [YEAR].
Home lab
A custom PC and a Synology NAS that handle my storage, backups and self-hosting. Cinema Club DC runs on the NAS in Docker and reaches the internet through a Cloudflare Tunnel. Tailscale connects my devices when I'm away from home, and Homebridge runs the home automation.
- Hardware
- [NAS MODEL] with [DRIVES AND RAID TYPE]. A custom PC with [CPU, GPU, RAM].
- Software
- Synology DSM, Container Manager, Docker Compose, Cloudflare Tunnel, Unbound, Tailscale, Homebridge
- Code
- Cinema Club DC on GitHub, including the deploy guide
How it fits together
Three kinds of traffic reach the NAS, and none of them need an open port. Pick one to follow it through.
- 1. CloudflareDNS, HTTPS, cache
cinemaclubdc.com points at Cloudflare, which handles HTTPS and caches the frontend's files.
- 2. The tunnelcloudflared container
cloudflared keeps an outbound connection open to Cloudflare, so requests reach the NAS with no open ports. On Synology it has to run over HTTP/2.
- 3. nginxfrontend container
Serves the React build and passes anything under /api to the backend.
- 4. Flaskbackend container
Gunicorn runs the app. The data is one SQLite file on a Docker volume, so rebuilding the containers never touches it.
- 1. Discordgateway connection
The bot keeps its own connection open to Discord, so slash commands come straight to it. It has 3 seconds to answer.
- 2. The botbot container
It answers commands and posts new schedule drops, calling the backend over Docker's internal network with a shared token.
- 3. Flaskbackend container
The same backend the site uses, plus internal routes that only the bot can call.
- 1. TailscaleWireGuard
[MY DEVICES] are on one private network, so the NAS and the PC are reachable from anywhere without opening ports.
- 2. DSMthe NAS's admin page
Container Manager, logs, the Task Scheduler and my files, the same as at home.
- 3. Custom PC[PC SPECS]
[WHAT I USE THE PC FOR REMOTELY]
Simplified. Internal addresses and admin settings are left out on purpose.
Running Cinema Club DC on a NAS
The site is one Docker Compose file. Three containers are the app itself: a Flask backend under Gunicorn that also runs the theater scrapers, the React frontend on nginx, and the Discord bot. A fourth is a small caching DNS resolver, and a fifth runs cloudflared for the tunnel.
DSM's Task Scheduler runs the scrapers. Every theater is checked every 6 hours, and one is checked every 30 minutes because it posts films a week before tickets go on sale, and members want the on-sale alert quickly. To ship an update I pull the code on the NAS, rebuild, and clear Cloudflare's cache so visitors get the new frontend.
| Container | What it does |
|---|---|
| frontend | The React build on nginx. Serves the site and passes API calls to the backend. |
| backend | Flask under Gunicorn. The API, the theater scrapers and the SQLite database. |
| bot | The Discord bot. Slash commands and schedule posts. |
| dns | An Unbound caching resolver, added to fix failed lookups (below). |
| cloudflared | The Cloudflare Tunnel. Connects out to Cloudflare so nothing has to connect in. |
# Shipping an update
ssh nas
cd /volume1/docker/cinema-club-dc
git pull
sudo docker-compose up -d --build
# DSM Task Scheduler, every 6 hours: every theater
docker exec cinemaclub-backend python scraper.py
# every 30 minutes: the theater that posts early
docker exec cinemaclub-backend python scraper.py --only sunsProblems I had to fix
Lookups failing inside Docker
On the NAS, Docker's built-in DNS forwarder failed about 1 lookup in 5. That broke sign-in emails and calls to the movie data APIs (TMDB and OMDb). Pointing the containers straight at the router helped until the router started failing about 1 in 6 as well.
So I added a small Unbound container that asks the router and caches the answers, and serves a cached answer when the router doesn't respond. It has a fixed address on its own Docker network that the backend and bot join, and the backend retries any lookup for about 3 seconds before giving up. A diagnostic script counts failures so I can tell which layer is at fault.
# docker-compose.yml (excerpt): the caching resolver
dns:
build:
context: .
dockerfile: Dockerfile.dns # alpine + unbound
environment:
- DNS_UPSTREAM=<router>
networks:
lookups:
ipv4_address: <fixed address>
restart: unless-stoppedThe tunnel on Synology
cloudflared connects over QUIC by default, and on Synology that fails with a socket error. Running the tunnel over HTTP/2 fixed it. The tunnel container joins the site's Docker network so it can reach the frontend by name.
Slow first replies after quiet hours
Discord gives a bot 3 seconds to answer a slash command. After a quiet spell the bot sometimes missed that, because the NAS had spun its drives down and waking them took longer than Discord would wait. Turning off drive hibernation fixed it, and the bot now logs where every slow reply spent its time.
Backups
The site's database is one SQLite file on a Docker volume. The backend saves a copy before any migration that rebuilds a table, and I take my own copies with SQLite's VACUUM INTO while the site is running. [HOW THE NAS ITSELF IS BACKED UP, FOR EXAMPLE HYPER BACKUP TO AN EXTERNAL DRIVE OR CLOUD STORAGE.]
Tailscale and Homebridge
Tailscale puts [MY DEVICES] on one private WireGuard network, so I can reach the NAS's admin page, my files and the PC from anywhere without opening ports. Homebridge runs [WHERE IT RUNS] and brings [ACCESSORIES] into Apple Home.