From 644e027abebf5537040e3bb6b754a3c0e9ffefd4 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 1 Sep 2025 09:09:16 +0200 Subject: [PATCH] Fixes #1515 Replaces hacky way of building two binaries for ARM and Intel and putting the right one into the image by using a multi-stage build. You can now build SB without even installing Deno. Also adds a HEALTCHECK --- Dockerfile | 17 +++++++++++-- README.md | 12 ++++++++++ deno.json | 53 ++++++++++++++++++++--------------------- scripts/build_docker.sh | 6 ----- 4 files changed, 53 insertions(+), 35 deletions(-) delete mode 100755 scripts/build_docker.sh diff --git a/Dockerfile b/Dockerfile index b9190814..32e6cbd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,14 @@ +FROM denoland/deno:2.4.5 AS builder + +RUN apt update && apt install -y curl git + +WORKDIR /app + +ADD . /app + +RUN deno task build + + FROM ubuntu:noble # The volume that will keep the space data @@ -20,11 +31,13 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TAR RUN mkdir -p -m 777 /space \ && chmod +x /tini \ && apt update \ - && apt install -y git \ + && apt install -y git curl \ && apt-get -y autoremove \ && apt-get clean \ && rm -rf /tmp/* /var/tmp/* /var/log/* /usr/share/man /var/lib/apt/lists/* +HEALTHCHECK CMD curl --fail http://localhost:3000/.ping || exit 1 + # Expose port 3000 # Port map this when running, e.g. with -p 3002:3000 (where 3002 is the host port) EXPOSE 3000 @@ -37,7 +50,7 @@ ENV SB_FOLDER=/space ADD ./docker-entrypoint.sh /docker-entrypoint.sh # Copy the bundled version of silverbullet into the container -ADD silverbullet-${TARGETARCH} /silverbullet +COPY --from=builder /app/silverbullet /silverbullet # Run the server, allowing to pass in additional argument at run time, e.g. # docker run -p 3002:3000 -v myspace:/space -it ghcr.io/silverbulletmd/silverbullet --user me:letmein diff --git a/README.md b/README.md index 17f7e6d0..80880be5 100644 --- a/README.md +++ b/README.md @@ -73,4 +73,16 @@ deno task watch-plugs To typecheck the entire codebase (recommended before submitting PR): ```shell deno task check +``` + +To build it in a docker container: + +```shell +docker build -t silverbullet . +``` + +and to then run it: + +```shell +docker run -p 3000:3000 -v :/space silverbullet ``` \ No newline at end of file diff --git a/deno.json b/deno.json index 93b54594..56c6e5a9 100644 --- a/deno.json +++ b/deno.json @@ -1,32 +1,8 @@ { "name": "@silverbulletmd/silverbullet", "version": "2.0.0", - "exports": { - "./syscall": "./plug-api/syscall.ts", - "./syscalls": "./plug-api/syscalls.ts", - "./lib/json": "./plug-api/lib/json.ts", - "./lib/tree": "./plug-api/lib/tree.ts", - "./lib/attribute": "./plug-api/lib/attribute.ts", - "./lib/ref": "./plug-api/lib/ref.ts", - "./lib/resolve": "./plug-api/lib/resolve.ts", - "./lib/frontmatter": "./plug-api/lib/frontmatter.ts", - "./type/client": "./type/client.ts", - "./type/command": "./type/command.ts", - "./type/config": "./type/config.ts", - "./type/datastore": "./type/datastore.ts", - "./type/event": "./type/event.ts", - "./type/index": "./type/index.ts", - "./type/rpc": "./type/rpc.ts", - "./lib/tags": "./plug-api/lib/tags.ts" - }, - "publish": { - "exclude": [ - "website", - "CHANGELOG.md", - "**/*.md" - ] - }, "tasks": { + "build": "rm -rf dist dist_client_bundle dist_plug_bundle && deno run -A build_plugs.ts && deno run -A build_web.ts --production && deno task compile", "clean": "rm -rf dist dist_client_bundle dist_plug_bundle", "deep-clean-mac": "rm -f deno.lock && rm -rf $HOME/Library/Caches/deno && deno task clean", "install": "deno install -g -f -A --import-map deno.json silverbullet.ts", @@ -35,11 +11,9 @@ "fmt": "deno fmt", "test": "deno test -A", "bench": "deno bench", - "build": "rm -rf dist dist_client_bundle dist_plug_bundle && deno run -A build_plugs.ts && deno run -A build_web.ts --production && deno task compile", "plugs": "deno run -A build_plugs.ts", "server": "deno run -A --check silverbullet.ts", "generate": "./scripts/generate.sh", - "docker": "./scripts/build_docker.sh", "watch-web": "deno run -A --check build_web.ts --watch", "watch-server": "deno run -A --check --watch silverbullet.ts", "watch-plugs": "deno run -A --check build_plugs.ts -w", @@ -57,6 +31,13 @@ "server:dist:windows-x86_64": "deno task bundle && deno compile -A --target x86_64-pc-windows-msvc -o silverbullet.exe dist/silverbullet.js", "server:zip:windows-x86_64": "deno task server:dist:windows-x86_64 && zip silverbullet-server-windows-x86_64.zip silverbullet.exe" }, + "publish": { + "exclude": [ + "website", + "CHANGELOG.md", + "**/*.md" + ] + }, "lint": { "exclude": [ "dist", @@ -94,6 +75,24 @@ "jsx": "react-jsx", "jsxImportSource": "npm:preact@10.26.4" }, + "exports": { + "./syscall": "./plug-api/syscall.ts", + "./syscalls": "./plug-api/syscalls.ts", + "./lib/json": "./plug-api/lib/json.ts", + "./lib/tree": "./plug-api/lib/tree.ts", + "./lib/attribute": "./plug-api/lib/attribute.ts", + "./lib/ref": "./plug-api/lib/ref.ts", + "./lib/resolve": "./plug-api/lib/resolve.ts", + "./lib/frontmatter": "./plug-api/lib/frontmatter.ts", + "./type/client": "./type/client.ts", + "./type/command": "./type/command.ts", + "./type/config": "./type/config.ts", + "./type/datastore": "./type/datastore.ts", + "./type/event": "./type/event.ts", + "./type/index": "./type/index.ts", + "./type/rpc": "./type/rpc.ts", + "./lib/tags": "./plug-api/lib/tags.ts" + }, "imports": { "@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.7", "@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.7", diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh deleted file mode 100755 index 52c655aa..00000000 --- a/scripts/build_docker.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -echo "Building both AMD64 and ARM64 Linux binaries" -deno task server:dist:linux-x86_64 && mv silverbullet silverbullet-amd64 -deno task server:dist:linux-aarch64 && mv silverbullet silverbullet-arm64 -docker build -t silverbullet . \ No newline at end of file