Vercel Setup Guide: Step-by-Step¶
This document provides a step-by-step guide for setting up your app Vercel project, configuring environments, and managing necessary credentials for deployment via GitHub Actions.
Part 1: Initial Vercel Project Setup (If Not Already Done)¶
If you haven't already created a Vercel project for your app application:
- Sign up/Log in to Vercel: Go to vercel.com and sign up or log in, preferably using your GitHub account.
- Import Project:
- From your Vercel dashboard, click "Add New..." > "Project".
- Import Git Repository: Select your GitHub repository where this monorepo resides. You may need to grant Vercel access to your repositories if you haven't already.
- Configure Project:
- Select Root Directory: This is crucial for monorepos. When Vercel asks for the "Root Directory," click the "Edit" button next to it and change it from the repository root to
packages/app. - Framework Preset: Vercel should automatically detect "Next.js".
- Project Name: Give your project a name on Vercel (e.g.,
delta-app). - Build and Output Settings: Defaults are usually fine for Next.js.
- Environment Variables: You can add these now or later (see Part 3).
- Select Root Directory: This is crucial for monorepos. When Vercel asks for the "Root Directory," click the "Edit" button next to it and change it from the repository root to
- Deploy: Click "Deploy". Vercel will attempt an initial deployment.
Part 2: Finding Essential Vercel IDs and Creating an Access Token¶
These are needed for your GitHub Actions workflows.
2.1. Finding Your Vercel Organization ID (VERCEL_ORG_ID)
- If using a Vercel Team:
- Go to your Vercel Dashboard.
- Select your Team from the scope selector (top-left).
- Navigate to the team's Settings tab.
- The Organization ID (Team ID) is usually visible here or in the URL (e.g.,
vercel.com/teams/YOUR_TEAM_SLUG/...). - If using a Personal Account (Hobby plan): The
orgIdmight correspond to your user ID. - Reliable Method (using Vercel CLI after linking):
- Install Vercel CLI:
npm install -g vercel - Login:
vercel login - Navigate to your local repository root:
cd /path/to/your/delta-project - Link the project:
vercel link(follow prompts, select existing project, set root topackages/app). - Inspect the generated file:
cat .vercel/project.json. This file will containorgId. Store this value for theVERCEL_ORG_IDGitHub Variable.
2.2. Finding Your Vercel Project ID (VERCEL_PROJECT_ID)
- Via Vercel Dashboard:
- Go to your Vercel Dashboard.
- Select your
appproject. - Navigate to the project's Settings tab.
- Under the General section, scroll down to find the Project ID (usually starts with
prj_). - Via Vercel CLI (after linking, as above):
- The
projectIdis also present in the.vercel/project.jsonfile. Store this value for theVERCEL_PROJECT_IDGitHub Variable.
2.3. Creating a Vercel Access Token (VERCEL_TOKEN)
- Go to your Vercel Dashboard.
- Click on your avatar/profile icon (top-right) > Settings.
- In the left sidebar, under "Personal Account" or your "Team Settings", click on Tokens.
- Click "Create".
- Token Name: Descriptive, e.g.,
GitHub Actions - Delta App. - Scope: Select the appropriate scope (your account or the specific team owning the project).
- Expiration: Choose an appropriate duration (e.g., 1 year, or "No Expiration" with a plan to rotate manually).
- Token Name: Descriptive, e.g.,
- Click "Create Token".
- Immediately copy the generated token value. Vercel will only show it once.
Store this value for the
VERCEL_TOKENGitHub Secret. This token will be used for both production and staging deployments as configured in the workflows.
Part 3: Configuring Environment Variables in Vercel¶
Set these directly in your Vercel Project's UI.
- Go to your Vercel Dashboard.
- Select your
appproject. - Navigate to Settings > Environment Variables.
You need to add variables for Production, Preview (for staging), and optionally Development environments.
For EACH variable listed below, add it for the "Production" environment and then add it again for the "Preview" environment (with potentially different values for staging).
- Variable Name (in Vercel UI):
NEXT_PUBLIC_SUPABASE_URL - Value (Production): Your production Supabase project URL.
- Value (Preview/Staging): Your staging Supabase project URL.
- Type: Plaintext. Ensure "All Environments" or specific ones are checked. (Available to Browser)
- Variable Name:
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY - Value (Production): Your production Supabase anon key.
- Value (Preview/Staging): Your staging Supabase anon key.
- Type: Secret. (Available to Browser - Vercel will warn; this is expected for this specific key).
- Variable Name:
SUPABASE_SECRET_KEY - Value (Production): Your production Supabase service role key.
- Value (Preview/Staging): Your staging Supabase service role key.
- Type: Secret. Crucially, ensure this is NOT exposed to the browser (do not check "Available to Browser" if Vercel UI has such an option, or ensure it's not prefixed
NEXT_PUBLIC_). - Variable Name:
AIHUB_API_GATEWAY_URL - Value (Production): URL of your production
aiHubservice. - Value (Preview/Staging): URL of your staging
aiHubservice. - Type: Secret. (Server-side only)
- Variable Name:
AIHUB_CUSTOM_SHARED_KEY(App sends to aiHub) - Value (Production): Unique secret string for production.
- Value (Preview/Staging): Unique secret string for staging.
- Type: Secret. (Server-side only)
- Variable Name:
VERCEL_AUTHORIZATION_API_KEY(App expects from aiHub) - Value (Production): Unique secret string for production (must match what prod aiHub sends).
- Value (Preview/Staging): Unique secret string for staging (must match what staging aiHub sends).
- Type: Secret. (Server-side only)
- Variable Name:
LOKI_URL - Value (Production): Your production Loki URL.
- Value (Preview/Staging): Your staging Loki URL.
- Type: Secret. (Server-side only)
- Variable Name:
LOKI_USER - Value (Production/Staging): Loki username (if auth enabled).
- Type: Secret. (Server-side only)
- Variable Name:
LOKI_PASSWORD - Value (Production/Staging): Loki password (if auth enabled).
- Type: Secret. (Server-side only)
- Variable Name:
SEND_DEV_LOGS_TO_LOKI - Value (Production):
false - Value (Preview/Staging):
trueorfalseas desired. - Type: Plaintext. (Server-side only)
- Variable Name:
NEXT_PUBLIC_SEND_DEV_LOGS_TO_LOKI - Value (Production):
false - Value (Preview/Staging):
trueorfalseas desired. - Type: Plaintext. (Client-side logging control)
(Note: NODE_ENV is typically set automatically by Vercel.)
Part 4: GitHub Variables and Secrets for Workflow Execution¶
Your GitHub Actions workflows use a combination of Variables (for non-sensitive IDs) and Secrets (for sensitive tokens) to interact with Vercel.
- Navigate to your GitHub repository.
-
Go to Settings > Secrets and variables > Actions.
-
Configure Variables:
- Under the "Variables" tab, click "New repository variable" for each:
VERCEL_ORG_ID: (Value from step 2.1)VERCEL_PROJECT_ID: (Value from step 2.2)
-
Configure Secrets:
- Under the "Secrets" tab, click "New repository secret" for:
VERCEL_TOKEN: (Value from step 2.3)
How it all connects:
- The GitHub Actions use
VERCEL_ORG_ID(from vars),VERCEL_PROJECT_ID(from vars), andVERCEL_TOKEN(from secrets) to interact with your Vercel project (link, pull settings, trigger builds/deploys). - The
vercel pullcommand in the workflow fetches the application-specific environment variables (likeNEXT_PUBLIC_SUPABASE_URL) that you configured in the Vercel UI (Part 3) into the build environment of the GitHub Action. - Your Next.js application code (
process.env.NEXT_PUBLIC_SUPABASE_URL) then uses these values during build and runtime.
Part 5: Configuring Vercel Deployment Protection for API Access¶
To ensure that your Vercel-deployed app APIs can be securely accessed by other services (like your aiHub service running on Fargate) without exposing them publicly, you need to configure Vercel's Deployment Protection. This involves enabling standard Vercel Authentication and then setting up a bypass secret for automation.
The aiHub service is configured to send a specific header x-vercel-protection-bypass with the value of the VERCEL_AUTOMATION_BYPASS_SECRET when calling Vercel APIs. You can refer to packages/aiHub/src/index.ts for an example of how this header is implemented.
5.1. Accessing Deployment Protection Settings
- Go to your Vercel Dashboard.
- Select your
appproject (e.g.,deltaordelta-app). - Navigate to the project's Settings tab.
- In the left sidebar, click on Deployment Protection.
(Example URL provided by user:
https://vercel.com/chris-parkers-projects-e12d04e3/delta/settings/deployment-protection. Adaptchris-parkers-projects-e12d04e3to your Vercel team/username anddeltato your Vercel project name.) (General Vercel documentation: https://vercel.com/docs/deployment-protection)
5.2. Enabling Vercel Authentication
- Under the "Deployment Protection" section, ensure that Vercel Authentication is selected as the "Standard Protection" method. This is usually the default. If it's set to "No protection" or another method, change it to "Vercel Authentication".
5.3. Setting up Protection Bypass for Automation
- Scroll down to the Protection Bypass for Automation section.
- Click the "Create Secret" button (or similar, the UI might vary slightly).
- Secret Name: Give it a descriptive name, for example,
AIHUB_BYPASS_SECRET. (This name is for your reference in the Vercel UI and does not need to match the environment variable name used byaiHub). - Secret Value:
- This is the crucial part. The value you enter here must match the value of the
VERCEL_AUTOMATION_BYPASS_SECRETenvironment variable that youraiHubservice (and other automated services) will use. - This
VERCEL_AUTOMATION_BYPASS_SECRETshould be securely stored (e.g., as a GitHub repository secret if youraiHubdeployment process pulls it from there, or directly in your Fargate task definition's environment variables). - Important: Generate a strong, unique secret for this purpose.
- This is the crucial part. The value you enter here must match the value of the
- Click "Add" or "Create".
5.4. How it Works
- When Vercel Authentication is active, direct access to your deployment URLs (including API routes) will require Vercel login.
- Services like
aiHubcan bypass this authentication by including thex-vercel-protection-bypassheader with the correct secret value you just configured in Vercel's "Protection Bypass for Automation" setting. - The
VERCEL_AUTOMATION_BYPASS_SECRETenvironment variable (used byaiHub) provides the value for this header.
Note: The VERCEL_AUTOMATION_BYPASS_SECRET itself is managed outside of Vercel's environment variables for the app project. It's a secret known by the calling service (aiHub) and its value is what you configure in Vercel's "Protection Bypass for Automation" setting.