-
Notifications
You must be signed in to change notification settings - Fork 0
Rename server to API and enhance Alchemy integration #45
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9b5f730
chore: rename apps/server to apps/api
ahargunyllib 6873db5
chore: migrate to alchemy for api
ahargunyllib 7a71a8f
feat: update alchemy configuration and scripts for API development
ahargunyllib bf73f4f
feat: enhance alchemy integration with state management and update en…
ahargunyllib a578e6a
feat: add GitHub Actions workflow for API deployment and integrate al…
ahargunyllib de17951
chore: remove bun.lock
ahargunyllib 7558fc7
feat: set NODE_ENV to production in deployment workflow
ahargunyllib 62441ba
fix: update repository name in GitHub comment for preview deployment
ahargunyllib 80bb5ac
feat: update pull request event types and fix commit SHA reference in…
ahargunyllib 1247f5d
feat: remove unused destroy and deploy scripts from package.json
ahargunyllib da617c4
feat: add health check endpoint to the API
ahargunyllib 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
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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| name: API Deployment | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "apps/api/**" | ||
| - "packages/**" | ||
| - "package.json" | ||
| - "pnpm-lock.yaml" | ||
| - "!**/*.md" | ||
| - "!**/README*" | ||
|
|
||
| concurrency: | ||
| group: preview-${{ github.event.pull_request.number }}-${{ github.sha }} | ||
| cancel-in-progress: false | ||
|
|
||
| env: | ||
| STAGE: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || (github.ref == 'refs/heads/main' && 'prod' || github.ref_name) }} | ||
ahargunyllib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| deploy: | ||
| if: ${{ github.event.action != 'closed' }} | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v5 | ||
| with: | ||
| version: "10.14.0" | ||
|
|
||
| - name: Cache pnpm store | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ~/.pnpm-store | ||
ahargunyllib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pnpm-store- | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Deploy | ||
| working-directory: apps/api | ||
| run: pnpm dlx alchemy deploy --stage ${{ env.STAGE }} | ||
| env: | ||
| ALCHEMY_PASSWORD: ${{ secrets.ALCHEMY_PASSWORD }} | ||
| ALCHEMY_STATE_TOKEN: ${{ secrets.ALCHEMY_STATE_TOKEN }} | ||
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| CLOUDFLARE_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }} | ||
| PULL_REQUEST: ${{ github.event.number }} | ||
| GITHUB_SHA: ${{ github.sha }} | ||
ahargunyllib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| NODE_ENV: production | ||
ahargunyllib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cleanup: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }} | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v5 | ||
| with: | ||
| version: "10.14.0" | ||
|
|
||
| - name: Cache pnpm store | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ~/.pnpm-store | ||
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pnpm-store- | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Safety Check | ||
| run: |- | ||
| if [ "${{ env.STAGE }}" = "prod" ]; then | ||
| echo "ERROR: Cannot destroy prod environment in cleanup job" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Destroy Preview Environment | ||
| working-directory: apps/api | ||
| run: pnpm dlx alchemy destroy --stage ${{ env.STAGE }} | ||
| env: | ||
| ALCHEMY_PASSWORD: ${{ secrets.ALCHEMY_PASSWORD }} | ||
| ALCHEMY_STATE_TOKEN: ${{ secrets.ALCHEMY_STATE_TOKEN }} | ||
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
| CLOUDFLARE_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }} | ||
| PULL_REQUEST: ${{ github.event.number }} | ||
| NODE_ENV: production | ||
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 |
|---|---|---|
|
|
@@ -263,3 +263,6 @@ $RECYCLE.BIN/ | |
|
|
||
| # Wrangler | ||
| *.wrangler | ||
|
|
||
| # Alchemy | ||
| *.alchemy | ||
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,3 @@ | ||
| # openssl rand -base64 32 | ||
| ALCHEMY_STATE_TOKEN=your-generated-token-here | ||
| ALCHEMY_PASSWORD=your-generated-password-here |
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,58 @@ | ||
| import alchemy from "alchemy"; | ||
| import { Worker } from "alchemy/cloudflare"; | ||
| import { GitHubComment } from "alchemy/github"; | ||
| import { CloudflareStateStore } from "alchemy/state"; | ||
|
|
||
| const app = await alchemy("realm-api", { | ||
| stateStore: | ||
| process.env.NODE_ENV === "production" | ||
| ? (scope) => | ||
| new CloudflareStateStore(scope, { | ||
| scriptName: "realm-api-state-store", | ||
| }) | ||
| : undefined, // Uses default FileSystemStateStore | ||
| password: process.env.ALCHEMY_PASSWORD, | ||
| }); | ||
|
|
||
| export const worker = await Worker("api", { | ||
| name: "realm-api", | ||
| entrypoint: "./src/index.ts", | ||
| url: true, | ||
| adopt: true, | ||
| bindings: {}, | ||
| observability: { | ||
| enabled: true, | ||
| logs: { | ||
| enabled: true, | ||
| headSamplingRate: 1, | ||
| invocationLogs: true, | ||
| persist: true, | ||
| }, | ||
| traces: { | ||
| enabled: true, | ||
| headSamplingRate: 1, | ||
| persist: true, | ||
| }, | ||
| }, | ||
| domains: ["api.ahargunyllib.dev"], | ||
| dev: { | ||
| port: 3000, | ||
| }, | ||
| }); | ||
|
|
||
| if (process.env.PULL_REQUEST) { | ||
| // if this is a PR, add a comment to the PR with the preview URL | ||
| // it will auto-update with each push | ||
| await GitHubComment("preview-comment", { | ||
| owner: "ahargunyllib", | ||
| repository: "ahargunyllib/realm", | ||
| issueNumber: Number(process.env.PULL_REQUEST), | ||
| body: `### Preview Deployment | ||
|
|
||
| **Commit:** \`${process.env.COMMIT_SHA}\` | ||
| **Preview URL:** ${`https://${worker.url}`} | ||
| **Deployed at:** ${new Date().toUTCString()}`, | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| await app.finalize(); | ||
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,19 @@ | ||
| { | ||
| "name": "api", | ||
| "type": "module", | ||
| "version": "0.0.1", | ||
| "scripts": { | ||
| "typecheck": "tsc --noEmit", | ||
| "dev": "alchemy dev --app realm-api", | ||
| "destroy": "NODE_ENV=production alchemy destroy --app realm-api", | ||
| "deploy": "NODE_ENV=production alchemy deploy --app realm-api" | ||
| }, | ||
| "dependencies": { | ||
| "alchemy": "catalog:", | ||
| "hono": "^4.7.9" | ||
| }, | ||
| "devDependencies": { | ||
| "@realm/tsconfig": "workspace:*", | ||
| "typescript": "catalog:" | ||
| } | ||
| } |
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,3 @@ | ||
| import type { worker } from "../alchemy.run"; | ||
|
|
||
| export type Env = typeof worker.bindings; |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.