Skip to content

CIRCE / DOCUMENTATION

Bun

Run Circe on Bun with systemd or Docker, including the native HTTP server and SQLite.

Documentation menu
On this page

Prepare the project

bun x @sxnnyside/circe init --runtime bun --standard
bun install
cp .env.example .env        # then fill in the values
bun x circe doctor
bun x circe dev

Production:

bun install --production
bun x circe build
bun x circe start

systemd

# /etc/systemd/system/circe-bot.service
[Unit]
Description=Circe Discord Bot
After=network.target

[Service]
Type=simple
User=botuser
WorkingDirectory=/opt/circe-bot
ExecStart=/usr/local/bin/bun x circe start
Restart=on-failure
RestartSec=5s
TimeoutStopSec=15
EnvironmentFile=/opt/circe-bot/.env
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/opt/circe-bot/data

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now circe-bot
sudo journalctl -u circe-bot -f

pm2 also works with Bun: follow the pm2 guide and set script: "bun", args: "x circe start" and interpreter: "none".

HTTP interactions

With transport: "http", circe start binds Bun.serve on the configured port and verifies the X-Signature-Ed25519 header with native Web Crypto. Discord requires HTTPS, so terminate TLS in front of it.

Docker

FROM oven/bun:1.4-slim
WORKDIR /app

COPY package.json bun.lock ./
RUN bun install --frozen-lockfile --production

COPY circe.config.ts ./
COPY src ./src

EXPOSE 8787
CMD ["bun", "x", "circe", "start"]

SQLite cooldowns

import { cooldown } from "@sxnnyside/circe";
import { SqliteCooldownStore } from "@sxnnyside/circe/sqlite";

const store = new SqliteCooldownStore({ path: "./data/cooldowns.sqlite" });
export const userCooldown = cooldown({ durationMs: 5_000, scope: "user", store });

On Bun this uses native bun:sqlite.