






























@@ -29,9 +29,83 @@ jobs:
2929shell: pwsh
3030steps:
3131 - name: Begin Testbox
32-uses: useblacksmith/begin-testbox@d0e04585c26905fdd92c94a09c159544c7ee1b67
33-with:
34-testbox_id: ${{ inputs.testbox_id }}
32+shell: bash
33+env:
34+TESTBOX_ID: ${{ inputs.testbox_id }}
35+run: |
36+ set -euo pipefail
37+38+ metadata_port="${METADATA_PORT:-}"
39+ if [ -z "$metadata_port" ]; then
40+ metadata_port="$(cat /proc/cmdline | tr ' ' '\n' | grep '^metadata_port=' | cut -d= -f2)"
41+ fi
42+ if [ -z "$metadata_port" ]; then
43+ echo "metadata_port not found in kernel cmdline" >&2
44+ exit 1
45+ fi
46+47+ metadata_addr="192.168.127.1:${metadata_port}"
48+ state=/tmp/.testbox
49+ mkdir -p "$state"
50+ chmod 700 "$state"
51+52+ installation_model_id="$(curl -s --connect-timeout 2 --max-time 5 "http://${metadata_addr}/installationModelID")"
53+ api_url="$(curl -s --connect-timeout 2 --max-time 5 "http://${metadata_addr}/backendURL")"
54+ auth_token="$(curl -s --connect-timeout 2 --max-time 5 "http://${metadata_addr}/stickyDiskToken")"
55+56+ if [ -z "$api_url" ] || [ -z "$installation_model_id" ] || [ -z "$auth_token" ]; then
57+ echo "could not read required Blacksmith metadata" >&2
58+ exit 1
59+ fi
60+61+ if [ -n "${BLACKSMITH_HOSTNAME:-}" ]; then
62+ runner_host="$BLACKSMITH_HOSTNAME"
63+ else
64+ runner_host="${BLACKSMITH_HOST_PUBLIC_IP:-}"
65+ fi
66+ runner_ssh_port="${BLACKSMITH_SSH_PORT:-22}"
67+68+ response="$(curl -s -f -X POST "${api_url}/api/testbox/phone-home" \
69+ -H "Content-Type: application/json" \
70+ -H "Authorization: Bearer ${auth_token}" \
71+ -d "{
72+ \"testbox_id\": \"${TESTBOX_ID}\",
73+ \"installation_model_id\": ${installation_model_id},
74+ \"status\": \"hydrating\",
75+ \"ip_address\": \"${runner_host}\",
76+ \"ssh_port\": \"${runner_ssh_port}\",
77+ \"working_directory\": \"${GITHUB_WORKSPACE}\",
78+ \"adopted_run_id\": \"${GITHUB_RUN_ID}\",
79+ \"metadata\": {}
80+ }" 2>/dev/null || true)"
81+82+ echo "$TESTBOX_ID" > "$state/testbox_id"
83+ echo "$installation_model_id" > "$state/installation_model_id"
84+ echo "$auth_token" > "$state/auth_token"
85+ echo "$api_url" > "$state/api_url"
86+ echo "$runner_host" > "$state/runner_host"
87+ echo "$runner_ssh_port" > "$state/runner_ssh_port"
88+ echo "$GITHUB_WORKSPACE" > "$state/working_directory"
89+ echo "$GITHUB_RUN_ID" > "$state/adopted_run_id"
90+91+ if [ -n "$response" ] && echo "$response" | jq -e . >/dev/null 2>&1; then
92+ echo "$response" | jq -r '.ssh_public_key // empty' > "$state/ssh_public_key"
93+ idle_timeout="$(echo "$response" | jq -r '.idle_timeout // empty')"
94+ echo "${idle_timeout:-10}" > "$state/idle_timeout"
95+ echo "phone-home response=json"
96+ else
97+ printf '%s\n' "$response" > "$state/ssh_public_key"
98+ echo "10" > "$state/idle_timeout"
99+ echo "phone-home response=raw"
100+ fi
101+102+ ssh_public_key="$(cat "$state/ssh_public_key" 2>/dev/null || true)"
103+ if [ -n "$ssh_public_key" ]; then
104+ mkdir -p ~/.ssh
105+ printf '%s\n' "$ssh_public_key" >> ~/.ssh/authorized_keys
106+ chmod 700 ~/.ssh
107+ chmod 600 ~/.ssh/authorized_keys
108+ fi
3510936110 - name: Checkout
37111uses: actions/checkout@v6
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。