Skip to content

Deployment

This guide covers deploying your Brain Framework agent on any long running Node.js server environment, including database setup considerations.

Choose the appropriate database adapter based on your deployment needs:

PostgreSQL

@elizaos/adapter-postgres

  • Recommended for production deployments
  • Scalable and robust

SQLite

@elizaos/adapter-sqlite

  • Great for development and small deployments
  • Self-contained file database

Supabase

@elizaos/adapter-supabase

  • Cloud-native solution
  • Managed database service
  • Node.js 22 or higher
  • pnpm 9.x (recommended)
  • Database system based on chosen adapter
  • Persistent storage for database files (if using SQLite)
  1. Install required packages:

    Terminal window
    npm i github:elizaos-plugins/adapter-postgres
  2. Create a PM2 ecosystem file (ecosystem.config.js):

    module.exports = {
    apps: [
    {
    name: "brain-agent",
    script: "./dist/index.js",
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: "1G",
    env: {
    NODE_ENV: "production",
    DATABASE_URL: "postgresql://user:pass@localhost:5432/db",
    },
    },
    ],
    };
  3. Configure your database adapter:

    import { AgentBuilder } from "@iqai/agent";
    import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
    const agent = new AgentBuilder()
    .withDatabase(
    new PostgresDatabaseAdapter({
    connectionString: process.env.DATABASE_URL,
    })
    )
    .build();
  4. Build and start:

    Terminal window
    pnpm build
    pm2 start ecosystem.config.js
Terminal window
# Required environment variables
DATABASE_URL=postgresql://user:pass@localhost:5432/db

Here is a link to Digital Ocean guide to create a droplet: Setup a DO Droplet

  1. Connect to your droplet:

    Terminal window
    ssh root@your_droplet_ip
  2. Update the system:

    Terminal window
    sudo apt update && sudo apt upgrade -y
  1. Install NGINX

    Terminal window
    sudo apt install nginx -y
  2. Start and Enable NGINX

    Terminal window
    sudo systemctl start nginx
    sudo systemctl enable nginx
  3. Verify the Installation

    Terminal window
    sudo systemctl status nginx

    You can also open your web browser and navigate to:

    Terminal window
    http://your_droplet_ip
  4. Configure Firewall for NGINX

    Terminal window
    sudo apt install ufw -y
    sudo ufw allow 'Nginx Full'
  5. Test and Reload NGINX Configuration

    Terminal window
    sudo nginx -t
    sudo systemctl reload nginx
  1. Install Net Tools

    Terminal window
    sudo apt install net-tools -y
    netstat --version
  2. Configure Firewall for Your Application

    Terminal window
    sudo ufw allow ssh # or sudo ufw allow 22/tcp
    sudo ufw allow 3000/tcp # Adjust port as needed for your application
    sudo ufw reload
    sudo ufw enable
    sudo ufw status
  1. Install Git

    Terminal window
    sudo apt install git -y
    git --version
  2. Configure Git (optional depending on use case)

    Terminal window
    git config --global user.name "Your Name"
    git config --global user.email "[email protected]"
  1. Install Node.js

    Terminal window
    curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
    sudo apt install -y nodejs
  2. Verify Node.js Installation

    Terminal window
    node -v
    npm -v
  3. Install PNPM

    Terminal window
    npm install -g pnpm
    pnpm -v
Terminal window
sudo mkdir -p /home/ubuntu/
cd /home/ubuntu
git clone https://github.com/username/repository.git
cd your-project
pnpm install

You can use the following methods to deploy your agent: PM2, Docker, and Docker Compose.

  1. Install PM2

    Terminal window
    sudo npm install -g pm2
  2. Set Up PM2 to Start on Boot (Optional)

    Terminal window
    pm2 startup systemd
    pm2 save
  3. Start Your Application with PM2

    Terminal window
    pm2 start "pnpm dev" --name your-app-name
  4. Basic PM2 Commands

    Terminal window
    # Restart application
    pm2 restart your-app-name
    # Stop application
    pm2 stop your-app-name
    # Delete application from PM2
    pm2 delete your-app-name
    # View running applications
    pm2 list
    # Monitor application
    pm2 monit
  1. Install Certbot for Let’s Encrypt SSL

    Terminal window
    sudo apt install certbot python3-certbot-nginx -y
  2. Obtain SSL Certificate

    Terminal window
    sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
  1. Check NGINX Logs

    Terminal window
    sudo tail -f /var/log/nginx/access.log
    sudo tail -f /var/log/nginx/error.log
  2. Check System Resources

    Terminal window
    htop # Install with: sudo apt install htop
  1. Create a folder .github/workflows in your project root
  2. Then a file ci.yml in the folder .github/workflows created in your project root
  3. Copy and paste the following code in the ci.yml, you can edit further to your specification
Terminal window
name: Brain Agent CI/CD
on:
push:
branches: [main]
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Lint
run: pnpm lint
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build
env:
LIST_YOUR_ENV_KEYS: ${{ secrets.GET_THE_SET_VALUES_IN_GITHUB_SECRET }}
deploy:
needs: build
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: |
apps/**
- name: Deploy to Server
if: steps.changed-files.outputs.any_changed == 'true'
uses: appleboy/[email protected]
with:
host: ${{ secrets.DIGITALOCEAN_HOST }}
username: ${{ secrets.DIGITALOCEAN_USER }}
key: ${{ secrets.DIGITALOCEAN_PRIVATE_KEY }}
port: ${{ secrets.DIGITALOCEAN_PORT }}
script: |
cd /home/ubuntu/your-project/apps
git pull origin main
cat > .env << EOF
LIST_YOUR_ENV_KEYS: ${{ secrets.GET_THE_SET_VALUES_IN_GITHUB_SECRET }}
EOF
chmod 600 .env
pnpm install
# pm2 restart your-agent-name or docker-compose down && docker-compose up -d --build

You can deploy your agent to Google Cloud Run using either the Web UI or Command Line.

  1. Prerequisites
    • Google Cloud Account (with billing enabled)
    • Project in GCP (or create new one)
    • Agent Code (Dockerized or supported language)

    Note: If not containerized, Cloud Run can build from source (Python/Node.js/Go)

  2. Access Cloud Run
  3. Create Service
    • Click ”+ CREATE SERVICE”
    • Choose deployment method:
      • Existing container image (if using Docker)
      • Source code (if you want Cloud Run to build the container from your source code ie GitHub/Cloud Source)
  4. Configure Service
    • Name: my-agent
    • Region: us-central1 (or closest)
    • Authentication: Allow unauthenticated if public
    • Container: Image URL or source connection
    • Advanced (optional): CPU/Memory, Auto-scaling
  5. Remember to set these
    • Set port to be set to 3000
    • Add direct client interface to be used to allow health checks
    • Memory & CPU: Adjust if needed (recommended: 2 CPU, 1-2GB RAM)
    • Environment variables: Define environment variables your agent needs before deployment
    • Scaling: Set minimum and maximum instances (recommended: min. 1)
  6. Deploy & Test
  1. Monitoring
    • Logs: Cloud Console > Logging > Cloud Run
    • Metrics: Monitoring > Cloud Run Dashboard
  2. Next Steps
    • Set up CI/CD with Cloud Build
    • Configure custom domains
    • Add event triggers (Pub/Sub, Storage)

For more complex configurations, refer to the: Google Cloud Run documentation