Add detailed diagnostics to Dokploy deployment workflow
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 4m2s
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 4m2s
This commit is contained in:
@@ -33,8 +33,11 @@ jobs:
|
||||
archive_file="$(mktemp "$temp_root/minegeo-dokploy-source.XXXXXX")"
|
||||
response_file="$(mktemp "$temp_root/minegeo-dokploy-response.XXXXXX")"
|
||||
deployment_file="$(mktemp "$temp_root/minegeo-dokploy-status.XXXXXX")"
|
||||
metrics_file="$(mktemp "$temp_root/minegeo-dokploy-metrics.XXXXXX")"
|
||||
error_file="$(mktemp "$temp_root/minegeo-dokploy-errors.XXXXXX")"
|
||||
headers_file="$(mktemp "$temp_root/minegeo-dokploy-headers.XXXXXX")"
|
||||
cleanup() {
|
||||
rm -f "$auth_file" "$archive_file" "$response_file" "$deployment_file"
|
||||
rm -f "$auth_file" "$archive_file" "$response_file" "$deployment_file" "$metrics_file" "$error_file" "$headers_file"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
@@ -42,24 +45,57 @@ jobs:
|
||||
printf 'x-api-key: %s\n' "$DOKPLOY_API_KEY" > "$auth_file"
|
||||
unset DOKPLOY_API_KEY
|
||||
|
||||
echo "[Dokploy] Workflow revision: $(git rev-parse HEAD)"
|
||||
curl --version | head -n 2
|
||||
node scripts/dokploy-diagnostics.mjs environment "$DOKPLOY_URL"
|
||||
|
||||
dokploy_request() {
|
||||
label="$1"
|
||||
body_file="$2"
|
||||
shift 2
|
||||
: > "$body_file"
|
||||
: > "$headers_file"
|
||||
: > "$metrics_file"
|
||||
: > "$error_file"
|
||||
echo "[Dokploy] Starting $label at $(date -u '+%Y-%m-%dT%H:%M:%SZ')" >&2
|
||||
if curl --silent --show-error \
|
||||
--header "@$auth_file" \
|
||||
--dump-header "$headers_file" \
|
||||
--output "$body_file" \
|
||||
--write-out '%{http_code}\nremote_ip=%{remote_ip} remote_port=%{remote_port} local_ip=%{local_ip}\ndns=%{time_namelookup}s connect=%{time_connect}s tls=%{time_appconnect}s first_byte=%{time_starttransfer}s total=%{time_total}s\nssl_verify_result=%{ssl_verify_result} redirects=%{num_redirects} uploaded=%{size_upload}B downloaded=%{size_download}B\n' \
|
||||
"$@" > "$metrics_file" 2> "$error_file"; then
|
||||
curl_exit=0
|
||||
else
|
||||
curl_exit=$?
|
||||
fi
|
||||
node scripts/dokploy-diagnostics.mjs request "$label" "$curl_exit" \
|
||||
"$metrics_file" "$error_file" "$headers_file" "$body_file" "$auth_file" >&2
|
||||
http_code="$(head -n 1 "$metrics_file")"
|
||||
if [ "$curl_exit" -ne 0 ]; then
|
||||
echo "[Dokploy] $label failed: curl exit $curl_exit, HTTP ${http_code:-000}." >&2
|
||||
return 1
|
||||
fi
|
||||
case "$http_code" in
|
||||
2??) ;;
|
||||
*) echo "[Dokploy] $label failed: HTTP ${http_code:-000}." >&2; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Only committed files from this revision are uploaded. This excludes
|
||||
# .git metadata, local .env files, caches, and untracked workspace data.
|
||||
git archive --format=zip --output="$archive_file" HEAD
|
||||
echo "[Dokploy] Source archive size: $(wc -c < "$archive_file") bytes"
|
||||
|
||||
before_code="$(curl --silent --get \
|
||||
--header "@$auth_file" \
|
||||
dokploy_request "API preflight GET /api/deployment.all" "$deployment_file" --get \
|
||||
--data-urlencode "applicationId=$DOKPLOY_APPLICATION_ID" \
|
||||
--connect-timeout 10 --max-time 30 \
|
||||
--output "$deployment_file" --write-out '%{http_code}' \
|
||||
"$DOKPLOY_URL/api/deployment.all" 2>/dev/null || true)"
|
||||
case "$before_code" in
|
||||
2??) ;;
|
||||
*) echo "Dokploy API preflight failed (HTTP ${before_code:-000}); response withheld." >&2; exit 1 ;;
|
||||
esac
|
||||
"$DOKPLOY_URL/api/deployment.all"
|
||||
|
||||
previous_id="$(DOKPLOY_STATUS_FILE="$deployment_file" node <<'NODE'
|
||||
const fs = require("node:fs");
|
||||
const payload = JSON.parse(fs.readFileSync(process.env.DOKPLOY_STATUS_FILE, "utf8"));
|
||||
let payload;
|
||||
try { payload = JSON.parse(fs.readFileSync(process.env.DOKPLOY_STATUS_FILE, "utf8")); }
|
||||
catch { console.error("Dokploy deployment list was not valid JSON."); process.exit(2); }
|
||||
const rows = Array.isArray(payload)
|
||||
? payload
|
||||
: [payload?.data, payload?.deployments, payload?.items].find(Array.isArray);
|
||||
@@ -68,38 +104,31 @@ jobs:
|
||||
process.stdout.write(String(latest?.id ?? latest?.deploymentId ?? ""));
|
||||
NODE
|
||||
)" || {
|
||||
node scripts/dokploy-diagnostics.mjs request "API preflight response parsing" parse-error \
|
||||
"$metrics_file" "$error_file" "$headers_file" "$deployment_file" "$auth_file" >&2
|
||||
echo "Dokploy returned an unexpected deployment list; source was not uploaded." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
upload_code="$(curl --silent \
|
||||
--header "@$auth_file" \
|
||||
dokploy_request "Source upload POST /api/application.dropDeployment" "$response_file" \
|
||||
--form-string "applicationId=$DOKPLOY_APPLICATION_ID" \
|
||||
--form "zip=@$archive_file;type=application/zip" \
|
||||
--connect-timeout 15 --max-time 1800 \
|
||||
--output "$response_file" --write-out '%{http_code}' \
|
||||
"$DOKPLOY_URL/api/application.dropDeployment" 2>/dev/null || true)"
|
||||
case "$upload_code" in
|
||||
2??) echo "Dokploy accepted the source archive; waiting for the VPS build and deployment." ;;
|
||||
*) echo "Dokploy source upload failed (HTTP ${upload_code:-000}); response withheld." >&2; exit 1 ;;
|
||||
esac
|
||||
"$DOKPLOY_URL/api/application.dropDeployment"
|
||||
echo "Dokploy accepted the source archive; waiting for the VPS build and deployment."
|
||||
|
||||
attempt=0
|
||||
while [ "$attempt" -lt 360 ]; do
|
||||
status_code="$(curl --silent --get \
|
||||
--header "@$auth_file" \
|
||||
dokploy_request "Deployment status GET /api/deployment.all (attempt $((attempt + 1))/360)" "$deployment_file" --get \
|
||||
--data-urlencode "applicationId=$DOKPLOY_APPLICATION_ID" \
|
||||
--connect-timeout 10 --max-time 30 \
|
||||
--output "$deployment_file" --write-out '%{http_code}' \
|
||||
"$DOKPLOY_URL/api/deployment.all" 2>/dev/null || true)"
|
||||
case "$status_code" in
|
||||
2??) ;;
|
||||
*) echo "Dokploy deployment status check failed (HTTP ${status_code:-000})." >&2; exit 1 ;;
|
||||
esac
|
||||
"$DOKPLOY_URL/api/deployment.all"
|
||||
|
||||
status="$(DOKPLOY_STATUS_FILE="$deployment_file" DOKPLOY_PREVIOUS_DEPLOYMENT_ID="$previous_id" node <<'NODE'
|
||||
const fs = require("node:fs");
|
||||
const payload = JSON.parse(fs.readFileSync(process.env.DOKPLOY_STATUS_FILE, "utf8"));
|
||||
let payload;
|
||||
try { payload = JSON.parse(fs.readFileSync(process.env.DOKPLOY_STATUS_FILE, "utf8")); }
|
||||
catch { console.error("Dokploy deployment status was not valid JSON."); process.exit(2); }
|
||||
const rows = Array.isArray(payload)
|
||||
? payload
|
||||
: [payload?.data, payload?.deployments, payload?.items].find(Array.isArray);
|
||||
@@ -117,7 +146,9 @@ jobs:
|
||||
}
|
||||
NODE
|
||||
)" || {
|
||||
echo "Dokploy returned an unexpected deployment status; response withheld." >&2
|
||||
node scripts/dokploy-diagnostics.mjs request "Deployment status response parsing" parse-error \
|
||||
"$metrics_file" "$error_file" "$headers_file" "$deployment_file" "$auth_file" >&2
|
||||
echo "Dokploy returned an unexpected deployment status; inspect the response diagnostics above." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user