fix(runtime): preserve lifecycle command options

This commit is contained in:
XiaoSeS 2026-09-17 14:04:48 +08:00 committed by GitHub
parent 120d616ca5
commit 48376069db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 108 additions and 11 deletions

View file

@ -23,6 +23,7 @@ POSTGRES_IMAGE_VALUE="${POSTGRES_IMAGE:-}"
REDIS_IMAGE_VALUE="${REDIS_IMAGE:-}"
DISABLE_SCANNER=false
USE_ALIYUN=false
EXPLICIT_REF=false
while [ "$#" -gt 0 ]; do
case "$1" in
@ -53,6 +54,7 @@ while [ "$#" -gt 0 ]; do
--ref)
[ "$#" -ge 2 ] || { echo "Missing value for --ref" >&2; exit 1; }
SKILLHUB_REF="$2"
EXPLICIT_REF=true
shift 2
;;
--server-image)
@ -119,12 +121,10 @@ done
if [ "$USE_ALIYUN" = "true" ]; then
SKILLHUB_RAW_BASE="${SKILLHUB_RAW_BASE:-https://imageless.oss-cn-beijing.aliyuncs.com}"
RUNTIME_SCRIPT_URL="$SKILLHUB_RAW_BASE/runtime.sh"
RUNTIME_SOURCE_ARG=" --aliyun"
echo "Using Aliyun OSS for runtime files: $SKILLHUB_RAW_BASE"
else
SKILLHUB_RAW_BASE="${SKILLHUB_RAW_BASE:-https://raw.githubusercontent.com/iflytek/skillhub/$SKILLHUB_REF}"
RUNTIME_SCRIPT_URL="$SKILLHUB_RAW_BASE/scripts/runtime.sh"
RUNTIME_SOURCE_ARG=""
echo "Using GitHub raw for runtime files: $SKILLHUB_RAW_BASE"
fi
COMPOSE_FILE="$SKILLHUB_HOME/compose.release.yml"
@ -376,6 +376,85 @@ run_compose() {
$compose_cmd --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@"
}
shell_quote() {
case "$1" in
*[!A-Za-z0-9_./:=@%+-]*)
printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"
;;
*)
printf '%s' "$1"
;;
esac
}
append_runtime_flag() {
RUNTIME_LIFECYCLE_ARGS="$RUNTIME_LIFECYCLE_ARGS $1"
}
append_runtime_option() {
RUNTIME_LIFECYCLE_ARGS="$RUNTIME_LIFECYCLE_ARGS $1 $(shell_quote "$2")"
}
build_runtime_lifecycle_args() {
RUNTIME_LIFECYCLE_ARGS=""
if [ "$USE_ALIYUN" = "true" ]; then
append_runtime_flag "--aliyun"
elif [ "$EXPLICIT_REF" = "true" ] || [ "$SKILLHUB_REF" != "main" ]; then
append_runtime_option "--ref" "$SKILLHUB_REF"
fi
if [ -n "$SKILLHUB_VERSION_VALUE" ]; then
append_runtime_option "--version" "$SKILLHUB_VERSION_VALUE"
fi
if [ "$SKILLHUB_HOME" != "$SKILLHUB_HOME_DEFAULT" ]; then
append_runtime_option "--home" "$SKILLHUB_HOME"
fi
if [ -n "$SKILLHUB_PUBLIC_BASE_URL_VALUE" ]; then
append_runtime_option "--public-url" "$SKILLHUB_PUBLIC_BASE_URL_VALUE"
fi
if [ -n "$SKILLHUB_MIRROR_REGISTRY_VALUE" ] && [ "$USE_ALIYUN" != "true" ]; then
append_runtime_option "--mirror-registry" "$SKILLHUB_MIRROR_REGISTRY_VALUE"
fi
if [ -n "$SKILLHUB_SERVER_IMAGE_VALUE" ]; then
append_runtime_option "--server-image" "$SKILLHUB_SERVER_IMAGE_VALUE"
fi
if [ -n "$SKILLHUB_WEB_IMAGE_VALUE" ]; then
append_runtime_option "--web-image" "$SKILLHUB_WEB_IMAGE_VALUE"
fi
if [ -n "$SKILLHUB_SCANNER_IMAGE_VALUE" ]; then
append_runtime_option "--scanner-image" "$SKILLHUB_SCANNER_IMAGE_VALUE"
fi
if [ -n "$POSTGRES_IMAGE_VALUE" ]; then
append_runtime_option "--postgres-image" "$POSTGRES_IMAGE_VALUE"
fi
if [ -n "$REDIS_IMAGE_VALUE" ]; then
append_runtime_option "--redis-image" "$REDIS_IMAGE_VALUE"
fi
if [ "$DISABLE_SCANNER" = "true" ]; then
append_runtime_flag "--no-scanner"
fi
}
print_runtime_command() {
lifecycle_command="$1"
printf ' curl -fsSL %s | sh -s -- %s%s\n' \
"$RUNTIME_SCRIPT_URL" \
"$lifecycle_command" \
"$RUNTIME_LIFECYCLE_ARGS"
}
build_runtime_lifecycle_args
prepare_runtime_files
case "$COMMAND" in
@ -390,17 +469,17 @@ case "$COMMAND" in
run_compose up -d
fi
PUBLIC_URL="${SKILLHUB_PUBLIC_BASE_URL_VALUE:-http://localhost}"
HOME_ARG=""
if [ "$SKILLHUB_HOME" != "$SKILLHUB_HOME_DEFAULT" ]; then
HOME_ARG=" --home $SKILLHUB_HOME"
fi
cat <<EOF
SkillHub runtime started.
Web UI: $PUBLIC_URL
Backend API: http://localhost:8080
Runtime dir: $SKILLHUB_HOME
Stop with:
curl -fsSL $RUNTIME_SCRIPT_URL | sh -s -- down$RUNTIME_SOURCE_ARG$HOME_ARG
Lifecycle commands:
$(print_runtime_command up)
$(print_runtime_command down)
$(print_runtime_command ps)
$(print_runtime_command logs)
$(print_runtime_command pull)
EOF
;;
down)

