PostgreSQL
@elizaos/adapter-postgres
- Recommended for production deployments
- Scalable and robust
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
SQLite
@elizaos/adapter-sqlite
Supabase
@elizaos/adapter-supabase
Install required packages:
npm i github:elizaos-plugins/adapter-postgres
pnpm add github:elizaos-plugins/adapter-postgres
yarn add github:elizaos-plugins/adapter-postgres
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", }, }, ],};
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();
Build and start:
pnpm build pm2 start ecosystem.config.js
# Required environment variablesDATABASE_URL=postgresql://user:pass@localhost:5432/db
# Set file location DATABASE_PATH=./data/agent.db
# Required environment variables SUPABASE_URL=your-project-urlSUPABASE_KEY=your-api-key
Here is a link to Digital Ocean guide to create a droplet: Setup a DO Droplet
Connect to your droplet:
ssh root@your_droplet_ip
Update the system:
sudo apt update && sudo apt upgrade -y
Install NGINX
sudo apt install nginx -y
Start and Enable NGINX
sudo systemctl start nginxsudo systemctl enable nginx
Verify the Installation
sudo systemctl status nginx
You can also open your web browser and navigate to:
http://your_droplet_ip
Configure Firewall for NGINX
sudo apt install ufw -ysudo ufw allow 'Nginx Full'
Test and Reload NGINX Configuration
sudo nginx -tsudo systemctl reload nginx
Install Net Tools
sudo apt install net-tools -ynetstat --version
Configure Firewall for Your Application
sudo ufw allow ssh # or sudo ufw allow 22/tcpsudo ufw allow 3000/tcp # Adjust port as needed for your applicationsudo ufw reloadsudo ufw enablesudo ufw status
Install Git
sudo apt install git -ygit --version
Configure Git (optional depending on use case)
git config --global user.name "Your Name"
Install Node.js
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -sudo apt install -y nodejs
Verify Node.js Installation
node -vnpm -v
Install PNPM
npm install -g pnpmpnpm -v
sudo mkdir -p /home/ubuntu/cd /home/ubuntugit clone https://github.com/username/repository.gitcd your-projectpnpm install
You can use the following methods to deploy your agent: PM2, Docker, and Docker Compose.
Install PM2
sudo npm install -g pm2
Set Up PM2 to Start on Boot (Optional)
pm2 startup systemdpm2 save
Start Your Application with PM2
pm2 start "pnpm dev" --name your-app-name
Basic PM2 Commands
# Restart applicationpm2 restart your-app-name
# Stop applicationpm2 stop your-app-name
# Delete application from PM2pm2 delete your-app-name
# View running applicationspm2 list
# Monitor applicationpm2 monit
Install Docker
sudo apt install docker.io -ysudo systemctl start dockersudo systemctl enable docker
Deploy with Docker
# Build your Docker imagedocker build -t image_name .
# Run your containerdocker run -d --name container_name -p host_port:container_port image_name
# Stop and remove containerdocker stop container_namedocker rm container_name
Sample Setup
FROM node:23-slim
WORKDIR /app
# Install pnpmRUN npm install -g pnpm
# Copy package files and install dependenciesCOPY package.json pnpm-lock.yaml* ./RUN pnpm install
# Copy project filesCOPY src/ ./src/COPY tsconfig.json ./COPY .env ./
# Create data directory for SQLiteRUN mkdir -p data
# Run the applicationCMD ["pnpm", "dev"]
Build and run:
docker build -t brain-agent .docker run -d \ -p 3000:3000 \ --name brain-agent \ -e DATABASE_URL=postgresql://user:pass@host:5432/db \ brain-agent
Common commands:
# Stop containerdocker stop brain-agent
# Start containerdocker start brain-agent
# View logsdocker logs -f brain-agent
Install Docker Compose
sudo apt install docker-compose -y
Create docker-compose.yml:
version: '3.8'services: app: build: . ports: - "3000:3000" environment: DATABASE_URL: postgresql://user:pass@db:5432/db depends_on: - db
db: image: postgres:15 environment: POSTGRES_USER: user POSTGRES_PASSWORD: pass POSTGRES_DB: db volumes: - postgres_data:/var/lib/postgresql/data
volumes: postgres_data:
Deploy with Docker Compose
# Navigate to your project directorycd /path/to/your/project
# Create or modify docker-compose.yml file# Run your containersdocker-compose up --build -d
# Stop and remove containersdocker-compose down
Management commands:
# View logsdocker-compose logs -f
Install Certbot for Let’s Encrypt SSL
sudo apt install certbot python3-certbot-nginx -y
Obtain SSL Certificate
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Check NGINX Logs
sudo tail -f /var/log/nginx/access.logsudo tail -f /var/log/nginx/error.log
Check System Resources
htop # Install with: sudo apt install htop
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' 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.
Note: If not containerized, Cloud Run can build from source (Python/Node.js/Go)
curl https://my-agent-xyz.a.run.app
gcloud auth logingcloud config set project PROJECT_ID
gcloud run deploy my-agent \ --image=gcr.io/PROJECT_ID/agent-image:latest \ --platform=managed \ --region=us-central1 \ --allow-unauthenticated
gcloud run deploy my-agent \ --source . \ --platform=managed \ --region=us-central1
SERVICE_URL=$(gcloud run services describe my-agent \ --region=us-central1 \ --format="value(status.url)")
curl $SERVICE_URL
# Update deploymentgcloud run deploy my-agent --image=NEW_IMAGE
# View logsgcloud logging read "resource.type=cloud_run_revision"
# Delete servicegcloud run services delete my-agent
For more complex configurations, refer to the: Google Cloud Run documentation