GitHub Integration Guide
Docklift integrates with GitHub using a GitHub App. This allows for accessing private repositories and receiving webhook events (push) for auto-deployments.
Architecture
- •Routes:
backend/src/routes/github.ts - •Service:
backend/src/services/git.ts(for cloning/pulling) - •Authentication: Uses JWT signed with a private key to authenticate as the GitHub App.
Setup Flow (Manifest Flow)
- •Initiation: User clicks "Connect GitHub" in UI.
- •Manifest Generation:
POST /api/github/manifestgenerates a GitHub App manifest. - •Redirect: User is redirected to GitHub to create the app.
- •Callback: GitHub redirects back to
/api/github/manifest/callbackwith a code. - •Exchange: Backend exchanges code for App Credentials (ID, Client ID, Secret, Private Key, Webhook Secret).
- •Storage: Credentials are stored in the
Settingstable in the database. - •Installation: User is redirected to install the newly created app on their account/orgs.
Key Components
Repository Listing
- •Endpoint:
GET /api/github/repos - •Logic: Fetches repositories from all installations accessible to the App.
- •Important: Uses pagination to ensure all repositories are retrieved (recursively fetching all pages).
Webhooks (Auto-Deploy)
- •Endpoint:
POST /api/github/webhook - •Event: Listen for
pushevents. - •Logic:
- •Verifies signature using
github_webhook_secret. - •Matches repository URL from payload with
Projectdatabase entries. - •Triggers deployment for matching projects with
auto_deploy: true.
- •Verifies signature using
Authentication
- •App Auth: Uses
jsonwebtokento sign a JWT with the stored Private Key (RS256). - •Installation Auth: Uses the App JWT to request an "Installation Token" for specific API acts (like cloning or fetching repos).
Troubleshooting
- •"Repositories not loading": Check if the App is installed on the specific GitHub account.
- •"Webhook not triggering": Verify the
webhook_secretin DB matches GitHub. Check ifauto_deployis enabled for the project. - •"Authentication Failed": The Private Key might be missing or invalid in the database.
Useful Database Settings (Settings table)
- •
github_app_id - •
github_private_key - •
github_webhook_secret - •
github_installation_id(Default installation ID)