بنقرة واحدة
kagaribi-deployment
Build and deploy Kagaribi packages to cloud platforms with automatic URL tracking
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Build and deploy Kagaribi packages to cloud platforms with automatic URL tracking
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | kagaribi-deployment |
| description | Build and deploy Kagaribi packages to cloud platforms with automatic URL tracking |
Guide Claude through building and deploying Kagaribi packages to production environments.
npx kagaribi build [--env environment]
Examples:
npx kagaribi build # Default environment
npx kagaribi build --env production # Production environment
npx kagaribi build --env staging # Staging environment
Output:
dist/
root/
index.js # Bundled application
wrangler.toml # (Cloudflare Workers only)
Dockerfile # (Google Cloud Run only)
users/
index.js
...
Kagaribi's deployment model enables independent deployment per package.
Each package can be deployed individually to different FaaS platforms:
users → Cloudflare Workers (fast edge response)payments → AWS Lambda (integration with existing AWS infrastructure)analytics → Google Cloud Run (suitable for batch processing)notifications → Deno Deploy (lightweight notification processing)Critical design principle:
url field in kagaribi.config.ts and connects to appropriate URLsWhy this design?
getClient<T>() automatically switches communication method based on deployment configuration:
Co-location (same process)
Distributed deployment (different FaaS)
url from kagaribi.config.tsPackages don't need to be aware of communication method.
Each package establishes its own DB connection.
Root package executes initDb(), and all packages use same DB connection via getDb():
// packages/root/src/index.ts
import { createDbMiddleware } from '@kagaribi/core';
import { initDb } from '../../../db/index.js';
const app = new Hono()
.use('*', createDbMiddleware({ initFn: initDb }));
Other packages simply call getDb():
// packages/users/src/index.ts
import { getDb, schema } from '../../../db/index.js';
app.get('/api/users', async (c) => {
const db = getDb(); // Use connection initialized by root
const users = await db.select().from(schema.users);
return c.json(users);
});
Each package independently establishes DB connection using createDbMiddleware():
// packages/users/src/index.ts (deployed to Cloudflare Workers)
import { createDbMiddleware } from '@kagaribi/core';
import { initDb, getDb, schema } from '../../../db/index.js';
const app = new Hono()
// Auto-initialize with middleware
.use('*', createDbMiddleware({ initFn: initDb }))
.get('/api/users', async (c) => {
const db = getDb();
const users = await db.select().from(schema.users);
return c.json(users);
});
Connection string management via environment variables:
DATABASE_URL environment variable at each deployment destinationcreateDbMiddleware() automatically reads environment variableprocess.env.DATABASE_URLc.env.DATABASE_URL (via bindings)Important: All packages connect to the same database, but connections are established individually per package.
Without explicit target or environment flags, shows deployment instructions:
npx kagaribi deploy
npx kagaribi deploy users
npx kagaribi deploy --dry-run
Output: Platform-specific commands and setup instructions (does not deploy).
Specify target platform or environment to perform actual deployment:
# Deploy specific package to target
npx kagaribi deploy users --cloudflare
npx kagaribi deploy payments --lambda
npx kagaribi deploy api --cloudrun
# Deploy all undeployed packages to target
npx kagaribi deploy --cloudflare
npx kagaribi deploy --lambda
# Deploy using environment configuration
npx kagaribi deploy --env production
npx kagaribi deploy --env staging
After successful deployment, kagaribi.config.ts is automatically updated
with the deployed URL.
Required tool: wrangler
npm install -g wrangler
wrangler login
Deploy command:
kagaribi deploy users --cloudflare
What happens:
dist/users/wrangler.tomlwrangler deploy from dist/users/kagaribi.config.ts with deployed URLEnvironment variables:
Configure in wrangler.toml:
[env.production.vars]
DATABASE_URL = "postgresql://..."
Using Cloudflare D1:
D1 is configured as a binding (not an environment variable). Add the binding to wrangler.toml:
[[d1_databases]]
binding = "DB" # Referenced in code as c.env.DB
database_name = "my-database"
database_id = "xxxx-xxxx-xxxx-xxxx" # Obtained from wrangler d1 create output
Migrations must be applied using wrangler d1 migrations apply (not drizzle-kit migrate):
npx wrangler d1 migrations apply my-database --local # Apply locally for testing
npx wrangler d1 migrations apply my-database # Apply to production
Required tool: aws CLI
Required environment variable: AWS_LAMBDA_ROLE_ARN
# Install AWS CLI
brew install awscli # or appropriate package manager
aws configure
# Set Lambda execution role ARN
export AWS_LAMBDA_ROLE_ARN=arn:aws:iam::123456789012:role/lambda-execution-role
Deploy command:
kagaribi deploy payments --lambda
What happens:
dist/payments/index.jskagaribi.config.ts with function URLEnvironment variables:
aws lambda update-function-configuration \
--function-name payments \
--environment Variables={DATABASE_URL=postgresql://...}
Required tool: gcloud CLI
Required environment variable: CLOUD_RUN_REGION (optional, defaults to us-central1)
# Install gcloud CLI
brew install google-cloud-sdk
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
# Set region (optional)
export CLOUD_RUN_REGION=asia-northeast1
Deploy command:
kagaribi deploy api --cloudrun
What happens:
dist/api/Dockerfilekagaribi.config.ts with service URLEnvironment variables:
gcloud run services update api \
--set-env-vars DATABASE_URL=postgresql://...
Required tool: deployctl
npm install -g deployctl
Deploy command:
kagaribi deploy notifications --deno
What happens:
dist/notifications/index.js to Deno Deploykagaribi.config.ts with deployed URLNo special tools required - Use your preferred deployment method.
kagaribi build --env production
Deploy to server:
# Copy dist/ directory to server
scp -r dist/ user@server:/app/
# On server, run with Node.js
cd /app/dist/root
node index.js
With PM2:
pm2 start dist/root/index.js --name my-app
pm2 save
With systemd:
Create /etc/systemd/system/my-app.service:
[Unit]
Description=Kagaribi App
[Service]
ExecStart=/usr/bin/node /app/dist/root/index.js
WorkingDirectory=/app/dist/root
Restart=always
Environment=DATABASE_URL=postgresql://...
[Install]
WantedBy=multi-user.target
Co-location bundles multiple packages into a single deployment for simpler infrastructure.
// kagaribi.config.ts
export default defineConfig({
packages: {
root: {
target: 'node',
},
auth: {
colocateWith: 'root', // Bundled with root
},
users: {
colocateWith: 'root', // Bundled with root
},
payments: {
target: 'aws-lambda', // Deployed separately
url: 'https://payments.example.com',
},
},
});
Benefits:
When to use:
When to deploy separately:
After deployment, kagaribi.config.ts is automatically updated:
Before deployment:
export default defineConfig({
packages: {
users: {
target: 'cloudflare-workers',
},
},
});
After kagaribi deploy users --cloudflare:
export default defineConfig({
packages: {
users: {
target: 'cloudflare-workers',
url: 'https://users.your-project.workers.dev', // Auto-added
},
},
});
This enables:
Define multiple environments in kagaribi.config.ts:
export default defineConfig({
packages: {
root: { target: 'node' },
},
environments: {
development: {
packages: {
'*': { colocateWith: 'root' }, // All local
},
},
staging: {
packages: {
users: {
target: 'cloudflare-workers',
url: '$STAGING_USERS_URL',
},
payments: {
target: 'aws-lambda',
url: '$STAGING_PAYMENTS_URL',
},
},
},
production: {
packages: {
users: {
target: 'cloudflare-workers',
url: '$PROD_USERS_URL',
},
payments: {
target: 'aws-lambda',
url: '$PROD_PAYMENTS_URL',
},
},
},
},
});
Deploy to specific environment:
# Set environment variables
export PROD_USERS_URL=https://users.prod.example.com
export PROD_PAYMENTS_URL=https://payments.prod.example.com
# Deploy
kagaribi deploy --env production
Set DATABASE_URL for each platform:
Cloudflare Workers (wrangler.toml):
[env.production.vars]
DATABASE_URL = "postgresql://user:pass@host/db"
AWS Lambda:
aws lambda update-function-configuration \
--function-name my-function \
--environment Variables={DATABASE_URL=postgresql://...}
Google Cloud Run:
gcloud run services update my-service \
--set-env-vars DATABASE_URL=postgresql://...
Node.js (.env or environment):
export DATABASE_URL=postgresql://user:pass@host:5432/db
node dist/root/index.js
Run migrations before deploying application code:
# Local or CI/CD environment
pnpm run db:migrate
In CI/CD:
# Example: GitHub Actions
- name: Run migrations
run: pnpm run db:migrate
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Deploy
run: kagaribi deploy --env production
Build the project:
kagaribi build --env production
Deploy packages:
# Deploy users to Cloudflare Workers
kagaribi deploy users --cloudflare
# Deploy payments to AWS Lambda
export AWS_LAMBDA_ROLE_ARN=arn:aws:iam::123456789012:role/lambda-role
kagaribi deploy payments --lambda
# Deploy API to Google Cloud Run
export CLOUD_RUN_REGION=us-central1
kagaribi deploy api --cloudrun
Verify deployments:
curl https://users.your-project.workers.dev/health
curl https://payments-xyz.lambda-url.us-east-1.on.aws/health
curl https://api-xyz.run.app/health
Check configuration:
cat kagaribi.config.ts
# Verify URLs are auto-updated
npx kagaribi dev before deploying/health endpoints in all packagesIssue: Authentication error during deployment
wrangler login, aws configure, gcloud auth login)Issue: AWS Lambda deployment fails with missing role
AWS_LAMBDA_ROLE_ARN environment variableIssue: Cloud Run deployment fails
gcloud config get-value projectIssue: RPC calls to deployed package fail
url in kagaribi.config.ts and verify service is runningIssue: Database connection fails in production
DATABASE_URL is correctly set for the deployment platformAfter deployment: