#!/bin/sh # Lets QM's core reach the agent computers it starts as Docker containers. # # QM 0.1.x reads QM_CORE_CONTAINER only into its AWS sandbox settings, so a # core that itself runs in a container never joins its sandboxes' networks # and every command fails with "exec daemon never became reachable" # (https://github.com/yc-software/qm/issues/2064, fixed by # https://github.com/yc-software/qm/pull/2712). This copies that one-line # fix into the running core container and restarts it. Run it after every # `qm up`; once a QM release has the fix, it says so and changes nothing. set -eu core="${1:-qm-team-core}" tmp="$(mktemp)" trap 'rm -f "$tmp"' EXIT has_fix() { awk '/^function localSandboxEnv/,/^}/' "$1" | grep -q QM_CORE_CONTAINER; } docker cp "$core:/app/src/config.ts" "$tmp" if has_fix "$tmp"; then echo "$core already passes its container name to local sandboxes" exit 0 fi sed -i 's|^\( *\)\(\.\.\.(env\.LOCAL_SANDBOX_DOCKER_BIN ? { dockerBin: env\.LOCAL_SANDBOX_DOCKER_BIN } : {}),\)$|\1\2\n\1...(env.QM_CORE_CONTAINER ? { coreContainer: env.QM_CORE_CONTAINER } : {}),|' "$tmp" has_fix "$tmp" || { echo "this QM release looks different; not patched" >&2; exit 1; } chmod 644 "$tmp" docker cp "$tmp" "$core:/app/src/config.ts" since="$(date -u +%Y-%m-%dT%H:%M:%SZ)" docker restart "$core" >/dev/null for _ in $(seq 60); do docker logs --since "$since" "$core" 2>&1 | grep -q '\[qm\] listening' && { echo "$core patched and restarted"; exit 0; } sleep 2 done echo "$core did not come back; see: docker logs $core" >&2 exit 1