View file

@ -92,20 +92,38 @@ grep -Fq "Generated SKILLHUB_DOWNLOAD_ANON_COOKIE_SECRET" "$stdout_generated" \
if grep -Fq "$generated_secret" "$stdout_generated"; then
fail "runtime must not print the generated secret value"
fi
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- down --home $home_generated" "$stdout_generated" \
|| fail "GitHub runtime should print the scripts/runtime.sh stop URL"
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- down --version sha-test --home $home_generated --public-url http://localhost" "$stdout_generated" \
|| fail "GitHub runtime should print a reproducible down command"
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- up --version sha-test --home $home_generated --public-url http://localhost" "$stdout_generated" \
|| fail "GitHub runtime should print a reproducible up command"
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- ps --version sha-test --home $home_generated --public-url http://localhost" "$stdout_generated" \
|| fail "GitHub runtime should print a reproducible ps command"
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- logs --version sha-test --home $home_generated --public-url http://localhost" "$stdout_generated" \
|| fail "GitHub runtime should print a reproducible logs command"
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- pull --version sha-test --home $home_generated --public-url http://localhost" "$stdout_generated" \
|| fail "GitHub runtime should print a reproducible pull command"
home_aliyun="$tmp/aliyun"
stdout_aliyun="$tmp/aliyun.out"
mkdir -p "$home_aliyun"
run_runtime "$home_aliyun" "$bin_dir" "$stdout_aliyun" --aliyun
grep -Fq "curl -fsSL file://$REPO_ROOT/runtime.sh | sh -s -- down --aliyun --home $home_aliyun" "$stdout_aliyun" \
grep -Fq "curl -fsSL file://$REPO_ROOT/runtime.sh | sh -s -- down --aliyun --version sha-test --home $home_aliyun --public-url http://localhost" "$stdout_aliyun" \
|| fail "Aliyun runtime should preserve the root runtime.sh URL and --aliyun source mode"
if grep -Fq "file://$REPO_ROOT/scripts/runtime.sh" "$stdout_aliyun"; then
fail "Aliyun runtime must not print the GitHub scripts/runtime.sh path"
fi
home_ref="$tmp/ref"
stdout_ref="$tmp/ref.out"
mkdir -p "$home_ref"
run_runtime "$home_ref" "$bin_dir" "$stdout_ref" --ref 36de54157bff59c18c5eff255d2c158df45a3e2a --no-scanner
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- down --ref 36de54157bff59c18c5eff255d2c158df45a3e2a --version sha-test --home $home_ref --public-url http://localhost --no-scanner" "$stdout_ref" \
|| fail "GitHub runtime should preserve pinned --ref and --no-scanner in down command"
grep -Fq "curl -fsSL file://$REPO_ROOT/scripts/runtime.sh | sh -s -- up --ref 36de54157bff59c18c5eff255d2c158df45a3e2a --version sha-test --home $home_ref --public-url http://localhost --no-scanner" "$stdout_ref" \
|| fail "GitHub runtime should preserve pinned --ref and --no-scanner in up command"
home_preserved="$tmp/preserved"
stdout_preserved="$tmp/preserved.out"
mkdir -p "$home_preserved"