forked from dstackai/dstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
27 lines (25 loc) · 977 Bytes
/
entrypoint.sh
File metadata and controls
27 lines (25 loc) · 977 Bytes
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
#!/bin/bash
set -e
if [ -n "${GOOGLE_APPLICATION_CREDENTIALS_JSON}" ]; then
GOOGLE_APPLICATION_CREDENTIALS_DIR="${HOME}/.config/gcloud/"
mkdir -p "${GOOGLE_APPLICATION_CREDENTIALS_DIR}"
echo "${GOOGLE_APPLICATION_CREDENTIALS_JSON}" > "${GOOGLE_APPLICATION_CREDENTIALS_DIR}/application_default_credentials.json"
fi
DB_PATH="${HOME}/.dstack/server/data/sqlite.db"
mkdir -p "$(dirname "$DB_PATH")"
if [[ -z "${LITESTREAM_REPLICA_URL}" ]]; then
exec dstack server --host 0.0.0.0
else
if [[ ! -f "$DB_PATH" ]]; then
echo "Attempting Litestream restore..."
if ! output=$(litestream restore -o "$DB_PATH" "$LITESTREAM_REPLICA_URL" 2>&1); then
if echo "$output" | grep -qiE "cannot calc restore plan"; then
echo "No replica snapshots found; starting with empty database."
else
echo "$output" >&2
exit 1
fi
fi
fi
exec litestream replicate -exec "dstack server --host 0.0.0.0" "$DB_PATH" "$LITESTREAM_REPLICA_URL"
fi