From 27645048f1e012e40b315d4e23029aab12b1af82 Mon Sep 17 00:00:00 2001 From: ShayManor Date: Sun, 23 Aug 2026 10:33:26 -0700 Subject: [PATCH] feat(deploy): add self-host compose file and document self-hosting The repo had three Dockerfiles but nothing that ran them together, and the README never mentioned self-hosting. The only deploy path was deploy/compose.yml, which is bound to the production box: it pulls private ghcr images and hard-fails on seven env vars including OAuth credentials, so nobody else could run it. Every one of those vars already has a default in the service config; the :?missing guards are a production-deploy check, not an application requirement. This adds a root compose file that builds the three services from source and needs only GITHUB_PAT and FETCHER_INTERNAL_TOKEN. deploy/compose.yml is unchanged, so production is unaffected. Verified by running it: all three images build, all five containers start, the generator serves the SPA and /api/health, and edge answers / with upstream_ok true. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS --- .env.example | 14 +++++++++ .gitignore | 1 + README.md | 27 +++++++++++++++++ docker-compose.yml | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 .env.example create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d81c03e --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +# Copy to .env and fill in. Only these two matter. + +# A GitHub personal access token. Classic or fine-grained, no scopes needed +# for public data - it is only used to raise your GitHub API rate limit. +# Create one at https://github.com/settings/tokens +GITHUB_PAT= + +# Shared secret the three services use to talk to each other. Any random +# string; it never leaves your machine. Generate one with: +# openssl rand -hex 32 +FETCHER_INTERNAL_TOKEN= + +# Port the card service listens on (http://localhost:PORT). +#GHSTATS_PORT=5003 diff --git a/.gitignore b/.gitignore index 7afcf72..771b378 100644 --- a/.gitignore +++ b/.gitignore @@ -241,3 +241,4 @@ screenshots/ **/*.md !README.md !**/README.md +/data/ diff --git a/README.md b/README.md index 976ab99..1b45045 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,33 @@ per account, so save it for when it matters. --- +## Self-hosting + +The public instance at `gh-stats.com` is free and you do not need to run your +own. Self-host if you want your own rate limit, private repository data staying +on your hardware, or control over when cards rebuild. + +You need Docker and a GitHub token. The token needs no scopes for public data; +it exists to raise your GitHub API rate limit. + +```bash +git clone https://github.com/ShayManor/github-readme-stats +cd github-readme-stats +cp .env.example .env # put your token in GITHUB_PAT +docker compose up -d --build +``` + +Then open `http://localhost:5002` and embed from your own host: + +```md +![stats](http://localhost:5002/api/YOUR_USERNAME) +``` + +Three services come up behind `docker compose`: `fetcher` talks to GitHub and +owns the token, `generator` renders the SVGs and serves the web UI on 5002, and +`edge` is a caching proxy on 5003 that serves cards at `/`. Data lives +in `./data`. Set `GHSTATS_PORT` to move the web UI off 5002. + ## FAQ **Can I use a private GitHub account?** diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..aac8a1d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,72 @@ +# Self-hosting gh-stats. +# +# Runs the same three services and the same published images that gh-stats.com +# runs. Everything is optional except GITHUB_PAT and FETCHER_INTERNAL_TOKEN. +# +# cp .env.example .env # then put your PAT in it +# docker compose up -d --build +# open http://localhost:5002 +# +# The production deploy uses deploy/compose.yml instead; this file is the +# stripped-down version for running it on your own box. + +name: ghstats + +x-fetcher-env: &fetcher-env + GITHUB_PAT: ${GITHUB_PAT:?set GITHUB_PAT in .env - see .env.example} + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?set FETCHER_INTERNAL_TOKEN in .env - any random string} + +services: + fetcher: + build: ./fetcher + image: ghstats-fetcher:local + restart: unless-stopped + environment: + <<: *fetcher-env + GENERATOR_URL: http://generator:5002 + volumes: + - ./data/fetcher:/app/data + + fetcher-cron: + build: ./fetcher + image: ghstats-fetcher:local + restart: unless-stopped + command: ["python", "-m", "src.cron"] + environment: *fetcher-env + volumes: + - ./data/fetcher:/app/data + depends_on: [fetcher] + + generator: + build: ./generator + image: ghstats-generator:local + restart: unless-stopped + environment: &generator-env + FETCHER_URL: http://fetcher:5001 + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?set FETCHER_INTERNAL_TOKEN in .env - any random string} + volumes: + - ./data/generator:/app/data + ports: + - "${GHSTATS_PORT:-5002}:5002" + depends_on: [fetcher] + + generator-worker: + build: ./generator + image: ghstats-generator:local + restart: unless-stopped + command: ["python", "-m", "src.worker"] + environment: *generator-env + volumes: + - ./data/generator:/app/data + depends_on: [generator] + + edge: + build: ./edge + image: ghstats-edge:local + restart: unless-stopped + environment: + GENERATOR_URL: http://generator:5002 + FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?set FETCHER_INTERNAL_TOKEN in .env - any random string} + ports: + - "${GHSTATS_EDGE_PORT:-5003}:5003" + depends_on: [generator]