Deploy to Cloudflare Workers: content-addressed assets, staged preview tests, rollback notes
This commit is contained in:
10 files changed
+1667
-23
No files matched your search
+21
-10
@@ -1,13 +1,24 @@
|
||||
#!/bin/sh
|
||||
# Builds web/dist: the gallery as wasm plus the page shell.
|
||||
# Builds web/dist; files under a/ are named by content.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
build=$(git rev-parse --short HEAD)-$(date +%s)
|
||||
rm -rf web/dist
|
||||
mkdir -p web/dist
|
||||
GOOS=js GOARCH=wasm go build -trimpath -ldflags="-s -w" -o web/dist/app.wasm ./cmd/web
|
||||
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" web/dist/
|
||||
for f in index.html main.js; do
|
||||
sed "s/__BUILD__/$build/g" "web/$f" > "web/dist/$f"
|
||||
done
|
||||
echo "web/dist built: $build, app.wasm $(wc -c < web/dist/app.wasm) bytes"
|
||||
d=web/dist
|
||||
rm -rf $d
|
||||
mkdir -p $d/a
|
||||
GOOS=js GOARCH=wasm go build -trimpath -ldflags="-s -w" -o $d/app.wasm ./cmd/web
|
||||
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" $d/
|
||||
size=$(wc -c < $d/app.wasm | tr -d ' ')
|
||||
sed "s/__SIZE__/$size/g" web/main.js > $d/main.js
|
||||
# name moves a file into a/ by its content hash.
|
||||
name() {
|
||||
to=a/$1.$(git hash-object "$d/$2" | cut -c1-12).$3
|
||||
mv "$d/$2" "$d/$to"
|
||||
echo "$to"
|
||||
}
|
||||
wasm=$(name app app.wasm wasm)
|
||||
sed -i.bak "s#__WASM__#$wasm#g" $d/main.js && rm $d/main.js.bak
|
||||
exec=$(name wasm_exec wasm_exec.js js)
|
||||
main=$(name main main.js js)
|
||||
sed "s#__EXEC__#$exec#g; s#__MAIN__#$main#g" web/index.html > $d/index.html
|
||||
cp web/_headers $d/
|
||||
echo "web/dist built: $main $wasm ($size bytes)"
|
||||
Reference in new issue
Block a user