Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Feb 5, 2025
1 parent 14e8df1 commit bca1149
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ jobs:

- name: Test
run: |
./cli.sh start_ephemeral_fdb_server &
FDBSERVER_PID=$!
trap "kill -9 $FDBSERVER_PID" EXIT
FDBSERVER_PID=$(./cli.sh start_ephemeral_fdb_server) || exit $?
trap "kill -15 $FDBSERVER_PID" EXIT
sbt --client test
- name: Publish
Expand Down
98 changes: 98 additions & 0 deletions cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s extglob globstar

readonly SCRIPT_DIR="$(dirname "$(realpath "$0")")"
export FDB_CLUSTER_FILE="${FDB_CLUSTER_FILE:-"${SCRIPT_DIR}/.fdb/cluster.file"}"

start_ephemeral_fdb_server() {
local background=${1:-"background"}
local data_dir pid

# shellcheck disable=SC2317
cleanup() {
local exit_code=$?
if [[ -n "${pid:-}" ]] && kill -0 "$pid" 2>/dev/null; then
echo "Stopping fdbserver (PID: $pid)" >&2
kill -15 "$pid" || true
fi
if [[ -n "${data_dir:-}" ]] && [[ -d "$data_dir" ]]; then
rm -rf "$data_dir"
fi
exit "$exit_code"
}
trap cleanup EXIT

if [[ -z "${FDB_CLUSTER_FILE:-}" ]]; then
echo "Error: FDB_CLUSTER_FILE environment variable not set" >&2
return 1
fi

data_dir="$(mktemp -d)" || {
echo "Error: Failed to create temporary directory" >&2
return 1
}
chmod 700 "$data_dir"

mkdir -p "$data_dir/data" "$data_dir/trace" || {
echo "Error: Failed to create data directories" >&2
return 1
}
chmod 700 "$data_dir/data" "$data_dir/trace"

if [[ ! -f "${FDB_CLUSTER_FILE}" ]]; then
local cluster_dir
cluster_dir="$(dirname "$FDB_CLUSTER_FILE")"
mkdir -p "$cluster_dir" || {
echo "Error: Failed to create cluster file directory" >&2
return 1
}
echo "${FDB_CLUSTER_STRING:-t17x3130g3ju1xwxnnwaal6e029grtel:o7q2o6qe@127.0.0.1:4500}" >"$FDB_CLUSTER_FILE"
chmod 600 "$FDB_CLUSTER_FILE"
fi

local fdbserver_path
fdbserver_path="$(command -v fdbserver)"
local -a cmd=(
"$fdbserver_path"
--cluster_file "$FDB_CLUSTER_FILE"
--datadir "$data_dir/data"
--logdir "$data_dir/trace"
--listen_address "127.0.0.1:4500"
--public_address "127.0.0.1:4500"
)

if [[ "$(uname -s)" =~ [dD]arwin ]]; then
echo "macOS detected, requesting sudo access..." >&2
if ! sudo -v; then
echo "Error: Failed to validate sudo access" >&2
return 1
fi
sudo "${cmd[@]}" >&2 &
else
"${cmd[@]}" >&2 &
fi

pid=$!
echo "FDB server process pid=$pid" >&2

if ! timeout 10 fdbcli --exec "status" >&2; then
echo "Failed checking for FDB status" >&2
return 1
fi

if ! fdbcli --exec "configure new single ssd-2" >&2; then
echo "Error: Failed to configure cluster" >&2
return 1
fi

echo "FDB server started successfully (PID: $pid)" >&2

if [[ "$background" == "background" ]]; then
echo "$pid"
else
wait "$pid"
fi
}

"$@"

0 comments on commit bca1149

Please sign in to comment.