@ranger1/dx 0.1.108 → 0.1.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,36 @@ function requirePositiveInteger(value, fieldPath) {
16
16
  return parsed
17
17
  }
18
18
 
19
+ function requireEnvName(value, fieldPath) {
20
+ const name = requireString(value, fieldPath)
21
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
22
+ throw new Error(`缺少必填配置: ${fieldPath}`)
23
+ }
24
+ return name
25
+ }
26
+
27
+ function resolveHealthCheckEndpoint(healthCheckConfig) {
28
+ if (healthCheckConfig.url != null) {
29
+ const url = requireString(healthCheckConfig.url, 'verify.healthCheck.url')
30
+ try {
31
+ new URL(url)
32
+ } catch {
33
+ throw new Error(`缺少必填配置: verify.healthCheck.url`)
34
+ }
35
+ return { url }
36
+ }
37
+
38
+ if (healthCheckConfig.envPort != null) {
39
+ const rawPath = healthCheckConfig.path == null ? '/health' : requireString(healthCheckConfig.path, 'verify.healthCheck.path')
40
+ return {
41
+ envPort: requireEnvName(healthCheckConfig.envPort, 'verify.healthCheck.envPort'),
42
+ path: rawPath.startsWith('/') ? rawPath : `/${rawPath}`,
43
+ }
44
+ }
45
+
46
+ throw new Error(`缺少必填配置: verify.healthCheck.url`)
47
+ }
48
+
19
49
  function resolveVerifyConfig(verifyConfig = {}) {
20
50
  const healthCheckConfig = verifyConfig?.healthCheck
21
51
  if (healthCheckConfig == null) {
@@ -24,16 +54,9 @@ function resolveVerifyConfig(verifyConfig = {}) {
24
54
  }
25
55
  }
26
56
 
27
- const url = requireString(healthCheckConfig.url, 'verify.healthCheck.url')
28
- try {
29
- new URL(url)
30
- } catch {
31
- throw new Error(`缺少必填配置: verify.healthCheck.url`)
32
- }
33
-
34
57
  return {
35
58
  healthCheck: {
36
- url,
59
+ ...resolveHealthCheckEndpoint(healthCheckConfig),
37
60
  timeoutSeconds:
38
61
  healthCheckConfig.timeoutSeconds == null
39
62
  ? 10
@@ -32,6 +32,8 @@ export function buildRemoteDeployScript(phaseModel = []) {
32
32
  const shouldMigrate = deploy.prismaMigrateDeploy !== false && deploy.skipMigration !== true
33
33
  const shouldSeed = deploy.prismaSeed === true
34
34
  const healthCheckUrl = healthCheck?.url ? String(healthCheck.url) : ''
35
+ const healthCheckEnvPort = healthCheck?.envPort ? String(healthCheck.envPort) : ''
36
+ const healthCheckPath = healthCheck?.path ? String(healthCheck.path) : ''
35
37
  const healthCheckTimeoutSeconds = Number(healthCheck?.timeoutSeconds || 10)
36
38
  const healthCheckMaxWaitSeconds = Number(healthCheck?.maxWaitSeconds || 24)
37
39
  const healthCheckRetryIntervalSeconds = Number(healthCheck?.retryIntervalSeconds || 2)
@@ -57,6 +59,8 @@ START_MODE=${escapeShell(startupMode)}
57
59
  SERVICE_NAME=${escapeShell(serviceName)}
58
60
  START_ENTRY=${escapeShell(startupEntry)}
59
61
  HEALTHCHECK_URL=${escapeShell(healthCheckUrl)}
62
+ HEALTHCHECK_ENV_PORT=${escapeShell(healthCheckEnvPort)}
63
+ HEALTHCHECK_PATH=${escapeShell(healthCheckPath)}
60
64
  HEALTHCHECK_TIMEOUT_SECONDS=${healthCheckTimeoutSeconds}
61
65
  HEALTHCHECK_MAX_WAIT_SECONDS=${healthCheckMaxWaitSeconds}
62
66
  HEALTHCHECK_RETRY_DELAY_SECONDS=${healthCheckRetryIntervalSeconds}
@@ -226,6 +230,34 @@ read_pm2_status() {
226
230
  ' "$SERVICE_NAME"
227
231
  }
228
232
 
233
+ resolve_healthcheck_url() {
234
+ if [[ -n "$HEALTHCHECK_URL" ]]; then
235
+ printf '%s\n' "$HEALTHCHECK_URL"
236
+ return
237
+ fi
238
+
239
+ if [[ -z "$HEALTHCHECK_ENV_PORT" ]]; then
240
+ return
241
+ fi
242
+
243
+ local healthcheck_port
244
+ healthcheck_port="$(run_with_env "$CURRENT_LINK" env | awk -F= -v key="$HEALTHCHECK_ENV_PORT" '$1 == key { print substr($0, index($0, "=") + 1); exit }')"
245
+ if ! [[ "$healthcheck_port" =~ ^[0-9]+$ ]]; then
246
+ echo "health check port env $HEALTHCHECK_ENV_PORT is missing or invalid" >&2
247
+ exit 1
248
+ fi
249
+
250
+ if [[ -z "$HEALTHCHECK_PATH" ]]; then
251
+ HEALTHCHECK_PATH="/health"
252
+ fi
253
+ if [[ "$HEALTHCHECK_PATH" != /* ]]; then
254
+ HEALTHCHECK_PATH="/$HEALTHCHECK_PATH"
255
+ fi
256
+
257
+ HEALTHCHECK_URL="http://127.0.0.1:\${healthcheck_port}\${HEALTHCHECK_PATH}"
258
+ printf '%s\n' "$HEALTHCHECK_URL"
259
+ }
260
+
229
261
  build_summary_json() {
230
262
  local release_name="$1"
231
263
  local current_release_path="$2"
@@ -436,6 +468,8 @@ if [[ "$START_MODE" == "pm2" ]]; then
436
468
  fi
437
469
  fi
438
470
 
471
+ HEALTHCHECK_URL="$(resolve_healthcheck_url)"
472
+
439
473
  if [[ -n "$HEALTHCHECK_URL" ]]; then
440
474
  healthcheck_started_at="$(date +%s)"
441
475
  until curl -fsS --max-time "$HEALTHCHECK_TIMEOUT_SECONDS" "$HEALTHCHECK_URL" >/dev/null; do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.108",
3
+ "version": "0.1.109",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {