From 5b8c25f8b3404cfc9d1954e34ce1af68c923f062 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 7 Dec 2022 18:43:47 +0100 Subject: [PATCH] Deno docker update (#174) Fix #150: update Dockerfile and docker-compose --- .github/workflows/docker.yml | 36 ++++++++++++++++++++++++ .github/workflows/{deno.yml => test.yml} | 10 +------ Dockerfile | 28 +++++++++++++----- README.md | 33 +++++++++++++++++++++- docker-compose.yaml | 18 ++++++------ scripts/build_docker.sh | 4 +++ web/cm_plugins/wiki_link.ts | 4 +++ website/CHANGELOG.md | 3 +- 8 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/docker.yml rename .github/workflows/{deno.yml => test.yml} (60%) create mode 100755 scripts/build_docker.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..4f3fac9d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,36 @@ +name: Docker + +on: + push: + branches: ["main"] + +jobs: + docker-build-push: + runs-on: ubuntu-latest + + steps: + - name: Setup repo + uses: actions/checkout@v3 + + - name: Setup Deno + uses: denoland/setup-deno@d4873ceeec10de6275fecd1f94b6985369d40231 + with: + deno-version: v1.28.1 + + - name: Run bundle build + run: | + deno task build + deno task bundle + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: zefhemel/silverbullet:latest diff --git a/.github/workflows/deno.yml b/.github/workflows/test.yml similarity index 60% rename from .github/workflows/deno.yml rename to .github/workflows/test.yml index d09545b1..f8692030 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/test.yml @@ -1,12 +1,4 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# This workflow will install Deno then run Deno lint and test. -# For more information see: https://github.com/denoland/setup-deno - -name: Deno +name: Test on: push: diff --git a/Dockerfile b/Dockerfile index 2539beb4..b65bd2e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,26 @@ -FROM node:18.6.0-slim +FROM denoland/deno:alpine-1.28.3 -RUN mkdir /space -RUN chown node:node /space -USER node -WORKDIR /space +# The volume that will keep the space data +# Create a volume first: +# docker volume create myspace +# Then bind-mount it when running the container with the -v flag, e.g.: +# docker run -v myspace:/space -it zefhemel/silverbullet +VOLUME /space -RUN npx --yes @silverbulletmd/server || true +# Copy the bundled version of silverbullet into the container +ADD ./dist/silverbullet.js /silverbullet.js +# Make sure the deno user has access to the space volume +RUN mkdir -p /space +RUN chown -R deno:deno /space + +# deno user id is 1000 in alpine image +USER deno + +# Expose port 3000 +# Port map this when running, e.g. with -p 3002:3000 (where 3002 is the host port) EXPOSE 3000 -CMD ["sh","-c","npx --yes @silverbulletmd/server --port 3000 /space"] +# Run the server, allowing to pass in additional argument at run time, e.g. +# docker run -p 3002:3000 -v myspace:/space -it zefhemel/silverbullet --user me:letmein +ENTRYPOINT ["/tini", "--", "deno", "run", "-A", "--unstable", "/silverbullet.js", "/space"] \ No newline at end of file diff --git a/README.md b/README.md index 726caf84..32a9c088 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Or checkout these two videos: [plugs](https://silverbullet.md/🔌_Plugs), and you can customize it to your liking and your workflows. -## Installing Silver Bullet +## Installing Silver Bullet with Deno ### Installing Deno @@ -101,6 +101,37 @@ Simply run this: And restart Silver Bullet. You should be good to go. +## Installing Silver Bullet with Docker + +There is a [docker image on docker hub](https://hub.docker.com/r/zefhemel/silverbullet). To use it, first create a volume to keep your space (markdown) files: + +```shell +docker volume create myspace +``` + +Then, run the container, e.g. as follows: + +```shell +docker run -p 3000:3000 -v myspace:/space -d --name silverbullet zefhemel/silverbullet +``` + +If you'd like to pass in additional command line arguments (e.g. `--user` to add authentication) you can just append those to the command, e.g.: + +```shell +docker run -p 3000:3000 -v myspace:/space -d --name silverbullet zefhemel/silverbullet --user me:letmein +``` + +To build your own version of the docker image, run `./scripts/build_docker.sh`. + +You can also use docker-compose if you prefer. From a silverbullet check-out run: + +```shell +deno task bundle +PORT=3000 docker-compose up +``` + +or similar. + ## Troubleshooting If you upgraded to the new Deno-based Silver Bullet from an old version, you may diff --git a/docker-compose.yaml b/docker-compose.yaml index 4ff35c73..e59b0214 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,11 +1,13 @@ services: - sb: - build: ./ - image: sb - container_name: sb + silverbullet: + image: zefhemel/silverbullet + container_name: silverbullet + restart: unless-stopped + ## To enable additional options, such as BasicAuth, uncomment the following line: + # command: --user='user:pw' + volumes: + - space:/space ports: - ${PORT}:3000 - volumes: - - type: bind - source: ${DIRECTORY} - target: /space \ No newline at end of file +volumes: + space: diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh new file mode 100755 index 00000000..c221a375 --- /dev/null +++ b/scripts/build_docker.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +deno task bundle +docker build -t zefhemel/silverbullet . \ No newline at end of file diff --git a/web/cm_plugins/wiki_link.ts b/web/cm_plugins/wiki_link.ts index c78f444c..fe8df77e 100644 --- a/web/cm_plugins/wiki_link.ts +++ b/web/cm_plugins/wiki_link.ts @@ -58,6 +58,10 @@ export function cleanWikiLinkPlugin(editor: Editor) { break; } } + if (cleanPage === "") { + // Empty page name, or local @anchor use + pageExists = true; + } if (isCursorInRange(view.state, [from, to])) { // Only attach a CSS class, then get out diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 69f49c05..f09e0145 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -154,8 +154,7 @@ release. * **Attachments**: you can now copy & paste, or drag & drop files (images, PDF, whatever you like) into a page and it will be uploaded and appropriately - linked from your page. Attachment size is currently limited to 100mb. -* Changed full-text search page prefix from `@search/` to `🔍` for the {[Search + linked from your page. Attachment size is currently limited to 100mb. Changed full-text search page prefix from `@search/` to `🔍` for the {[Search Space]} command. * `page`, `plug` and `attachment` are now _reserved page names_, you cannot name your pages these (you will get an error when explicitly navigating to them).