feat: Add Orbiter deployment page
421c7799
1 file(s) · +159 −0
| 1 | + | # Orbiter |
|
| 2 | + | ||
| 3 | + | import { Button } from 'vocs/components' |
|
| 4 | + | ||
| 5 | + | <img src="https://docs.orbiter.host/light_logo.svg" alt="orbiter" className="mx-auto" /> |
|
| 6 | + | ||
| 7 | + | Much like the [inspiration](/why-bhvr) behind bhvr, [Orbiter](https://orbiter.host) is a site hosting platform built on the principles that the web should be open and without walled gardens. It features many of the things every dev wants: |
|
| 8 | + | ||
| 9 | + | - Simple CLI for local builds and deployments |
|
| 10 | + | - Custom Domains |
|
| 11 | + | - Analytics |
|
| 12 | + | - Version Control for easy rollbacks |
|
| 13 | + | - GitHub actions for automated deployments |
|
| 14 | + | - Serverless Functions |
|
| 15 | + | ||
| 16 | + | In this guide we'll show you how to deploy your [`server`](/packages/server) to Orbiter Functions. |
|
| 17 | + | ||
| 18 | + | ## Server Deployment |
|
| 19 | + | ||
| 20 | + | ::::note |
|
| 21 | + | Orbiter Functions are only available on paid plans. [Upgrade today!](https://app.orbiter.host/billing) |
|
| 22 | + | :::: |
|
| 23 | + | ||
| 24 | + | ::::steps |
|
| 25 | + | ||
| 26 | + | ### Setup Orbiter Account |
|
| 27 | + | ||
| 28 | + | Visit [app.orbiter.host](https://app.orbiter.host) to create an account and make an API key on the [App Dashboard](https://app.orbiter.host) or on the [Keys Page](https://app.orbiter.host/api-keys). |
|
| 29 | + | ||
| 30 | + | ### Install the Orbiter CLI and Authorize |
|
| 31 | + | ||
| 32 | + | ```bash [terminal] |
|
| 33 | + | bun add -g orbiter-cli@latest |
|
| 34 | + | ``` |
|
| 35 | + | ||
| 36 | + | ```bash [terminal] |
|
| 37 | + | orbiter auth |
|
| 38 | + | ``` |
|
| 39 | + | ||
| 40 | + | ### Update Export Format |
|
| 41 | + | ||
| 42 | + | Update the code inside `server/src/index.ts` to use the export format required by Orbiter Functions: |
|
| 43 | + | ||
| 44 | + | ```typescript [server/src/index.ts] |
|
| 45 | + | import { Hono } from 'hono' |
|
| 46 | + | import { cors } from 'hono/cors' |
|
| 47 | + | import type { ApiResponse } from 'shared/dist' |
|
| 48 | + | ||
| 49 | + | const app = new Hono() |
|
| 50 | + | ||
| 51 | + | app.use(cors()) |
|
| 52 | + | ||
| 53 | + | app.get('/', (c) => { |
|
| 54 | + | return c.text('Hello Hono!') |
|
| 55 | + | }) |
|
| 56 | + | ||
| 57 | + | app.get('/hello', async (c) => { |
|
| 58 | + | ||
| 59 | + | const data: ApiResponse = { |
|
| 60 | + | message: "Hello BHVR!", |
|
| 61 | + | success: true |
|
| 62 | + | } |
|
| 63 | + | ||
| 64 | + | return c.json(data, { status: 200 }) |
|
| 65 | + | }) |
|
| 66 | + | ||
| 67 | + | export default app; // [!code --] |
|
| 68 | + | export default { // [!code ++] |
|
| 69 | + | async fetch(request: Request, env: any, ctx: any) { // [!code ++] |
|
| 70 | + | return app.fetch(request, env, ctx) // [!code ++] |
|
| 71 | + | } // [!code ++] |
|
| 72 | + | }; // [!code ++] |
|
| 73 | + | ``` |
|
| 74 | + | ||
| 75 | + | ### Deploy Server |
|
| 76 | + | ||
| 77 | + | Move into the `server` package and run the deploy command with the server flag: |
|
| 78 | + | ||
| 79 | + | ```bash [terminal] |
|
| 80 | + | cd server |
|
| 81 | + | ||
| 82 | + | orbiter deploy --server |
|
| 83 | + | ``` |
|
| 84 | + | ||
| 85 | + | This will: |
|
| 86 | + | - Ask which site you want to link the server to (you must already have a client site deployed on Orbiter) |
|
| 87 | + | - Ask for the entry path for your server code (typically `src/index.ts`) |
|
| 88 | + | - Ask for your desired build folder (typically `dist`) |
|
| 89 | + | - Save your preferences to an `orbiter.json` file |
|
| 90 | + | - Build and bundle your server code |
|
| 91 | + | - Deploy it to Orbiter |
|
| 92 | + | ||
| 93 | + | If successful, you'll see a returned URL where you can access your API! |
|
| 94 | + | ||
| 95 | + | :::: |
|
| 96 | + | ||
| 97 | + | ## Environment Variables |
|
| 98 | + | ||
| 99 | + | If you need to use environment variables in your server, create a `.env` file with your values, then include the `--env` flag when deploying: |
|
| 100 | + | ||
| 101 | + | ```bash [terminal] |
|
| 102 | + | orbiter deploy --server --env |
|
| 103 | + | ``` |
|
| 104 | + | ||
| 105 | + | This will automatically scan your `.env` file and include the variables in the deployment. Orbiter will never be able to see your variables, so make sure they are correct! |
|
| 106 | + | ||
| 107 | + | ::::tip |
|
| 108 | + | You can also edit environment variables inside the [Orbiter App](https://app.orbiter.host) |
|
| 109 | + | :::: |
|
| 110 | + | ||
| 111 | + | ## GitHub Actions |
|
| 112 | + | ||
| 113 | + | You can set up GitHub Actions to automatically deploy your server whenever you push to your main branch. |
|
| 114 | + | ||
| 115 | + | Create a `.github/workflows/deploy.yaml` file in the root of your project: |
|
| 116 | + | ||
| 117 | + | ```bash [terminal] |
|
| 118 | + | mkdir -p .github/workflows && touch .github/workflows/deploy.yaml |
|
| 119 | + | ``` |
|
| 120 | + | ||
| 121 | + | Paste the following code into the `deploy.yaml` file: |
|
| 122 | + | ||
| 123 | + | ```yaml |
|
| 124 | + | name: "Deploy to Orbiter" |
|
| 125 | + | ||
| 126 | + | on: |
|
| 127 | + | push: |
|
| 128 | + | branches: [main] |
|
| 129 | + | ||
| 130 | + | jobs: |
|
| 131 | + | deploy: |
|
| 132 | + | runs-on: ubuntu-latest |
|
| 133 | + | steps: |
|
| 134 | + | - name: Checkout code |
|
| 135 | + | uses: actions/checkout@v4 |
|
| 136 | + | ||
| 137 | + | - name: Setup Bun |
|
| 138 | + | uses: oven-sh/setup-bun@v1 |
|
| 139 | + | with: |
|
| 140 | + | bun-version: latest |
|
| 141 | + | ||
| 142 | + | - name: Install dependencies |
|
| 143 | + | run: bun install |
|
| 144 | + | ||
| 145 | + | - name: Deploy to Orbiter |
|
| 146 | + | env: |
|
| 147 | + | ORBITER_API_KEY: ${{ secrets.ORBITER_API_KEY }} |
|
| 148 | + | run: bunx orbiter-cli@latest deploy-server --siteId YOUR_SITE_ID --entryFile src/index.ts --buildDir dist |
|
| 149 | + | ``` |
|
| 150 | + | ||
| 151 | + | Replace `YOUR_SITE_ID` with your actual site ID, which can be found by clicking the "ℹ" icon on the [Orbiter dashboard](https://app.orbiter.host). |
|
| 152 | + | ||
| 153 | + | You'll need to add your Orbiter API key as a repository secret. Navigate to GitHub project Settings > Secrets and Variables > Actions. Click `New repository secret`, then use `ORBITER_API_KEY` as the name, and paste your API key into the box below. |
|
| 154 | + | ||
| 155 | + | ## Further Reference |
|
| 156 | + | ||
| 157 | + | For more information about how to use Orbiter Functions, visit the official docs: |
|
| 158 | + | ||
| 159 | + | <Button href="https://docs.orbiter.host/functions">Orbiter Functions Docs</Button> |