fix: Run workers in prod without tsx. Fixes #1673

This commit is contained in:
Mohamed Bassem
2025-07-19 14:35:11 +00:00
parent 4fe541c422
commit 2cce45b7ed
8 changed files with 472 additions and 92 deletions

1
.gitignore vendored
View File

@@ -16,6 +16,7 @@ out/
# production
build
dist
# misc
.DS_Store

View File

@@ -19,7 +19,7 @@
"http-proxy-agent": "^7.0.2",
"https-proxy-agent": "^7.0.6",
"jsdom": "^24.0.0",
"liteque": "^0.4.1",
"liteque": "^0.5.0",
"metascraper": "^5.46.18",
"metascraper-amazon": "^5.46.18",
"metascraper-author": "5.46.18",
@@ -50,11 +50,14 @@
"devDependencies": {
"@karakeep/prettier-config": "workspace:^0.1.0",
"@types/jsdom": "^21.1.6",
"@types/node-cron": "^3.0.11"
"@types/node-cron": "^3.0.11",
"tsdown": "^0.12.9"
},
"scripts": {
"start": "tsx watch index.ts",
"start:prod": "tsx index.ts",
"build": "tsdown",
"build:watch": "tsdown --watch",
"lint": "oxlint .",
"lint:fix": "oxlint . --fix",
"format": "prettier . --ignore-path ../../.prettierignore",

View File

@@ -0,0 +1,21 @@
import { defineConfig } from "tsdown";
export default defineConfig({
entry: ["index.ts"],
format: ["esm"],
target: "node22",
outDir: "dist",
clean: true,
minify: false,
sourcemap: true,
platform: "node",
shims: true,
external: [
// Keep native binaries external (transitive deps of bundled workspace packages)
"better-sqlite3",
],
noExternal: [
// Bundle workspace packages (since they're not published to npm)
/^@karakeep\//,
],
});

View File

@@ -26,6 +26,7 @@ RUN cd packages/db && \
RUN (cd apps/web && pnpm exec next build --experimental-build-mode compile)
# Build the worker code
RUN (cd apps/workers && pnpm build)
RUN pnpm deploy --node-linker=isolated --filter @karakeep/workers --prod /prod/workers
# Build the cli
@@ -96,8 +97,6 @@ COPY --from=base --chown=node:node /app/apps/web/.next/static ./apps/web/.next/s
######################
COPY --from=base /prod/workers /app/apps/workers
RUN npm install -g tsx
ENTRYPOINT ["/init"]
################# The AIO ##############

View File

@@ -2,4 +2,4 @@
# shellcheck shell=bash
cd /app/apps/workers;
exec tsx index.ts
exec node dist/index.mjs

View File

@@ -229,6 +229,7 @@ install_karakeep() {
$shh pnpm build
cd "$APP_DIR"/workers
$shh pnpm i --frozen-lockfile
$shh pnpm build
cd "$APP_DIR"/cli
$shh pnpm i --frozen-lockfile
$shh pnpm build
@@ -342,7 +343,7 @@ Group=karakeep
Restart=always
EnvironmentFile=${ENV_FILE}
WorkingDirectory=${APP_DIR}/workers
ExecStart=/usr/bin/pnpm run start:prod
ExecStart=/usr/bin/node dist/index.mjs
StandardOutput=append:${LOG_DIR}/karakeep-workers.log
StandardError=append:${LOG_DIR}/karakeep-workers.log
TimeoutStopSec=5
@@ -438,6 +439,7 @@ update_karakeep() {
cd "$APP_DIR"/web && $shh pnpm i --frozen-lockfile
$shh pnpm build
cd "$APP_DIR"/workers && $shh pnpm i --frozen-lockfile
$shh pnpm build
cd "$APP_DIR"/cli && $shh pnpm i --frozen-lockfile
$shh pnpm build
cd "$INSTALL_DIR"/packages/db && $shh pnpm migrate

View File

@@ -9,7 +9,7 @@
"glob": "^11.0.0",
"html-to-text": "^9.0.5",
"js-tiktoken": "^1.0.20",
"liteque": "^0.4.1",
"liteque": "^0.5.0",
"meilisearch": "^0.37.0",
"nodemailer": "^7.0.4",
"ollama": "^0.5.14",

524
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff