diff --git a/.dockerignore b/.dockerignore index 99f7c1c..2cb7424 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,4 +8,7 @@ config.json # Other .devcontainer/ .github/ -.vscode/ \ No newline at end of file +.vscode/ +# Vercel +.vercel/ +vercel.json diff --git a/.gitignore b/.gitignore index 4050f67..8ae3e60 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ node_modules/ # Configuration files config.json *.env -*.ignore \ No newline at end of file +*.ignore +# Vercel +.vercel/ +public/ diff --git a/AGENTS.md b/AGENTS.md index c570666..d83d242 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -103,3 +103,10 @@ environment file -> process environment. Keys are **case-sensitive**. Pushing to `main` triggers `.github/workflows/deploy-docker.yaml`, which builds the `Dockerfile` (`oven/bun:1`) and publishes the image to GHCR with a build-provenance attestation. + +The bot runs on Vercel as a [Daemon](https://vercel.com/docs/daemons), declared +in `vercel.json`. Vercel builds the same `Dockerfile` on each production +deployment. Keep `instances` at exactly `1`: more than one instance makes every +Gateway event fire twice. On deploy, Vercel sends `SIGTERM` to the old +instance, and `src/index.ts` disconnects at once so the two instances do not +overlap. Secrets are project environment variables (Production scope). diff --git a/src/index.ts b/src/index.ts index d4cefae..008aad9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,3 +74,11 @@ client.once(Events.ClientReady, () => { }); client.login(config.token); + +// Disconnect at once on SIGTERM, so that the old and new instances do not +// both handle events during a deploy. +process.once("SIGTERM", async () => { + console.log("[bot]", "received SIGTERM, shutting down"); + await client.destroy(); + process.exit(0); +}); diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..912c80d --- /dev/null +++ b/vercel.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://openapi.vercel.sh/vercel.json", + "buildCommand": "mkdir -p public && printf 'User-agent: *\\nDisallow: /\\n' > public/robots.txt", + "outputDirectory": "public", + "daemons": { + "codercord": { + "root": "./", + "entrypoint": "Dockerfile", + "instances": { + "iad1": 1 + }, + "resources": { + "requests": { + "memory": "1Gi" + } + } + } + } +}