Use a release uuid to manage caching
This commit is contained in:
parent
6a78413ad8
commit
c0c68e22ba
@ -29,3 +29,6 @@ emcc --clear-cache --clear-ports
|
|||||||
./pull_minetest.sh
|
./pull_minetest.sh
|
||||||
./build_fsroot.sh
|
./build_fsroot.sh
|
||||||
./build_minetest.sh
|
./build_minetest.sh
|
||||||
|
|
||||||
|
# Finished product
|
||||||
|
./build_www.sh
|
||||||
|
@ -62,33 +62,3 @@ if ! $INCREMENTAL; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
emmake make
|
emmake make
|
||||||
|
|
||||||
echo "Installing into www/"
|
|
||||||
rm -rf "$WWW_DIR"
|
|
||||||
mkdir "$WWW_DIR"
|
|
||||||
|
|
||||||
FILES="minetest.js minetest.wasm minetest.worker.js"
|
|
||||||
|
|
||||||
for I in $FILES; do
|
|
||||||
cp src/"$I" "$WWW_DIR"
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -f src/minetest.wasm.map ]; then
|
|
||||||
cp src/minetest.wasm.map "$WWW_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp "$BASE_DIR/static/index.html" "$WWW_DIR"
|
|
||||||
cp "$BASE_DIR/static/launcher.js" "$WWW_DIR"
|
|
||||||
cp "$BASE_DIR/static/.htaccess" "$WWW_DIR"
|
|
||||||
|
|
||||||
cp "$BUILD_DIR/fsroot.tar.zst" "$WWW_DIR/base.pack"
|
|
||||||
|
|
||||||
echo "DONE"
|
|
||||||
|
|
||||||
popd
|
|
||||||
popd
|
|
||||||
|
|
||||||
# Optional step to deploy to webserver
|
|
||||||
if [ -f deploy.sh ]; then
|
|
||||||
./deploy.sh
|
|
||||||
fi
|
|
||||||
|
55
build_www.sh
Executable file
55
build_www.sh
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash -eux
|
||||||
|
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
# Generate a random hash for this release
|
||||||
|
# This is used as a prefix for cache invalidation
|
||||||
|
SEEDFILE="/tmp/minetest_build_uuid_seed"
|
||||||
|
dd status=none if=/dev/urandom bs=64 count=1 > "$SEEDFILE"
|
||||||
|
md5sum -b "$SEEDFILE" > "$SEEDFILE".hash
|
||||||
|
RELEASE_UUID=`cut -b -12 "$SEEDFILE".hash`
|
||||||
|
|
||||||
|
RELEASE_DIR="$WWW_DIR/$RELEASE_UUID"
|
||||||
|
PACKS_DIR="$RELEASE_DIR/packs"
|
||||||
|
|
||||||
|
echo "Installing release $RELEASE_UUID into www/"
|
||||||
|
rm -rf "$WWW_DIR"
|
||||||
|
mkdir "$WWW_DIR"
|
||||||
|
mkdir "$RELEASE_DIR"
|
||||||
|
mkdir "$PACKS_DIR"
|
||||||
|
|
||||||
|
# Copy emscripten generated files
|
||||||
|
pushd "$BUILD_DIR/minetest/src"
|
||||||
|
EMSCRIPTEN_FILES="minetest.js minetest.wasm minetest.worker.js"
|
||||||
|
for I in $EMSCRIPTEN_FILES; do
|
||||||
|
cp "$I" "$RELEASE_DIR"
|
||||||
|
done
|
||||||
|
if [ -f minetest.wasm.map ]; then
|
||||||
|
cp minetest.wasm.map "$RELEASE_DIR"
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
|
||||||
|
apply_substitutions() {
|
||||||
|
local srcfile="$1"
|
||||||
|
local dstfile="$2"
|
||||||
|
sed "s/%__RELEASE_UUID__%/$RELEASE_UUID/g" "$srcfile" > "$dstfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy static files, replacing $RELEASE_UUID with the id
|
||||||
|
pushd "$BASE_DIR/static"
|
||||||
|
apply_substitutions htaccess_toplevel "$WWW_DIR"/.htaccess
|
||||||
|
apply_substitutions index.html "$WWW_DIR"/index.html
|
||||||
|
apply_substitutions htaccess_release "$RELEASE_DIR"/.htaccess
|
||||||
|
apply_substitutions launcher.js "$RELEASE_DIR"/launcher.js
|
||||||
|
popd
|
||||||
|
|
||||||
|
# Copy base file system pack
|
||||||
|
cp "$BUILD_DIR/fsroot.tar.zst" "$PACKS_DIR/base.pack"
|
||||||
|
|
||||||
|
echo "DONE"
|
||||||
|
|
||||||
|
# Optional script to customize deployment
|
||||||
|
# Use this to add extra data packs, deploy to webserver, etc
|
||||||
|
if [ -f deploy.sh ]; then
|
||||||
|
./deploy.sh
|
||||||
|
fi
|
@ -1,4 +1,7 @@
|
|||||||
#!/bin/bash -eux
|
#!/bin/bash -eux
|
||||||
|
|
||||||
|
# Incremental build for making changes to only minetest / irrlicht
|
||||||
|
|
||||||
export INCREMENTAL=true
|
export INCREMENTAL=true
|
||||||
./build_minetest.sh
|
./build_minetest.sh
|
||||||
|
./build_www.sh
|
||||||
|
1
static/htaccess_release
Normal file
1
static/htaccess_release
Normal file
@ -0,0 +1 @@
|
|||||||
|
Header set Cache-Control "public, max-age=31536000, immutable"
|
@ -6,6 +6,6 @@
|
|||||||
<title>Minetest for the Web</title>
|
<title>Minetest for the Web</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" src="launcher.js"></script>
|
<script type="text/javascript" src="%__RELEASE_UUID__%/launcher.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// These are relative paths
|
||||||
|
const RELEASE_DIR = '%__RELEASE_UUID__%'; // set by build_www.sh
|
||||||
|
const PACKS_DIR = RELEASE_DIR + '/packs';
|
||||||
|
|
||||||
const rtCSS = `
|
const rtCSS = `
|
||||||
body {
|
body {
|
||||||
font-family: arial;
|
font-family: arial;
|
||||||
@ -194,7 +198,7 @@ var pendingPacks = 0;
|
|||||||
function fetchPack(name) {
|
function fetchPack(name) {
|
||||||
pendingPacks += 1;
|
pendingPacks += 1;
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', name + '.pack', true);
|
xhr.open('GET', PACKS_DIR + '/' + name + '.pack', true);
|
||||||
xhr.responseType = 'arraybuffer';
|
xhr.responseType = 'arraybuffer';
|
||||||
xhr.onprogress = (event) => {
|
xhr.onprogress = (event) => {
|
||||||
console.log(`Fetched ${event.loaded} of ${event.total}`);
|
console.log(`Fetched ${event.loaded} of ${event.total}`);
|
||||||
@ -481,6 +485,6 @@ fetchPacks();
|
|||||||
// Start loading the wasm module
|
// Start loading the wasm module
|
||||||
const mtModuleScript = document.createElement("script");
|
const mtModuleScript = document.createElement("script");
|
||||||
mtModuleScript.type = "text/javascript";
|
mtModuleScript.type = "text/javascript";
|
||||||
mtModuleScript.src = "minetest.js";
|
mtModuleScript.src = RELEASE_DIR + "/minetest.js";
|
||||||
mtModuleScript.async = true;
|
mtModuleScript.async = true;
|
||||||
document.body.appendChild(mtModuleScript);
|
document.body.appendChild(mtModuleScript);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user