Deployment to Vercel
ACAP Bicol started deploying its Node backend to Vercel along with the official Render deployment starting in its 2.0 version, aiming to achieve faster API response times than its (standard-pricing) Render-deployed APIs that experience 30 secs - 1 minute cold starts specifically for its ACAP-RMCAS APIs.
ACAP does not officially endorse deployment to Vercel nor activation of the ACAP-RMCAS APIs for other regions. Therefore, no step-by-step video guides demonstrate its initialization and usage, unlike the supported Render [1] (opens in a new tab) [2] (opens in a new tab) deployment.
The Vercel deployment and new API endpoints (also accessible in the official Render deployment, if activated) are only for the prototype development purposes of sharing ACAP Bicol's internal PAGASA-sourced weather forecast data with collaborators, which needed to start using unified data sources and processes from July 2024, with an option to be activated by other regions upon request by the DA.
All ACAP Node REST APIs (except for PDF bulletin creation) are supported in its Vercel deployment.
While ACAP does not officially endorse and encourage deployment to Vercel, interested developers can also explore setting up and using its deployment for study purposes.
To ensure smooth integration with the existing ACAP 1.0 deployments other than ACAP Bicol, the Vercel deployment and activation of the ACAP-RCMAS APIs are made into optional features for ACAP 2.0 that can be triggered by supplying certain backend environment variables and GitHub Secrets/Variables.
The following steps describe how ACAP configures the Vercel CLI and GitHub Actions for building and deploying its NodeJS Express server app to Vercel for reference.
Vercel Requirements
- Vercel account
ℹ️
ACAP Bicol uses a standard-tier Vercel account pricing plan, which limits sharing its Vercel apps to only one (1) developer.
- Vercel CLI (opens in a new tab)
- Installed locally
- For reference, ACAP is using the v28.16.7 version.
- ACAP uses the Vercel CLI (opens in a new tab) in GitHub Actions to deploy its Node backend to Vercel to avoid linking the code repository to Vercel. Using the Vercel CLI is one of the three (3) supported methods (opens in a new tab) for deploying apps to Vercel.
- Node
- Node v16.14.2 (or ACAP's latest declared Node version)
Initialize Dependencies
Prepare the local PC or laptop for Vercel deployment.
-
Create a Vercel Access Token.
- Login to Vercel.
- Create a Vercel Access Token in Profile Icon -> Account Settings -> Tokens named
VERCEL_TOKEN
, selecting the"No Expiration"
option.
-
Install Vercel CLI globally if it's not installed on the local development PC or laptop.
- You can try installing the
@latest
CLI version and revert to v28.16.7 (used by ACAP) if the steps following the global installation fail. - Install the CLI version used by ACAP.
npm i -g vercel@28.16.7
- You can try installing the
Development App Initialization
These steps will initialize an ACAP server app for deployment to the "DEVELOPMENT" Vercel environment.
Repeat the following steps to initialize an ACAP server app for deployment to the "PRODUCTION" Vercel environment under the Production App Initialization section.
Initialize the ACAP Development Vercel App
-
Login using the Vercel CLI
vercel login
-
Navigate to the acap-v2/server directory using a terminal. Run the command to create a new Vercel project.
vercel link
-
Answer the required prompts:
- Set up "path/to/acap-v2/server"? [Y/n]: Press Enter
- Which scope should contain your project? Press Enter to select the default
- Link to existing project? [y/N]: Press Enter (n)
- What's your project's name?: Type any app name (e.g., "acap-dev") and press Enter
- In which directory is your code located? ./: Press Enter to select the ./ default
- Other info prompts:
Local settings detected in vercel.json: No framework detected. Default Project Settings: ...
- Want to modify these settings? [y/N] n: Press Enter (n)
-
Take note of the
projectId
andorgId
values from theproject.json
file inside the generated.vercel
folder.Add these "DEVELOPMENT" Vercel values in the forked ACAPs' GitHub Secrets as:
VERCEL_TOKEN=(Use the VERCEL_TOKEN value from step #1) VERCEL_ORG_ID=(value of orgId) VERCEL_PROJECT_ID_DEV=(value of projectId) VERCEL_APP_DEV=(name of the "DEVELOPMENT" Vercel app)
-
Confirm the creation of an empty Vercel app with the project name from the prompt in the Vercel account's projects dashboard.
-
Go to (Vercel Project) -> Settings -> Environment Variables. Set the environment variables similar to the "DEVELOPMENT" Render Environment Variables.
⚠️Ensure similar environment variables and values in the "DEVELOPMENT" Render deployment with the Vercel Environment variables. Set the value:
DEPLOYMENT_PLATFORM=vercel
-
Set the development Vercel app's Runtime to Node 16.x.
- Go to the (Vercel Project) -> Settings -> General -> Node.js Version section.
- Set the Node.js Version to
16.x
⚠️The Vercel app's Node.js Version should be similar to its declared Node version in its server's
engines
section in the/server/package.json
file. Vercel stops supporting old Node versions after some time, which may cause future deployments to fail.
Deploy Development Local App
-
Prepare the local ACAP server directory for Vercel deployment. Confirm that the acap-v2/server directory has the following files:
- Create a
.vercelignore
file to exclude unnecessary items from being deployed to Vercel.- Copy the contents of the
.gitignore
file into the.vercelignore
file. - Include all other directories and files to omit in the Vercel deployment in the .vercelignore file.
- Copy the contents of the
- Make sure that your target project directory has an /api directory that:
- contains Vercel serverless function files following the Vercel "api" syntax
- Or an
index.js
file (for standalone Express apps), minus theapp.listen()
part, with the app exported asmodule.exports = app
- Create a
vercel.json
file in the /acap-v2/server directory. See the attachedvercel.json
file for reference.{ "rewrites": [{ "source": "/api/(.)", "destination": "/api" }], "redirects": [{ "source": "/src(.)", "destination": "/index.html" }] }
- Create a
-
Generate the API documentation for Vercel deployment.
npm run gen:docs:vercel
-
Deploy the "DEVELOPMENT" Vercel app locally for the first time from a terminal, using the "raw" value of the
VERCEL_TOKEN
variable from step #1.vercel pull --yes --environment=production --token=VERCEL_TOKEN vercel build --prod --token=VERCEL_TOKEN vercel deploy --prebuilt --prod --token=VERCEL_TOKEN
Production App Initialization
These steps will initialize an ACAP server app for deployment to the "PRODUCTION" Vercel environment.
Initialize the ACAP Production Vercel App
-
Delete the acap-v2/server/.vercel directory generated after completing the ACAP Development App Initialization steps.
⚠️Delete this folder to avoid conflicts setting up the "PRODUCTION" Vercel app.
-
Login using the Vercel CLI if not yet signed in.
vercel login
-
Navigate to the acap-v2/server directory using a terminal. Run the
vercel link
command to create a new Vercel project - for the "PRODUCTION" environment.vercel link
-
Answer the required prompts, similar to the ACAP Development App Initialization. Provide a different project name when prompted with the question:
- What's your project's name?: Type a new app name (e.g., "acap-prod") and press Enter
-
Take note of the new
projectId
andorgId
values from theproject.json
file inside the newly generated .vercel folder.Add these "PRODUCTION" Vercel values in the forked ACAPs' GitHub Secrets as:
VERCEL_PROJECT_ID_PROD=(value of new projectId) VERCEL_APP_PROD=(name of the "PRODUCTION" Vercel app)
-
Confirm the creation of an empty Vercel app with the "PRODUCTION" project name created by the prompt in the Vercel account's projects dashboard.
-
Go to the PRODUCTION" (Vercel Project) -> Settings -> Environment Variables. Set the environment variables similar to the "PRODUCTION" Render Environment Variables.
💡Ensure similar environment variables and values in the "PRODUCTION" Render deployment with the Vercel Environment variables. Set the value:
DEPLOYMENT_PLATFORM=vercel
-
Set the production Vercel app's Runtime to Node 16.x.
⚠️The Vercel app's Node.js Version should be similar to its declared Node version in its server's
engines
section in the/server/package.json
file. Vercel stops supporting old Node versions after some time, which may cause future deployments to fail.
Deploy Production Local App
-
Generate the API documentation for Vercel deployment.
npm run gen:docs:vercel
-
Deploy the "PRODUCTION" Vercel app locally for the first time from the terminal. Use the "raw" value of the
VERCEL_TOKEN
variable from step #1.vercel pull --yes --environment=production --token=VERCEL_TOKEN vercel build --prod --token=VERCEL_TOKEN vercel deploy --prebuilt --prod --token=VERCEL_TOKEN
GitHub Actions
-
Confirm the creation of the GitHub Secrets.
VERCEL_TOKEN
- Vercel Access Token (from the Initialize Dependencies section, step #1)VERCEL_ORG_ID
- Vercel Organization ID
- Retrieved by answering the prompts from either the Initialize the ACAP Development Vercel App or Initialize the ACAP Production Vercel App steps
VERCEL_PROJECT_ID_DEV
- Development Vercel app project IDVERCEL_APP_DEV
- Development Vercel app project nameVERCEL_PROJECT_ID_PROD
- Production Vercel app project IDVERCEL_APP_PROD
- Production Vercel app project nameROOT_API_URL_VERCEL_DEV
- Development Vercel app website URLROOT_API_URL_VERCEL_PROD
- Production Vercel app website URL
-
Confirm the creation of the GitHub Variable.
DEPLOYMENT_PLATFORM
- Value:
vercel
- Value: Set to
default
or do not include in the GitHub Variables to skip deployment to Vercel
- Value:
-
Review the contents of the .github/workflows/deploy-dev.yml and .github/workflows/release.yml files -->
deploy-server-vercel
job for more information about the GitHub Actions workflows for deployment to the "DEVELOPMENT" and "PRODUCTION" Vercel environments. -
Trigger a deployment to ACAP's development and production environments using GitHub Actions. Observe failure/success logs for the overall deployments, including Vercel.
-
Delete the local /server/.vercel folder. Development or production deployments to Vercel should now trigger in GitHub Actions.