Skip to content

Commit 2609654

Browse files
committed
feat: support configuring kv path, persist kv data in docker
1 parent 8622928 commit 2609654

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
FROM denoland/deno:alpine-1.45.0
1+
FROM denoland/deno:alpine-1.46.3
2+
3+
RUN mkdir /data && chown deno:deno /data
4+
VOLUME /data
5+
ENV KV_PATH=/data/kv.sqlite3
26

37
USER deno
48
WORKDIR /app
59

610
COPY . .
711
RUN deno cache src/main.ts
812

9-
CMD ["run", "--allow-env", "--allow-net=:8080,discord.com", "--unstable-kv", "src/main.ts"]
13+
CMD [\
14+
"run",\
15+
"--allow-env", "--allow-net=:8080,discord.com", "--allow-read=/data", "--allow-write=/data",\
16+
"--unstable-kv",\
17+
"src/main.ts"\
18+
]

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42
main:
53
image: shiftinv/github-webhook-filter

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export default {
1313
debug: parseBool(get("DEBUG", "0")),
1414
hostname: get("HOSTNAME", "127.0.0.1"),
1515
port: parseInt(get("PORT", "8080")),
16+
1617
signKey: get("SIGN_KEY", null),
1718
maxWebhookRetries: parseInt(get("MAX_RETRIES", "3")),
1819
maxWebhookRetryMs: parseInt(get("MAX_RETRY_MS", "30000")),
1920
mainRedirect: get("MAIN_REDIRECT", null),
21+
KV_PATH: get("KV_PATH", null) ?? undefined,
2022

2123
// set by deno deploy
2224
deployId: get("DENO_DEPLOYMENT_ID", "<unknown>"),

src/kv.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import config from "./config.ts";
12
import type { RequestLog } from "./util.ts";
23

34
const KEY_EXPIRY = 3; // seconds
45
const MAX_RETRIES = 50;
56

6-
const kv = await Deno.openKv();
7+
const kv = await Deno.openKv(config.KV_PATH);
78

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

0 commit comments

Comments
 (0)