Skip to content

therustyrobot/hosthing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hosthing

Management scripts for wiring self-hosted apps behind a Cloudflare Tunnel + Traefik reverse proxy.

These scripts are designed to be run by an AI agent (e.g. opencode) that reads the README, understands the stack, and executes the scripts on your behalf. You can run them yourself too, but the interactive prompts and --dry-run flags make them agent-friendly.

Stack

your-domain.com
  └── Cloudflare Access (Zero Trust auth)
        └── Cloudflare Tunnel (no open ports)
              └── Traefik (reverse proxy, wildcard TLS)
                    └── Docker container

Setup (one-time)

Copy .env.example to .env and fill in the values:

Key Description
CF_API_TOKEN Cloudflare API token with Tunnel Edit, Access Edit, DNS Edit permissions
CF_ACCOUNT_ID Cloudflare account ID (from tunnel token or dashboard)
CF_TUNNEL_ID Cloudflare Tunnel ID
DOMAIN Your domain (e.g. example.com)
CF_ACCESS_EMAIL Email allowed through Zero Trust Access
TRAEFIK_NETWORK Docker network Traefik listens on (default: traefik-proxy)
GLANCE_CONFIG_DIR Path to Glance config dir (enables auto dashboard integration)

Adding a new app

./add-app --name <subdomain> --port <container-port> [options]

Creates a public hostname, DNS record, Zero Trust Access policy, adds Traefik labels to your compose file, and optionally adds the app to your Glance dashboard.

Options

Flag Description
--name Subdomain (e.g. outlineoutline.yourdomain.com)
--port Port the container listens on internally
--dir Path to the app's docker-compose directory (patches it automatically)
--service Which service in the compose file to add labels to (defaults to --name)
--no-access Skip Cloudflare Access setup (app will be public)
--no-restart Don't restart the stack after patching
--dry-run Show what would happen without making changes

What add-app does

  1. Cloudflare Tunnel — adds/updates a public hostname rule pointing to Traefik
  2. DNS — creates/corrects a CNAME record → tunnel
  3. Cloudflare Access — creates a Zero Trust self-hosted app with an email-allow policy
  4. Docker Compose — patches the compose file with Traefik labels and traefik-proxy network membership, then restarts the stack
  5. Glance Dashboard — interactively prompts to add the app to the monitor and/or services pages

Examples

./add-app --name outline --port 3000 --dir ~/outline
./add-app --name gitea --port 3000 --dir ~/gitea --service server
./add-app --name someapp --port 8080 --dir ~/someapp --dry-run
./add-app --name someapp --port 8080              # tunnel + DNS + Access only

Removing an app

./remove-app --name <subdomain> [options]

Reverses add-app — removes the Tunnel ingress, DNS record, Access app, Traefik labels, and Glance dashboard entries. Each step is confirmed interactively.

Options

Flag Description
--name Subdomain to remove (e.g. outlineoutline.yourdomain.com)
--dir Path to the app's docker-compose directory
--service Which service in the compose file to clean up (defaults to --name)
--no-access Skip Cloudflare Access removal
--force Skip all confirmations (use defaults — careful)
--dry-run Show what would be removed without making changes

What remove-app does (each step confirmed interactively)

  1. Cloudflare Tunnel — removes the public hostname ingress rule
  2. DNS — deletes the CNAME record
  3. Cloudflare Access — deletes the Zero Trust app and its policies
  4. Docker Compose — offers a choice: strip Traefik labels only, stop the stack, or stop + remove volumes
  5. Glance Dashboard — removes entries from the monitor and services pages, then restarts Glance

Examples

./remove-app --name outline --dir ~/outline
./remove-app --name someapp --dry-run
./remove-app --name someapp                      # CF/DNS/Access only, skip compose
./remove-app --name outline --dir ~/outline --force

Troubleshooting

App returns 404 from Cloudflare — tunnel ingress rule not saved, or the app isn't joined to the Traefik network. Run docker inspect <container> and check for the traefik network in its networks.

Traefik shows "no route matched" — verify the traefik.http.routers.<name>.rule label matches the hostname exactly.

Access blocks you — make sure you're logged in with the email matching CF_ACCESS_EMAIL. Add more emails in the Zero Trust dashboard under Access > Applications.

API token errors — confirm the token has Tunnel Edit + Access Edit + DNS Edit permissions.

About

Management scripts for wiring self-hosted apps behind a Cloudflare Tunnel + Traefik reverse proxy.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages