5.7 KiB
description
| description |
|---|
| Bootstrap a repository with Vercel-linked resources by running preflight checks, provisioning integrations, verifying env keys, and then executing db/dev startup commands safely. |
Vercel Project Bootstrap
Run a deterministic bootstrap flow for new or partially configured repositories.
Preflight
- Confirm Vercel CLI is installed and authenticated.
vercel --version
vercel whoami
- Confirm repo linkage by checking
.vercel/project.json. - If not linked, inspect available teams/projects before asking the user to choose:
vercel teams ls
vercel projects ls --scope <team>
vercel link --yes --scope <team> --project <project>
- Find the env template in priority order:
.env.example,.env.sample,.env.template. - Create local env file if missing:
cp .env.example .env.local
- Detect package manager and available scripts (
db:push,db:seed,db:migrate,db:generate,dev) frompackage.json. - Inspect auth/database signals (
prisma/schema.prisma,drizzle.config.*,auth.*,src/**/auth.*) to scope bootstrap details.
Stop with clear guidance if CLI auth or linkage fails.
Plan
Execute in this order:
- Preflight validation and project linking.
- Resource provisioning (prefer Vercel-managed Neon integration).
- Secret/bootstrap env setup (
AUTH_SECRET, env pull, key verification). - Application bootstrap (
db:*thendev) only after env checks pass.
- Do not run
db:push,db:migrate,db:seed, ordevuntil Vercel linking is complete and env keys are verified. - Prefer Vercel-managed provisioning (
vercel integration ...) for shared resources. - Use provider CLIs only as fallback when Vercel integration flow is unavailable.
- Never echo secret values in terminal output, logs, or summaries.
Commands
1. Link + local env template
Copy the first matching template file only if .env.local does not exist:
cp .env.example .env.local
If .env.example is absent, use .env.sample or .env.template.
2. Provision Postgres
Preferred path (Vercel-managed Neon)
- Read integration setup guidance:
vercel integration guide neon
- Add Neon integration to the Vercel scope:
vercel integration add neon --scope <team>
- Verify expected environment variable names exist in Vercel and pull locally:
vercel env ls
vercel env pull .env.local --yes
Fallback path 1 (Dashboard)
- Provision Neon through the Vercel dashboard integration UI.
- Re-run
vercel env pull .env.local --yes.
Fallback path 2 (Neon CLI)
Use Neon CLI only when Vercel-managed provisioning is unavailable. After creating resources, add required env vars in Vercel and pull again.
3. Generate and store AUTH_SECRET
Generate a high-entropy secret without printing it, then store it in Vercel and refresh local env:
AUTH_SECRET="$(node -e "console.log(require('node:crypto').randomBytes(32).toString('base64url'))")"
printf "%s" "$AUTH_SECRET" | vercel env add AUTH_SECRET development preview production
unset AUTH_SECRET
vercel env pull .env.local --yes
4. Verify required env keys
Compare required keys from template file against .env.local keys (names only, never values):
template_file=""
for candidate in .env.example .env.sample .env.template; do
if [ -f "$candidate" ]; then
template_file="$candidate"
break
fi
done
comm -23 \
<(grep -E '^[A-Za-z_][A-Za-z0-9_]*=' "$template_file" | cut -d '=' -f 1 | sort -u) \
<(grep -E '^[A-Za-z_][A-Za-z0-9_]*=' .env.local | cut -d '=' -f 1 | sort -u)
Proceed only when missing key list is empty.
Do not continue if any required keys are missing.
5. Run app bootstrap commands (after verification)
After linkage + env verification:
npm run db:push
npm run db:seed
npm run dev
Use the repository package manager (npm, pnpm, bun, or yarn) and run only scripts that exist in package.json.
Verification
Confirm each checkpoint:
vercel whoamisucceeds..vercel/project.jsonexists and matches chosen project.- Postgres integration path completed (Vercel integration, dashboard, or provider CLI fallback).
vercel env pull .env.local --yessucceeds.- Required env key diff is empty.
- Database command status is recorded (
db:push,db:seed,db:migrate,db:generateas applicable). devcommand starts without immediate config/auth/env failure.
If verification fails, stop and report exact failing step plus remediation.
Summary
Return a final bootstrap summary in this format:
## Bootstrap Result
- **Linked Project**: <team>/<project>
- **Resource Path**: vercel-integration-neon | dashboard-neon | neon-cli
- **Env Keys**: <count> required, <count> present, <count> missing
- **Secrets**: AUTH_SECRET set in Vercel (value never shown)
- **Migration Status**: not-run | success | failed (<step>)
- **Dev Result**: not-run | started | failed
Next Steps
- If env keys are still missing, add the missing keys in Vercel and re-run
vercel env pull .env.local --yes. - If DB commands fail, fix connectivity/schema issues and re-run only the failed db step.
- If
devfails, resolve runtime errors, then restart with your package manager'srun dev.