-
Notifications
You must be signed in to change notification settings - Fork 0
feat(infra): add Heroku deployment configuration #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mroderick
wants to merge
3
commits into
main
Choose a base branch
from
feature/heroku-deployment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 22 | ||
| 24 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| web: npm start | ||
| release: ./scripts/heroku-release.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "name": "Codebar Auth", | ||
| "description": "Authentication service for Codebar using Better Auth", | ||
| "repository": "https://github.com/codebar/auth", | ||
| "website": "https://auth.codebar.io", | ||
| "success_url": "/health", | ||
| "stack": "heroku-24", | ||
| "formation": { | ||
| "web": { | ||
| "quantity": 1, | ||
| "size": "basic" | ||
| } | ||
| }, | ||
| "addons": [ | ||
| { | ||
| "plan": "heroku-postgresql:essential-0", | ||
| "as": "DATABASE" | ||
| } | ||
| ], | ||
| "env": { | ||
| "GITHUB_CLIENT_ID": { | ||
| "description": "GitHub OAuth App Client ID (create at https://github.com/settings/developers)", | ||
| "required": true | ||
| }, | ||
| "GITHUB_CLIENT_SECRET": { | ||
| "description": "GitHub OAuth App Client Secret", | ||
| "required": true | ||
| }, | ||
| "BETTER_AUTH_SECRET": { | ||
| "description": "Secret key for Better Auth session encryption", | ||
| "generator": "secret" | ||
| }, | ||
| "CODEBAR_AUTH_URL": { | ||
| "description": "Base URL for auth service", | ||
| "value": "https://auth.codebar.io" | ||
| } | ||
| }, | ||
|
|
||
| "buildpacks": [ | ||
| { | ||
| "url": "heroku/nodejs" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Deployment | ||
|
|
||
| How to deploy codebar-auth to Heroku. | ||
|
|
||
| ## Automatic Deployments | ||
|
|
||
| The standard workflow. Every merge to `main` triggers: | ||
|
|
||
| 1. Heroku pulls the latest code | ||
| 2. Build phase installs dependencies | ||
| 3. Release phase runs database migrations | ||
| 4. New dynos start serving traffic | ||
|
|
||
| No manual intervention required. | ||
|
|
||
| ## Manual Deployment (Emergency Only) | ||
|
|
||
| Use only when automatic deploys fail or during incidents requiring immediate hotfixes. | ||
|
|
||
| ```bash | ||
| # Break-the-glass: bypass automatic deploys | ||
| git push heroku main --force | ||
| ``` | ||
|
|
||
| **Warning:** Manual deployment bypasses GitHub branch protection and CI checks. Use sparingly. | ||
|
|
||
| ## Rollback | ||
|
|
||
| ```bash | ||
| # Rollback to previous release | ||
| heroku releases:rollback | ||
|
|
||
| # Rollback to specific version | ||
| heroku releases:rollback v42 | ||
| ``` | ||
|
|
||
| ## Monitoring | ||
|
|
||
| ```bash | ||
| heroku logs --tail # View app logs | ||
| heroku ps # Check dyno status | ||
| heroku releases # View deployment history | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Heroku Setup | ||
|
|
||
| One-time setup for deploying codebar-auth to Heroku. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Heroku CLI installed and authenticated (`heroku login`) | ||
| - GitHub OAuth app created at https://github.com/settings/developers | ||
| - Admin access to the codebar/auth GitHub repository | ||
|
|
||
| ## Create the Heroku App | ||
|
|
||
| ```bash | ||
| # Create app from app.json (provisions dyno, database, and env vars) | ||
| heroku create codebar-auth-production --manifest | ||
|
|
||
| # Set GitHub OAuth credentials | ||
| heroku config:set GITHUB_CLIENT_ID=your_client_id | ||
| heroku config:set GITHUB_CLIENT_SECRET=your_client_secret | ||
| ``` | ||
|
|
||
| ## Connect GitHub Repository | ||
|
|
||
| 1. Open the Heroku Dashboard: `heroku open` | ||
| 2. Navigate to the **Deploy** tab | ||
| 3. In **Deployment method**, select **GitHub** | ||
| 4. Search for and connect to the `codebar/auth` repository | ||
| 5. In **Automatic deploys**, select the `main` branch | ||
| 6. Click **Enable Automatic Deploys** | ||
|
|
||
| ## First Deploy | ||
|
|
||
| The `main` branch is protected from direct pushes. Merge the infrastructure PR to trigger the first deployment. | ||
|
|
||
| Heroku deploys automatically when code merges to `main`. The release phase runs database migrations before dynos start. | ||
|
|
||
| ## GitHub OAuth Configuration | ||
|
|
||
| After deploying, update your GitHub OAuth app settings: | ||
|
|
||
| - **Homepage URL:** `https://auth.codebar.io` | ||
| - **Authorization callback URL:** `https://auth.codebar.io/api/auth/callback/github` | ||
|
|
||
| ## Infrastructure | ||
|
|
||
| | Component | Configuration | | ||
| | ------------ | --------------------------------- | | ||
| | **Dyno** | Basic (always-on) | | ||
| | **Database** | Heroku Postgres Essential-0 (1GB) | | ||
| | **Stack** | heroku-24 | | ||
| | **Node.js** | >= 24.0.0 | | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Source | Description | | ||
| | ---------------------- | ---------------- | ---------------------------- | | ||
| | `DATABASE_URL` | Auto-provisioned | PostgreSQL connection string | | ||
| | `GITHUB_CLIENT_ID` | Required | GitHub OAuth client ID | | ||
| | `GITHUB_CLIENT_SECRET` | Required | GitHub OAuth client secret | | ||
| | `BETTER_AUTH_SECRET` | Auto-generated | Session encryption key | | ||
| | `CODEBAR_AUTH_URL` | Auto-set | Application base URL | | ||
| | `PORT` | Heroku | Dyno port | | ||
|
till marked this conversation as resolved.
|
||
|
|
||
| ## Files | ||
|
|
||
| - `app.json` — App manifest | ||
| - `Procfile` — Process definitions | ||
| - `scripts/heroku-release.sh` — Release tasks | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/sh | ||
|
till marked this conversation as resolved.
|
||
| # Release phase script - runs after build, before new dynos start. | ||
| # Using a script file (vs inline in Procfile) allows: | ||
| # - Explicit error handling with set -e (fails release if migrations fail) | ||
| # - Clear logging of release phase progress | ||
| # - Easy extension for future release tasks (seeding, cache warming, etc.) | ||
| set -e | ||
|
|
||
| echo "Running database migrations..." | ||
| npm run db:migrate | ||
|
|
||
| echo "Release phase complete!" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be an org app
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we need someone to add that, or grant us privileges to do it ourselves?
https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-programmatic-access-to-your-organization/adding-and-removing-github-app-managers-in-your-organization#about-github-app-managers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to setup anything, we can ask Kimberly to extend the current app by adding (allow listing) an additional redirect URL.