Skip to content

Commit

Permalink
SilverBullet pivot to become an offline-first PWA (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel authored May 23, 2023
1 parent b256269 commit 5f484be
Show file tree
Hide file tree
Showing 389 changed files with 4,400 additions and 291,045 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git
79 changes: 0 additions & 79 deletions .github/workflows/desktop.yml

This file was deleted.

89 changes: 89 additions & 0 deletions .github/workflows/docker-s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Docker S3

on:
push:
branches:
- "main"
tags:
- "*"
env:
DENO_VERSION: v1.33
# Docker & Registries
ARCHITECTURES: linux/amd64,linux/arm64
IMAGE_NAME: silverbullet-s3
NAMESPACE_GITHUB: silverbulletmd
NAMESPACE_DOCKER: zefhemel
jobs:
docker-build:
runs-on: ubuntu-latest

steps:
- name: Setup repo
uses: actions/checkout@v3

- name: Set up QEMU for multi-arch builds with buildx
uses: docker/setup-qemu-action@v2
with:
platforms: ${{ env.ARCHITECTURES }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: ${{ env.ARCHITECTURES }}

- name: Setup Deno
uses: denoland/setup-deno@d4873ceeec10de6275fecd1f94b6985369d40231
with:
deno-version: ${{ env.DENO_VERSION }}

- 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: Log in to the ghcr Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
#
# MetaData Extract Docu: <https://github.com/docker/metadata-action>
#
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4.4.0
with:
images: |
# Set the different image names(paces) for docker-hub & ghcr
${{ env.NAMESPACE_DOCKER }}/${{ env.IMAGE_NAME }}
ghcr.io/${{ env.NAMESPACE_GITHUB }}/${{ env.IMAGE_NAME }}
tags: |
# <https://github.com/docker/metadata-action#typeref>
# minimal (short sha), enable f desired
# type=sha,enable=true,priority=100,prefix=commit-,suffix=,format=short
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
#
# tag w/ full tag part of git tag: <https://github.com/docker/metadata-action#typesemver>
# only present for `on.push.tags` !
type=semver,pattern={{raw}},enable=true
# type=edge,branch=local # usually this would be the develop branch
- name: Build and push main docker images
uses: docker/build-push-action@v4.0.0
with:
context: .
platforms: ${{ env.ARCHITECTURES }}
push: true
file: Dockerfile.s3
# Disable to get rid of unknown architecture in ghcr
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 5 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ on:
branches:
- "main"
tags:
- "**"
- "*"
env:
DENO_VERSION: v1.32.5
DENO_VERSION: v1.33
# Docker & Registries
ARCHITECTURES: linux/amd64,linux/arm64
IMAGE_NAME: silverbullet
NAMESPACE_GITHUB: silverbulletmd
NAMESPACE_DOCKER: zefhemel
jobs:
docker-build-push:
docker-main:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -76,12 +76,13 @@ jobs:
type=semver,pattern={{raw}},enable=true
# type=edge,branch=develop # usually this would be the develop branch
- name: Build and push Docker images
- name: Build and push main docker images
uses: docker/build-push-action@v4.0.0
with:
context: .
platforms: ${{ env.ARCHITECTURES }}
push: true
file: Dockerfile
# Disable to get rid of unknown architecture in ghcr
provenance: false
tags: ${{ steps.meta.outputs.tags }}
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build & Release

on:
push:
tags:
- "*"
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.33
- name: Run build
run: deno task build
- name: Bundle
run: deno task bundle
- name: Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
files: |
website/CHANGELOG.md
dist/silverbullet.js
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ jobs:
uses: actions/checkout@v3

- name: Setup Deno
# uses: denoland/setup-deno@v1
uses: denoland/setup-deno@d4873ceeec10de6275fecd1f94b6985369d40231
uses: denoland/setup-deno@v1
with:
deno-version: v1.32.5
deno-version: v1.33

- name: Run build
run: deno task build
Expand All @@ -30,4 +29,4 @@ jobs:
run: deno task check

- name: Run tests
run: deno task test
run: deno task test --trace-ops
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
pages
test_space
.DS_Store
dist_bundle
dist_client_bundle
dist_plug_bundle
dist
*.js.map
website_build
data.db*
publish-data.db
/index.json
.idea
deno.lock
node_modules
fly.toml
env.sh
22 changes: 11 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM lukechannings/deno:v1.33.2
# 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
# docker run -v myspace:/space -p3000:3000 -it zefhemel/silverbullet
VOLUME /space

# Accept TARGETARCH as argument
Expand All @@ -20,15 +20,15 @@ ENV SILVERBULLET_USERNAME silverbullet

# Make sure the deno user has access to the space volume
RUN mkdir -p /space \
&& addgroup --gid ${SILVERBULLET_UID_GID} silverbullet \
&& adduser --uid ${SILVERBULLET_UID_GID} --gid ${SILVERBULLET_UID_GID} ${SILVERBULLET_USERNAME} \
&& chown -R ${SILVERBULLET_USERNAME}:${SILVERBULLET_USERNAME} /space \
&& chown -R ${SILVERBULLET_USERNAME}:${SILVERBULLET_USERNAME} /deno-dir \
&& chmod +x /tini \
&& echo "**** cleanup ****" \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf \
&& addgroup --gid ${SILVERBULLET_UID_GID} silverbullet \
&& adduser --uid ${SILVERBULLET_UID_GID} --gid ${SILVERBULLET_UID_GID} ${SILVERBULLET_USERNAME} \
&& chown -R ${SILVERBULLET_USERNAME}:${SILVERBULLET_USERNAME} /space \
&& chown -R ${SILVERBULLET_USERNAME}:${SILVERBULLET_USERNAME} /deno-dir \
&& chmod +x /tini \
&& echo "**** cleanup ****" \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/* \
Expand All @@ -44,4 +44,4 @@ EXPOSE 3000

# 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", "--hostname", "0.0.0.0", "/space"]
ENTRYPOINT /tini -- deno run -A /silverbullet.js -L0.0.0.0 /space
24 changes: 24 additions & 0 deletions Dockerfile.s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This Dockerfile is used to build a Docker image that runs silverbullet with an S3 bucket as a backend
# Configure it with the following environment variables

# AWS_ACCESS_KEY_ID=XXXX
# AWS_SECRET_ACCESS_KEY=XXXX
# AWS_ENDPOINT=s3.eu-central-1.amazonaws.com
# AWS_REGION=eu-central-1
# AWS_BUCKET=my-sb-bucket

FROM denoland/deno:alpine-1.33.2

# Copy the bundled version of silverbullet into the container
ADD ./dist/silverbullet.js /silverbullet.js

# 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

# 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 deno run -A /silverbullet.js -L 0.0.0.0 s3://
35 changes: 35 additions & 0 deletions build_bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { denoPlugins, esbuild } from "./plugos/deps.ts";

await Deno.mkdir("dist", { recursive: true });
await esbuild.build({
entryPoints: {
silverbullet: "silverbullet.ts",
},
outdir: "dist",
format: "esm",
absWorkingDir: Deno.cwd(),
bundle: true,
treeShaking: true,
sourcemap: false,
minify: false,
plugins: [
{
name: "json",
setup: (build) =>
build.onLoad({ filter: /\.json$/ }, () => ({ loader: "json" })),
},

...denoPlugins({
importMapURL: new URL("./import_map.json", import.meta.url)
.toString(),
}),
],
});
const bundleJs = await Deno.readTextFile("dist/silverbullet.js");
// Patch output JS with import.meta.main override to avoid ESBuild CLI handling
await Deno.writeTextFile(
"dist/silverbullet.js",
"import.meta.main = false;\n" + bundleJs,
);
console.log("Output in dist/silverbullet.js");
esbuild.stop();
17 changes: 0 additions & 17 deletions build_mobile.ts

This file was deleted.

3 changes: 0 additions & 3 deletions build_plugs.sh

This file was deleted.

Loading

0 comments on commit 5f484be

Please sign in to comment.