-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.sh
executable file
·93 lines (76 loc) · 3.63 KB
/
build.sh
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
#!/bin/bash
# Set Spark version information
DEFAULT_SPARK_MAJOR_VERSION="3.5"
DEFAULT_SPARK_VERSION="3.5.0"
LIGT_VERSION="0.2"
USER_SPARK_MAJOR_VERSION=""
USER_SPARK_VERSION=""
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-DdefaultSparkMajorVersion=*)
USER_SPARK_MAJOR_VERSION="${1#*=}"
shift
;;
-DdefaultSparkVersion=*)
USER_SPARK_VERSION="${1#*=}"
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Assign default values if user input is missing
SPARK_MAJOR_VERSION="${USER_SPARK_MAJOR_VERSION:-$DEFAULT_SPARK_MAJOR_VERSION}"
SPARK_VERSION="${USER_SPARK_VERSION:-$DEFAULT_SPARK_VERSION}"
# echo "SPARK_MAJOR_VERSION: $SPARK_MAJOR_VERSION"
# echo "SPARK_VERSION: $SPARK_VERSION"
OUTPUT_ZIP="lightning-metastore-$SPARK_MAJOR_VERSION-$LIGT_VERSION.zip"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Set the target folder inside the zip
TARGET_FOLDER="lightning-metastore-$SPARK_MAJOR_VERSION-$LIGT_VERSION"
# Step 1: Build front-end (React)
echo "Building front-end..."
cd "$SCRIPT_DIR/gui" || { echo "Failed to navigate to GUI directory"; exit 1; }
npm install || { echo "Dependency installation failed"; exit 1; }
npm run build || { echo "React build failed"; exit 1; }
# Prepare target directory structure inside /tmp/tar_build
rm -rf "/tmp/tar_build"
mkdir -p "/tmp/tar_build"
mkdir -p "/tmp/tar_build/$TARGET_FOLDER/web"
mkdir -p "/tmp/tar_build/$TARGET_FOLDER/lib"
mkdir -p "/tmp/tar_build/$TARGET_FOLDER/bin"
mkdir -p "/tmp/tar_build/$TARGET_FOLDER/model"
mkdir -p "/tmp/tar_build/$TARGET_FOLDER/3rd-party-lib"
mkdir -p "/tmp/tar_build/$TARGET_FOLDER/history"
# Copy built front-end files
cp -r build/* "/tmp/tar_build/$TARGET_FOLDER/web" || { echo "Failed to copy front-end files"; exit 1; }
# Step 2: Build back-end (Gradle, Scala, Spark)
echo "Building back-end..."
cd "$SCRIPT_DIR" || { echo "Failed to navigate to project root"; exit 1; }
./gradlew clean build -DdefaultSparkMajorVersion="$SPARK_MAJOR_VERSION" -DdefaultSparkVersion="$SPARK_VERSION" || { echo "Gradle build failed"; exit 1; }
# Step 3: Extract JAR files from distribution package
echo "Extracting JAR files from distribution..."
DIST_DIR="$SCRIPT_DIR/spark/v${SPARK_MAJOR_VERSION}/spark-runtime/build/distributions"
# Find tar or zip file in the directory and extract JARs
if ls "$DIST_DIR/lightning-metastore-${SPARK_MAJOR_VERSION}"*.tar 1> /dev/null 2>&1; then
echo "Found tar distribution"
tar -xvf "$DIST_DIR/lightning-metastore-${SPARK_MAJOR_VERSION}"*.tar -C "/tmp/tar_build/$TARGET_FOLDER/lib" --strip-components=2 '*.jar' || { echo "Failed to extract JARs from tar"; exit 1; }
elif ls "$DIST_DIR/lightning-metastore-${SPARK_MAJOR_VERSION}"*.zip 1> /dev/null 2>&1; then
echo "Found zip distribution"
unzip "$DIST_DIR/lightning-metastore-${SPARK_MAJOR_VERSION}"*.zip '*.jar' -d "/tmp/tar_build/$TARGET_FOLDER/lib" || { echo "Failed to extract JARs from zip"; exit 1; }
else
echo "Distribution package not found"; exit 1;
fi
# Step 4: Copy scripts from spark-common/spark-shell directory to bin
echo "Copying scripts to bin..."
cp "$SCRIPT_DIR/spark/spark-shell"/*.sh "/tmp/tar_build/$TARGET_FOLDER/bin" || { echo "Failed to copy scripts"; exit 1; }
# Step 5: Package all files into a zip archive in the project root
echo "Packaging files into zip archive..."
cd /tmp/tar_build || { echo "Failed to navigate to /tmp/tar_build"; exit 1; }
zip -r "$OLDPWD/build/$OUTPUT_ZIP" "$TARGET_FOLDER" || { echo "Zip packaging failed"; exit 1; }
cd - || { echo "Failed to return to previous directory"; exit 1; }
# Build completed
echo "Build and packaging completed successfully: $OUTPUT_ZIP"