-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathbuild.sh
executable file
·129 lines (105 loc) · 4.5 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
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
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
function fail() {
local error="${*:-Unknown error}"
echo "$(chalk red "${error}")"
exit 1
}
joined_arguments=""
# Function to check and build the Java JAR file for iceberg if needed
function check_and_build_jar() {
local connector="$1"
echo "============================== Checking for Iceberg JAR file =============================="
# Check if the JAR exists in the base directory
if [ -f "debezium-server-iceberg-sink.jar" ]; then
echo "JAR file found in base directory."
return 0
fi
# Check in the target directory
if [ -f "writers/iceberg/debezium-server-iceberg-sink/target/debezium-server-iceberg-sink-0.0.1-SNAPSHOT.jar" ]; then
echo "JAR file found in target directory, copying to base directory..."
cp writers/iceberg/debezium-server-iceberg-sink/target/debezium-server-iceberg-sink-0.0.1-SNAPSHOT.jar ./debezium-server-iceberg-sink.jar
return 0
fi
# If JAR not found, build it
echo "Iceberg JAR file not found. Building with Maven..."
# Store current directory
local current_dir=$(pwd)
# Navigate to the Maven project directory
if [ -d "writers/iceberg/debezium-server-iceberg-sink" ]; then
cd writers/iceberg/debezium-server-iceberg-sink
else
fail "Cannot find Iceberg Maven project directory."
fi
# Build with Maven
mvn clean package -Dmaven.test.skip=true || fail "Maven build failed"
# Return to original directory
cd "$current_dir"
# Copy the JAR file to the base directory
if [ -f "writers/iceberg/debezium-server-iceberg-sink/target/debezium-server-iceberg-sink-0.0.1-SNAPSHOT.jar" ]; then
cp writers/iceberg/debezium-server-iceberg-sink/target/debezium-server-iceberg-sink-0.0.1-SNAPSHOT.jar ./debezium-server-iceberg-sink.jar
else
fail "Maven build completed but could not find the JAR file."
fi
echo "============================== JAR file built and copied to base directory =============================="
}
function build_and_run() {
local connector="$1"
if [[ $2 == "driver" ]]; then
path=drivers/$connector
elif [[ $2 == "adapter" ]]; then
path=adapters/$connector
else
fail "The argument does not have a recognized prefix."
fi
# Check if writer.json is specified in the arguments
local writer_file=""
local using_iceberg=false
# Parse the arguments to find the writer.json file path
local previous_arg=""
for arg in $joined_arguments; do
if [[ "$previous_arg" == "--destination" || "$previous_arg" == "-d" ]]; then
writer_file="$arg"
break
fi
previous_arg="$arg"
done
# If writer file was found, check if it contains iceberg
if [[ -n "$writer_file" && -f "$writer_file" ]]; then
echo "Checking writer file: $writer_file for iceberg destination..."
if grep -qi "iceberg" "$writer_file"; then
echo "Iceberg destination detected in writer file."
using_iceberg=true
fi
fi
# If using iceberg, check and potentially build the JAR
if [[ "$using_iceberg" == true ]]; then
check_and_build_jar "iceberg"
fi
cd $path || fail "Failed to navigate to path: $path"
go mod tidy
go build -ldflags="-w -s -X constants/constants.version=${GIT_VERSION} -X constants/constants.commitsha=${GIT_COMMITSHA} -X constants/constants.releasechannel=${RELEASE_CHANNEL}" -o olake main.go || fail "build failed"
echo "============================== Executing connector: $connector with args [$joined_arguments] =============================="
./olake $joined_arguments
}
if [ $# -gt 0 ]; then
argument="$1"
# Capture and join remaining arguments, skipping the first one
remaining_arguments=("${@:2}")
joined_arguments=$(
IFS=' '
echo "${remaining_arguments[*]}"
)
if [[ $argument == driver-* ]]; then
driver="${argument#driver-}"
echo "============================== Building driver: $driver =============================="
build_and_run "$driver" "driver" "$joined_arguments"
elif [[ $argument == adapter-* ]]; then
adapter="${argument#adapter-}"
echo "============================== Building adapter: $adapter =============================="
build_and_run "$adapter" "adapter" "$joined_arguments"
else
fail "The argument does not have a recognized prefix."
fi
else
fail "No arguments provided."
fi