Skip to content

Commit

Permalink
feat: support configuring kv path, persist kv data in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Dec 28, 2024
1 parent 8622928 commit 2609654
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
FROM denoland/deno:alpine-1.45.0
FROM denoland/deno:alpine-1.46.3

RUN mkdir /data && chown deno:deno /data
VOLUME /data
ENV KV_PATH=/data/kv.sqlite3

USER deno
WORKDIR /app

COPY . .
RUN deno cache src/main.ts

CMD ["run", "--allow-env", "--allow-net=:8080,discord.com", "--unstable-kv", "src/main.ts"]
CMD [\
"run",\
"--allow-env", "--allow-net=:8080,discord.com", "--allow-read=/data", "--allow-write=/data",\
"--unstable-kv",\
"src/main.ts"\
]
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
main:
image: shiftinv/github-webhook-filter
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export default {
debug: parseBool(get("DEBUG", "0")),
hostname: get("HOSTNAME", "127.0.0.1"),
port: parseInt(get("PORT", "8080")),

signKey: get("SIGN_KEY", null),
maxWebhookRetries: parseInt(get("MAX_RETRIES", "3")),
maxWebhookRetryMs: parseInt(get("MAX_RETRY_MS", "30000")),
mainRedirect: get("MAIN_REDIRECT", null),
KV_PATH: get("KV_PATH", null) ?? undefined,

// set by deno deploy
deployId: get("DENO_DEPLOYMENT_ID", "<unknown>"),
Expand Down
3 changes: 2 additions & 1 deletion src/kv.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import config from "./config.ts";
import type { RequestLog } from "./util.ts";

const KEY_EXPIRY = 3; // seconds
const MAX_RETRIES = 50;

const kv = await Deno.openKv();
const kv = await Deno.openKv(config.KV_PATH);

export async function getAndIncrementKV(key: string, reqLog: RequestLog): Promise<number> {
const kvKey = ["pr-comment", key];
Expand Down

0 comments on commit 2609654

Please sign in to comment.