Mirror a private git repo on Heroku (or elsewhere) behind Google login.
Think GitHub Pages but for private stuff.
- Updates the local copy by listening to an endpoint configured to a push webhook.
- Authenticates with git using SSH public key authentication (good with github deploy keys)
- Directory listings with
expressjs/serve-index
.
-
Create a deploy key for git authentication
$ ssh-keygen -t rsa -f deploykey
-
Add the deploy key to your private repo (https://github.com/user/repo/settings/keys)
-
Add a webhook to send a POST request that will trigger an update on pushes (https://github.com/user/repo/settings/hooks/new)
Endpoint should be
http://myapp.herokuapp.com/update
. Requests are authenticated using the secret which should be also set in env variablePOST_WEBHOOK_SECRET
. -
Create and configure the heroku app
$ git clone https://github.com/reaktor/serve-static-git && cd serve-static-git $ heroku apps:create myapp $ heroku config:set -a myapp \ BASE_URL='http://myapp.herokuapp.com' \ REPO_PATH='/app/hello-world' \ REPO_URL='git@github.com:raine/hello-world.git' \ SSH_PUBLIC_KEY="$(cat deploykey.pub)" \ SSH_PRIVATE_KEY="$(cat deploykey)" \ GOOGLE_OAUTH_CLIENT_ID='...' \ GOOGLE_OAUTH_CLIENT_SECRET='...' \ GOOGLE_OAUTH_ALLOWED_DOMAIN='mycompany.com' \ SESSION_SECRET='...' \ POST_WEBHOOK_SECRET='...' $ git push heroku master
-
Go to http://myapp.herokuapp.com. After Google login, directory listing of the repo should be visible. 🎉
In case of problems, check heroku logs -a myapp
for errors.
$ npm install
$ export \
BASE_URL='http://localhost:3000' \
REPO_PATH='/Users/raine/heroku-git-static/hello-world' \
REPO_URL='git@gitlab.com:rainevi/hello-world.git' \
PORT=3000 \
SSH_PUBLIC_KEY="$(cat deploykey.pub)" \
SSH_PRIVATE_KEY="$(cat deploykey)" \
GOOGLE_OAUTH_CLIENT_ID='...' \
GOOGLE_OAUTH_CLIENT_SECRET='...' \
GOOGLE_OAUTH_ALLOWED_DOMAIN='reaktor.fi' \
SESSION_SECRET='...' \
POST_WEBHOOK_SECRET='...'
$ npm run watch
$ open http://localhost:3000
- Heroku file system is ephemeral, a clone must be created on each restart
- Only full clones, due to
libgit2
not supporting shallow ones. libgit/#3058