From c1a1dc1bad3726a5a743e7d63ef0450fd26290ff Mon Sep 17 00:00:00 2001 From: uchidayuma Date: Tue, 2 Jun 2026 09:18:28 +0900 Subject: [PATCH] demo server move to fly.io --- .dockerignore | 15 +++++++++++++++ .gitignore | 1 + Dockerfile.demo | 1 + README.ja.md | 2 +- README.md | 2 +- fly.demo.toml | 31 +++++++++++++++++++++++++++++++ packages/server/src/db/client.ts | 7 ++++++- 7 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 fly.demo.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9d80e16 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +# flyctl launch added from .gitignore +**/node_modules +**/dist +**/.env +**/.env.* +**/data/*.db +**/data/*.db-shm +**/data/*.db-wal +**/models +**/*.tsbuildinfo +**/.claude/settings.local.json +**/*.draft.*.md +**/.claude/agent-memory +**/docs/launch +fly.toml diff --git a/.gitignore b/.gitignore index 6bb152d..f8cbc27 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ models/ .claude/settings.local.json *.draft.*.md .claude/agent-memory/ +docs/launch \ No newline at end of file diff --git a/Dockerfile.demo b/Dockerfile.demo index 2329e74..3890a61 100644 --- a/Dockerfile.demo +++ b/Dockerfile.demo @@ -30,6 +30,7 @@ RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \ COPY --from=builder /app/packages/server/dist ./packages/server/dist COPY --from=builder /app/packages/web/dist ./public +COPY --from=builder /app/packages/server/drizzle ./packages/server/drizzle RUN mkdir -p /app/data VOLUME ["/app/data"] diff --git a/README.ja.md b/README.ja.md index 97480d7..d26c403 100644 --- a/README.ja.md +++ b/README.ja.md @@ -43,7 +43,7 @@ https://github.com/user-attachments/assets/f1423bed-72e4-48d6-916a-8123d4bdfe38 ## ライブデモ -**インストール不要で試せます:** [personal-context.onrender.com](https://personal-context.onrender.com/) +**インストール不要で試せます:** [personal-context-demo.fly.dev/](https://personal-context-demo.fly.dev/) > **注意:** デモはRenderの無料プランで動いています。しばらくアクセスがなかった場合、初回表示まで **約30秒** かかることがあります。これは正常な動作です。 > diff --git a/README.md b/README.md index 0301dbd..18f365b 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ https://github.com/user-attachments/assets/9ab712f0-1af2-4b5f-9ca0-df786cd25fdb ## Live Demo -**Try it without installing anything:** [personal-context.onrender.com](https://personal-context.onrender.com/) +**Try it without installing anything:** [personal-context-demo.fly.dev/](https://personal-context-demo.fly.dev/) > **Note:** The demo runs on Render's free tier. If the service has been idle, it will take **~30 seconds to wake up** on first visit — this is normal. Just wait for the app to load. > diff --git a/fly.demo.toml b/fly.demo.toml new file mode 100644 index 0000000..9266818 --- /dev/null +++ b/fly.demo.toml @@ -0,0 +1,31 @@ +# fly.toml app configuration file generated for personal-context on 2026-06-02T08:42:44+09:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'personal-context-demo' +primary_region = 'sjc' + +[build] + dockerfile = "Dockerfile.demo" + +[env] + NODE_ENV = "production" + DEMO_MODE = "true" + +[mounts] + source = "context_data" + destination = "/app/data" # SQLiteファイルが保存されるパス + +[http_service] + internal_port = 3001 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 diff --git a/packages/server/src/db/client.ts b/packages/server/src/db/client.ts index ba72793..20f9234 100644 --- a/packages/server/src/db/client.ts +++ b/packages/server/src/db/client.ts @@ -5,6 +5,7 @@ import * as schema from './schema.js' import type { Db } from '../types.js' import path from 'path' import fs from 'fs' +import { fileURLToPath } from 'url' import { migrate } from 'drizzle-orm/libsql/migrator' const DB_PATH = process.env.DB_PATH ?? path.join(process.cwd(), 'data', 'personal_context.db') @@ -18,7 +19,11 @@ const simulateClient = createClient({ url: `file:${SIMULATE_DB_PATH}` }) export const db = drizzle(client, { schema }) export const simulateDb = drizzle(simulateClient, { schema }) -const DRIZZLE_FOLDER = new URL('../../drizzle', import.meta.url).pathname +// dev (tsx): import.meta.url = src/db/client.ts → ../../drizzle = packages/server/drizzle ✓ +// prod (tsup bundle): import.meta.url = dist/index.js → ../drizzle = packages/server/drizzle ✓ +const DRIZZLE_FOLDER = process.env.NODE_ENV === 'production' + ? fileURLToPath(new URL('../drizzle', import.meta.url)) + : fileURLToPath(new URL('../../drizzle', import.meta.url)) export async function initDatabase() { await migrate(db, { migrationsFolder: DRIZZLE_FOLDER })