Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Explicitly use the backend JAR for local Cypress runs (#66349)

Nemanja Glumac4efe26824e30
diff --git a/bin/build-backend-for-test b/bin/build-backend-for-test
new file mode 100755
index 00000000000..781a19e1d0a
--- /dev/null
+++ b/bin/build-backend-for-test
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+# Build a backend-only uberjar for e2e testing.
+#
+# This script builds a minimal backend uberjar (metabase-backend.jar) that contains
+# only the Clojure backend code. It is NOT the same as the all-in-one metabase.jar
+# which includes backend, frontend, static assets, and other resources.
+#
+# The backend-only jar is used for e2e tests where the frontend is served separately
+# and we only need the backend API server.
+#
+# Features:
+# - Outputs to target/uberjar/metabase-backend.jar
+# - Caches builds based on source file hashes to avoid unnecessary rebuilds
+# - Embeds a source hash in version.properties to detect when rebuilds are needed
+
+set -eu
+
+readonly VERSION_PROPERTY_NAME="src_hash"
+readonly JAR_FILENAME="metabase-backend.jar"
+readonly JAR_PATH="target/uberjar/$JAR_FILENAME"
+
+backend-source-hash() {
+ # hash all the files that might change a backend-only uberjar build
+ (
+ find src deps.edn resources/sample-database.db.mv.db -type f -print0 | xargs -0 shasum ;
+ find resources -type f \( -iname \*.clj -o -iname \*.edn -o -iname \*.yaml -o -iname \*.properties -o -iname \*.html \) -not -name "version.properties" -print0 | xargs -0 shasum ;
+ ) | shasum | awk '{ print $1 }'
+}
+
+backend-jar-hash() {
+ # pulling the version.properties directly from the jar is much faster than starting the JVM
+ unzip -c "$JAR_PATH" version.properties | grep "$VERSION_PROPERTY_NAME" | cut -f2 -d=
+}
+
+check-backend-jar-hash() {
+ local expected_hash actual_hash
+ expected_hash=$(backend-source-hash)
+ actual_hash=$(backend-jar-hash)
+ if [ "$expected_hash" == "$actual_hash" ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+build-backend-uberjar() {
+ local source_hash
+ source_hash=$(backend-source-hash)
+ ./bin/build.sh :steps [:version]
+ echo -e "\n$VERSION_PROPERTY_NAME=$source_hash" >> resources/version.properties
+ MB_JAR_FILENAME="$JAR_FILENAME" ./bin/build.sh :steps [:uberjar]
+}
+
+if [ ! -f "$JAR_PATH" ] || ! check-backend-jar-hash; then
+ echo "Building backend uberjar for e2e testing ($JAR_FILENAME)"
+ build-backend-uberjar
+else
+ echo "Backend uberjar already up to date for e2e testing ($JAR_FILENAME)"
+fi
diff --git a/bin/build-for-test b/bin/build-for-test
deleted file mode 100755
index 0c3a5211c5c..00000000000
--- a/bin/build-for-test
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env bash
-
-set -eu
-
-VERSION_PROPERTY_NAME="src_hash"
-
-source-hash() {
- # hash all the files that might change a backend-only uberjar build (for integration tests)
- (
- find src deps.edn resources/sample-database.db.mv.db -type f -print0 | xargs -0 shasum ;
- find resources -type f \( -iname \*.clj -o -iname \*.edn -o -iname \*.yaml -o -iname \*.properties -o -iname \*.html \) -not -name "version.properties" -print0 | xargs -0 shasum ;
- ) | shasum | awk '{ print $1 }'
-}
-
-uberjar-hash() {
- # java --add-opens java.base/java.nio=ALL-UNNAMED -jar target/uberjar/metabase.jar version | grep -oE 'source_hash [a-f0-9]+' | awk '{ print $2 }'
- # pulling the version.properties directly from the jar is much faster
- unzip -c target/uberjar/metabase.jar version.properties | grep "$VERSION_PROPERTY_NAME" | cut -f2 -d=
-}
-
-check-uberjar-hash() {
- expected_hash=$(source-hash)
- actual_hash=$(uberjar-hash)
- if [ "$expected_hash" == "$actual_hash" ]; then
- return 0
- else
- return 1
- fi
-}
-
-build-uberjar-for-test() {
- ./bin/build.sh :steps [:version]
- echo -e "\n$VERSION_PROPERTY_NAME=$(source-hash)" >> resources/version.properties
- ./bin/build.sh :steps [:uberjar]
-}
-
-if [ ! -f "target/uberjar/metabase.jar" ] || ! check-uberjar-hash; then
- echo "Building uberjar for testing"
- build-uberjar-for-test
-else
- echo "Uberjar already up to date for testing"
-fi
diff --git a/e2e/runner/cypress-runner-backend.js b/e2e/runner/cypress-runner-backend.js
index bd605828163..fa0da1d1710 100755
--- a/e2e/runner/cypress-runner-backend.js
+++ b/e2e/runner/cypress-runner-backend.js
@@ -22,7 +22,7 @@ const CypressBackend = {
this.server = server;
},
- async start() {
+ async start(jarPath = "target/uberjar/metabase.jar") {
if (!this.server) {
this.createServer();
}
@@ -52,22 +52,18 @@ const CypressBackend = {
MB_IS_CYPRESS: "true", // custom flag so we can detect we're running in Cypress, used in tests.
};
- this.server.process = spawn(
- "java",
- [...javaFlags, "-jar", "target/uberjar/metabase.jar"],
- {
- env: {
- ...process.env,
- ...metabaseConfig,
- },
- stdio:
- process.env["DISABLE_LOGGING"] ||
- process.env["DISABLE_LOGGING_BACKEND"]
- ? "ignore"
- : "inherit",
- detached: true,
+ this.server.process = spawn("java", [...javaFlags, "-jar", jarPath], {
+ env: {
+ ...process.env,
+ ...metabaseConfig,
},
- );
+ stdio:
+ process.env["DISABLE_LOGGING"] ||
+ process.env["DISABLE_LOGGING_BACKEND"]
+ ? "ignore"
+ : "inherit",
+ detached: true,
+ });
}
if (!(await isReady(this.server.host))) {
diff --git a/e2e/runner/run_cypress_local.ts b/e2e/runner/run_cypress_local.ts
index e3d6b120df8..64e1e00762b 100644
--- a/e2e/runner/run_cypress_local.ts
+++ b/e2e/runner/run_cypress_local.ts
@@ -85,7 +85,7 @@ const init = async () => {
if (options.BUILD_JAR) {
printBold("⏳ Building backend");
- shell("./bin/build-for-test");
+ shell("./bin/build-backend-for-test");
if (options.START_BACKEND) {
const isBackendRunning = shell(
@@ -109,7 +109,7 @@ const init = async () => {
process.env.MB_INTERNAL_DO_NOT_USE_SAMPLE_DB_DIR = tempSampleDBDir;
printBold("⏳ Starting backend");
- await CypressBackend.start();
+ await CypressBackend.start("target/uberjar/metabase-backend.jar");
}
} else {
printBold(