-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathdocker-run.sh
More file actions
executable file
·119 lines (112 loc) · 5.42 KB
/
Copy pathdocker-run.sh
File metadata and controls
executable file
·119 lines (112 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
# Run the blocknote-e2e image with live source.
#
# The image installs deps but builds nothing (see tests/Dockerfile); the suite
# resolves every @blocknote/* package to its src/ (see vite.config.browser.ts).
# So we bind-mount each packages/*/src over the image's (source-less) tree. Only
# the src/ dirs are mounted — never a whole package dir — so the image's Linux
# node_modules (pnpm's isolated symlinks live alongside src/) stay intact.
# Editing packages/*/src is therefore picked up on the next run with no rebuild.
# Example apps are baked into the image and transpiled from source at test time.
#
# Usage: tests/docker-run.sh [docker run flags...] -- [vitest/vp args...]
#
# `set -u` is intentionally omitted: macOS bash 3.2 errors on empty-array
# expansion under it, and both the flag and entrypoint-arg arrays may be empty.
set -eo pipefail
cd "$(git rev-parse --show-toplevel)"
docker_flags=()
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
docker_flags+=("$1")
shift
done
# Drop the "--" separator; the rest are entrypoint (vp test) args.
[ "$#" -gt 0 ] && shift
entrypoint_args=("$@")
# Auto-rebuild the image if its content hash label doesn't match the current
# repo state. The hash covers every file that affects the image's contents: the
# Dockerfile itself, plus everything it bakes in — the lockfile, workspace file,
# all package.json files, patches, and example sources. Generated output dirs
# are pruned: `pkg/` is wasm-pack's, and it emits a package.json, so without
# that prune, building the wasm this script *requires* would itself invalidate
# the image and force a second full rebuild. When they differ the
# image is rebuilt in place
# (Docker's layer cache makes this fast when only a leaf changed).
_dep_files() {
# Print the sorted list of files that are baked into the image.
{
echo pnpm-lock.yaml
echo pnpm-workspace.yaml
echo tests/Dockerfile
find patches examples \( -name node_modules -prune \) -o -type f -print 2>/dev/null
find . -name package.json \
-not -path '*/node_modules/*' \
-not -path '*/.git/*' \
-not -path '*/dist/*' \
-not -path '*/pkg/*'
} | sort -u
}
_content_hash() {
# sha256 of the concatenated sorted file contents; shasum is available on
# macOS & Linux (util-linux / coreutils).
_dep_files | xargs shasum -a 256 -- 2>/dev/null | shasum -a 256 | cut -d' ' -f1
}
current_hash=$(_content_hash)
image_hash=$(docker inspect --format '{{index .Config.Labels "blocknote.deps-hash"}}' blocknote-e2e 2>/dev/null || true)
if [ "$current_hash" != "$image_hash" ]; then
echo "blocknote-e2e image is out of date (deps/examples changed) — rebuilding…" >&2
docker build -t blocknote-e2e \
--label "blocknote.deps-hash=$current_hash" \
-f tests/Dockerfile .
fi
mounts=()
for src in packages/*/src; do
mounts+=(-v "$PWD/$src:/work/$src")
done
# xl-typst-compiler is consumed through its build outputs (see
# vite.config.browser.ts): the wasm + glue in pkg/ and the built TS wrapper.
# Build them first (build:wasm + build) - they are gitignored, so the image
# cannot contain them.
for out in pkg dist types; do
if [ ! -d "packages/xl-typst-compiler/$out" ]; then
echo "packages/xl-typst-compiler/$out is missing - build it first:" >&2
echo " pnpm exec vp run --filter @blocknote/xl-typst-compiler build" >&2
echo "(compiles the Rust wasm too when needed - requires rustup)" >&2
exit 1
fi
mounts+=(-v "$PWD/packages/xl-typst-compiler/$out:/work/packages/xl-typst-compiler/$out")
done
# The test files and browser config (callers iterate on these too).
mounts+=(
-v "$PWD/tests/src:/work/tests/src"
-v "$PWD/tests/vite.config.browser.ts:/work/tests/vite.config.browser.ts"
-v "$PWD/tests/vitestSetup.browser.ts:/work/tests/vitestSetup.browser.ts"
)
# The suggestion-gallery scenarios import the shared `testDocument` (aliased to
# ../shared in vite.config.browser.ts). Only shared/package.json is baked into the
# image (for the install), so mount the two source files it needs — they're
# transpiled at test time just like packages/*/src (mounting individual files
# keeps the image's node_modules symlinks intact).
mounts+=(
-v "$PWD/shared/testDocument.ts:/work/shared/testDocument.ts"
-v "$PWD/shared/testDocumentBlocks.ts:/work/shared/testDocumentBlocks.ts"
-v "$PWD/shared/formatConversionTestUtil.ts:/work/shared/formatConversionTestUtil.ts"
-v "$PWD/shared/api:/work/shared/api"
-v "$PWD/shared/util:/work/shared/util"
-v "$PWD/shared/assets:/work/shared/assets"
)
# Mount the report dir so the html reporter's output lands on the host instead
# of being thrown away with the container. Created on the host first so docker
# binds the dir (not an anonymous mountpoint).
mkdir -p "$PWD/tests/playwright-report"
mounts+=(-v "$PWD/tests/playwright-report:/work/tests/playwright-report")
# --init : avoid PID-1 special treatment / zombie processes
# --ipc=host : Chromium needs this in Docker to avoid OOM crashes
# Both flags are Playwright's recommended baseline for running its image.
# SKIP_DOCS_POSTINSTALL : the `vp test` entrypoint runs a deps-status check that
# re-runs `pnpm install` inside the container; without this the docs
# fumadocs-mdx postinstall runs and fails (see docs/package.json). The e2e
# suite never touches docs, so skip it here too — mirroring the image build.
exec docker run --rm --init --ipc=host -e SKIP_DOCS_POSTINSTALL=1 \
"${docker_flags[@]}" "${mounts[@]}" \
blocknote-e2e "${entrypoint_args[@]}"