Skip to content

Commit ca2e649

Browse files
committed
fix: retry console api key provisioning in install script
1 parent 51fe872 commit ca2e649

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

deploy/install-server.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,36 @@ require_secret_with_default() {
117117
create_console_api_key() {
118118
local output=""
119119
local api_key_line=""
120-
121-
output=$(
122-
cd "$TARGET_DIR"
123-
"${COMPOSE_CMD[@]}" run --rm -T --no-deps simprint-console-gateway \
124-
--config /app/configs/console.toml apikey create --name "extension-sync"
125-
)
126-
127-
api_key_line=$(printf '%s\n' "$output" | sed -n 's/^[[:space:]]*X-API-KEY: //p' | tail -n 1)
128-
129-
if [ -z "$api_key_line" ] || [ "${api_key_line#*:}" = "$api_key_line" ]; then
130-
echo "Error: failed to create Console API key for extension sync." >&2
131-
echo "$output" >&2
132-
exit 1
133-
fi
134-
135-
EXTENSION_SYNC_API_KEY_ID="${api_key_line%%:*}"
136-
EXTENSION_SYNC_API_KEY_SECRET="${api_key_line#*:}"
120+
local attempt=1
121+
local max_attempts=20
122+
123+
while [ "$attempt" -le "$max_attempts" ]; do
124+
if output=$(
125+
cd "$TARGET_DIR"
126+
"${COMPOSE_CMD[@]}" run --rm -T --no-deps simprint-console-gateway \
127+
--config /app/configs/console.toml apikey create --name "extension-sync" 2>&1
128+
); then
129+
api_key_line=$(printf '%s\n' "$output" | sed -n 's/^[[:space:]]*X-API-KEY: //p' | tail -n 1)
130+
131+
if [ -n "$api_key_line" ] && [ "${api_key_line#*:}" != "$api_key_line" ]; then
132+
EXTENSION_SYNC_API_KEY_ID="${api_key_line%%:*}"
133+
EXTENSION_SYNC_API_KEY_SECRET="${api_key_line#*:}"
134+
return 0
135+
fi
136+
137+
echo "Error: Console API key command succeeded but returned an unexpected payload." >&2
138+
echo "$output" >&2
139+
exit 1
140+
fi
141+
142+
echo "Waiting for simprint-console-gateway to finish database initialization (attempt $attempt/$max_attempts)..."
143+
sleep 3
144+
attempt=$((attempt + 1))
145+
done
146+
147+
echo "Error: failed to create Console API key for extension sync after $max_attempts attempts." >&2
148+
echo "$output" >&2
149+
exit 1
137150
}
138151

139152
if ! check_command docker; then

0 commit comments

Comments
 (0)