Skip to content
Directory
GitHub Star
Evidence, tags & source code

First Personal Agent Deployment with Docker Compose, PostgreSQL and HTTPS ​

Before deploying a persistent personal research Agent, I would deploy a tiny service that does not call a model: a report endpoint returning a synthetic record actually stored in a database. This isolates host, network, database, application and HTTPS failures before model keys or tool permissions enter the picture.

This standalone teaching project has not been run on a cloud host in this task. Use a new empty directory and an authorized test host. Tencent Cloud or another Linux VM is suitable; size it for actual memory, disk, concurrency and recovery requirements rather than treating example settings as capacity evidence.

Prepare the smallest application ​

Install supported Docker Engine and the Compose plugin. Create the following files. The database and app use Compose's internal network. Only the app port is mapped to host loopback; the database has no published ports.

Save as compose.yaml:

yaml
services:
  db:
    image: postgres:17
    environment:
      POSTGRES_DB: research_demo
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${DB_ADMIN_PASSWORD:?set DB_ADMIN_PASSWORD}
      APP_DB_PASSWORD: ${APP_DB_PASSWORD:?set APP_DB_PASSWORD}
    volumes:
      - db-data:/var/lib/postgresql/data
      - ./init.sh:/docker-entrypoint-initdb.d/10-init.sh:ro
    healthcheck:
      test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "postgres", "-d", "research_demo"]
      interval: 5s
      timeout: 3s
      retries: 12
  app:
    build: .
    environment:
      PGHOST: db
      PGDATABASE: research_demo
      PGUSER: research_app
      PGPASSWORD: ${APP_DB_PASSWORD:?set APP_DB_PASSWORD}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "127.0.0.1:8080:8080"
volumes:
  db-data:

Initialize with a separate administrator while giving the application read access only to the synthetic report. Save init.sh:

sh
#!/bin/sh
set -eu
psql -v ON_ERROR_STOP=1 -U postgres -d research_demo \
  -v app_password="$APP_DB_PASSWORD" <<'SQL'
CREATE ROLE research_app LOGIN PASSWORD :'app_password';
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
CREATE TABLE demo_report(id text PRIMARY KEY, title text NOT NULL);
INSERT INTO demo_report VALUES ('sample-001', 'Synthetic research report');
GRANT CONNECT ON DATABASE research_demo TO research_app;
GRANT USAGE ON SCHEMA public TO research_app;
GRANT SELECT ON demo_report TO research_app;
SQL

Save package.json:

json
{"private":true,"type":"module","dependencies":{"pg":"8.13.3"}}

Save Dockerfile:

dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package.json ./
RUN npm install --omit=dev --ignore-scripts
COPY server.mjs ./
USER node
CMD ["node", "server.mjs"]

Save server.mjs:

js
import http from 'node:http'
import pg from 'pg'
const pool = new pg.Pool({ max: 2, connectionTimeoutMillis: 3000 })
http.createServer(async (req, res) => {
  res.setHeader('Content-Type', 'application/json')
  if (req.url === '/health') {
    res.end(JSON.stringify({ ok: true }))
    return
  }
  if (req.url !== '/ready' && req.url !== '/report') {
    res.writeHead(404).end('{}')
    return
  }
  try {
    const { rows } = await pool.query(
      'SELECT id, title FROM demo_report WHERE id = $1', ['sample-001']
    )
    if (rows.length !== 1) throw Error('Missing sample')
    res.end(JSON.stringify(req.url === '/ready' ? { ok: true } : rows[0]))
  } catch {
    res.writeHead(503).end(JSON.stringify({ ok: false }))
  }
}).listen(8080, '0.0.0.0')

Node HTTP and a PostgreSQL driver ensure the endpoint really queries the database. There is no application login: never expose private reports through it. This teaching example pins major dependencies but is not a fully reproducible artifact; production builds should commit a lockfile, pin image digests and use controlled builds.

Verify locally before exposing HTTPS ​

Generate two distinct demo passwords. Add .env to both .gitignore and .dockerignore before building; do not print real values. An existing database volume does not rerun initialization scripts, and changing environment variables does not rotate existing role passwords.

sh
umask 077
printf 'DB_ADMIN_PASSWORD=%s\nAPP_DB_PASSWORD=%s\n' \
  "$(openssl rand -hex 24)" "$(openssl rand -hex 24)" > .env
chmod +x init.sh
docker compose up --build -d
curl --retry 10 --retry-connrefused --retry-delay 1 -fsS http://127.0.0.1:8080/health
curl -fsS http://127.0.0.1:8080/ready
curl -fsS http://127.0.0.1:8080/report

Health and readiness should return ok; the report should return sample-001 and Synthetic research report. Restart the app and read the original record. Before cleanup, verify the Compose project and persistent data; do not delete volumes during routine restart.

Next install Caddy on the host, use a domain you control, point DNS at the test host, and allow ports 80 and 443 as required. Restrict SSH to trusted sources. Complete any applicable regional registration requirements before public access.

caddyfile
research.example.com {
    reverse_proxy 127.0.0.1:8080
}

Replace research.example.com with an authorized test domain. Start the proxy following the Caddy HTTPS guide, and persist certificate data. The public exercise contains synthetic records only; add application authentication and download authorization before using real reports.

From an external client, check the certificate, /health, /ready and /report separately. If health passes but readiness fails, inspect database and permissions. If loopback works but public requests return 502, inspect the proxy and listener rather than resetting the database.

For supported Open ETF Agent installation, see its deployment recovery documentation; this Node 22 example is not its Runtime. Further self-hosting work is in the application roadmap.

Engineering notes, evidence and boundaries. · Contact: hpoenixf@foxmail.com · WeChat: hpoenixf0510