build: 🏗️ Package Worker

This commit is contained in:
Jesse Wierzbinski 2025-04-14 17:13:36 +02:00
parent 5a4ce29206
commit 1beb18e321
No known key found for this signature in database
7 changed files with 66 additions and 9 deletions

View file

@ -0,0 +1,30 @@
diff --git a/build-worker.ts b/build-worker.ts
index 5e2a6d5a..ee66871c 100644
--- a/build-worker.ts
+++ b/build-worker.ts
@@ -1,8 +1,8 @@
import { build } from "bun";
import { $ } from "bun";
-import ora from "ora";
+// import ora from "ora";
-const buildSpinner = ora("Building").start();
+// const buildSpinner = ora("Building").start();
await $`rm -rf dist && mkdir dist`;
@@ -18,7 +18,7 @@ await build({
minify: false,
});
-buildSpinner.text = "Transforming";
+// buildSpinner.text = "Transforming";
// Copy Drizzle migrations to dist
await $`cp -r drizzle dist/drizzle`;
@@ -30,4 +30,4 @@ await $`cp -r node_modules/@img/sharp-linuxmusl-* dist/node_modules/@img`;
await $`cp -r node_modules/detect-libc dist/node_modules/`;
-buildSpinner.stop();
+// buildSpinner.stop();

21
nix/package-worker.nix Normal file
View file

@ -0,0 +1,21 @@
# Simply edit the server to run "bun run build:worker" instead of "bun run build"
{versia-server}:
versia-server.overrideAttrs (oldAttrs: {
pname = "${oldAttrs.pname}-worker";
buildPhase = ''
runHook preBuild
bun run build:worker
runHook postBuild
'';
entrypointPath = "worker.js";
patches = [./fix-build-spinner-worker.patch];
meta =
oldAttrs.meta
// {
description = "${oldAttrs.meta.description} (worker)";
};
})

View file

@ -44,6 +44,8 @@ in
runHook postBuild
'';
entrypointPath = "index.js";
installPhase = let
libPath = lib.makeLibraryPath [
vips
@ -60,7 +62,7 @@ in
cp -r dist $out/${finalAttrs.pname}
makeWrapper ${lib.getExe bun} $out/bin/${finalAttrs.pname} \
--add-flags "run $out/${finalAttrs.pname}/index.js" \
--add-flags "run $out/${finalAttrs.pname}/${finalAttrs.entrypointPath}" \
--set NODE_PATH $out/${finalAttrs.pname}/node_modules \
--prefix PATH : ${binPath} \
--prefix LD_LIBRARY_PATH : ${libPath}