Skip to content

Commit 8941ed6

Browse files
committed
fix: simplify runtime output emission
1 parent 25fffd7 commit 8941ed6

4 files changed

Lines changed: 29 additions & 27 deletions

File tree

docs/config.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ docker run --rm \
8181

8282
## Runtime Output
8383

84-
By default the worker does not print runtime config details or write output files. The entrypoint logs a short hint that output can be enabled.
85-
86-
Set `WORKER_OUTPUT_FILE` when a deployment or workflow needs redacted runtime config evidence. The worker writes JSON runtime metadata to that path after `worker.yaml`, deployment environment overrides, and secret references have been applied.
87-
88-
Set `WORKER_OUTPUT_LOG=true` to also emit the same JSON to container logs as a single minified line prefixed with `WORKER_RUNTIME_OUTPUT_JSON=`. This is useful for Kubernetes or workflow systems where the next step reads container logs instead of a mounted file.
84+
By default the worker does not print runtime config details. The entrypoint logs a short hint that output can be enabled.
8985

9086
Set `WORKER_OUTPUT_STDOUT=true` when a workflow should capture only the runtime JSON from stdout. In this mode the entrypoint sends setup logs to stderr, writes the redacted runtime JSON to stdout, and exits before starting the process manager:
9187

@@ -95,6 +91,8 @@ docker run --rm \
9591
usabilitydynamics/udx-worker:latest > runtime-output/runtime.json
9692
```
9793

94+
Set `WORKER_OUTPUT_LOG=true` to also emit the same JSON to container logs as a single minified line prefixed with `WORKER_RUNTIME_OUTPUT_JSON=`. This is useful for Kubernetes or workflow systems where the next step reads container logs from a normal-running container.
95+
9896
The output contains:
9997

10098
- `env`: resolved non-secret environment variables.

lib/runtime_output.sh

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,29 @@ build_runtime_redacted_json() {
8181
local config_json="$1"
8282
local names name json
8383

84-
if [[ ! -f "$WORKER_ENV_FILE" ]]; then
85-
log_error "Runtime output" "Environment file not found: $WORKER_ENV_FILE"
86-
return 1
84+
json=$(echo "$config_json" | jq -c --arg pattern "^(${SUPPORTED_SECRET_PROVIDERS})/.+/.+" '
85+
[
86+
(.config.secrets // {} | keys[]?),
87+
(.config.env // {} | to_entries[]? | select(((.value // "") | tostring) | test($pattern)) | .key)
88+
]
89+
') || return 1
90+
91+
if [[ -f "$WORKER_ENV_FILE" ]]; then
92+
names=$(grep "^export " "$WORKER_ENV_FILE" | cut -d'=' -f1 | cut -d' ' -f2)
93+
while IFS= read -r name; do
94+
if [[ -n "$name" ]] && is_runtime_output_redacted_name "$config_json" "$name"; then
95+
json=$(echo "$json" | jq --arg name "$name" '. + [$name]') || return 1
96+
fi
97+
done <<< "$names"
8798
fi
8899

89-
names=$(grep "^export " "$WORKER_ENV_FILE" | cut -d'=' -f1 | cut -d' ' -f2)
90-
json="[]"
91-
while IFS= read -r name; do
92-
if [[ -n "$name" ]] && is_runtime_output_redacted_name "$config_json" "$name"; then
93-
json=$(echo "$json" | jq --arg name "$name" '. + [$name]') || return 1
94-
fi
95-
done <<< "$names"
100+
if [[ -f "$WORKER_ENV_REDACTION_FILE" ]]; then
101+
while IFS= read -r name; do
102+
if [[ -n "$name" ]]; then
103+
json=$(echo "$json" | jq --arg name "$name" '. + [$name]') || return 1
104+
fi
105+
done < "$WORKER_ENV_REDACTION_FILE"
106+
fi
96107

97108
echo "$json" | jq -S 'unique'
98109
}
@@ -140,8 +151,8 @@ emit_runtime_output_stdout() {
140151
emit_runtime_output() {
141152
local config_json runtime_json
142153

143-
if [[ -z "${WORKER_OUTPUT_FILE:-}" ]] && ! runtime_output_log_enabled && ! runtime_output_stdout_enabled; then
144-
log_info "Runtime output disabled. Set WORKER_OUTPUT_FILE, WORKER_OUTPUT_LOG=true, or WORKER_OUTPUT_STDOUT=true to emit redacted JSON runtime config for workflow/deployment integrations."
154+
if ! runtime_output_log_enabled && ! runtime_output_stdout_enabled; then
155+
log_info "Runtime output disabled. Set WORKER_OUTPUT_STDOUT=true or WORKER_OUTPUT_LOG=true to emit redacted JSON runtime config for workflow/deployment integrations."
145156
return 0
146157
fi
147158

@@ -151,13 +162,6 @@ emit_runtime_output() {
151162
return 1
152163
fi
153164

154-
if [[ -n "${WORKER_OUTPUT_FILE:-}" ]]; then
155-
mkdir -p "$(dirname "$WORKER_OUTPUT_FILE")" || return 1
156-
install -m 600 /dev/null "$WORKER_OUTPUT_FILE" || return 1
157-
printf '%s\n' "$runtime_json" > "$WORKER_OUTPUT_FILE"
158-
log_info "Runtime output written to $WORKER_OUTPUT_FILE"
159-
fi
160-
161165
if runtime_output_log_enabled; then
162166
emit_runtime_output_log "$runtime_json" || return 1
163167
fi

src/configs/worker.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ kind: workerConfig
33
version: udx.io/worker-v1/config
44
config:
55
env:
6-
WORKER_OUTPUT_FILE: ""
76
WORKER_OUTPUT_LOG: "false"
87
WORKER_OUTPUT_STDOUT: "false"
98
secrets: {}

test/modules/25_runtime_output.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ CONFIG_JSON='{
3434
"CONFIG_REF": "gcp/project-id/secret-name"
3535
},
3636
"secrets": {
37-
"CONFIG_SECRET": "aws/secret-name/us-west-2"
37+
"CONFIG_SECRET": "aws/secret-name/us-west-2",
38+
"CONFIG_ONLY_SECRET": "aws/config-only/us-west-2"
3839
}
3940
}
4041
}'
@@ -58,7 +59,7 @@ if echo "$RUNTIME_OUTPUT" | jq -e '.env.CONFIG_SECRET or .env.CONFIG_REF or .env
5859
exit 1
5960
fi
6061

61-
if ! echo "$RUNTIME_OUTPUT" | jq -e '.redacted == ["CONFIG_REF", "CONFIG_SECRET", "DEPLOYMENT_SECRET", "DEPLOYMENT_SECRET_TWO"]' >/dev/null; then
62+
if ! echo "$RUNTIME_OUTPUT" | jq -e '.redacted == ["CONFIG_ONLY_SECRET", "CONFIG_REF", "CONFIG_SECRET", "DEPLOYMENT_SECRET", "DEPLOYMENT_SECRET_TWO"]' >/dev/null; then
6263
print_error "runtime output redacted list is incorrect"
6364
exit 1
6465
fi

0 commit comments

Comments
 (0)