runbot/runbot_merge/localtunnel
Xavier Morel d6e1516f31 [IMP] runbot_merge: support arbitrary tunnel scripts
Rather than add individual tunnel methods to conftest, just allows
specifying a tunnel script and have that do whatever.

Protocol is uncomplicated: workers run the `$tunnel` with an arbitrary
port, script should create a tunnel to `localhost:$port`, print the
ingress of the tunnel to `STDOUT` with a terminating newline then
close `STDOUT`, and wait for `SIGINT` or `SIGTERM`, doing  whatever
cleanup they need when receiving either of those.

`ngrok` and `localtunnel` adapter scripts are provided out of the box,
though the ngrok one doesn't *really* work when using xdist without a
pre-spawned ngrok worker. Then again using xdist against github actual
is suicidal (because concurrency limits + rate limits) so likely
irrelevant.

Fixes #729
2024-12-09 16:02:28 +01:00

26 lines
585 B
Python

#!/usr/bin/env python
import re
import signal
import subprocess
import sys
import threading
port = int(sys.argv[1])
p = subprocess.Popen(['lt', '-p', str(port)], stdout=subprocess.PIPE, encoding="utf-8")
r = p.stdout.readline()
m = re.match(r'your url is: (https://.*\.localtunnel\.me)', r)
assert m, "could not get the localtunnel URL"
print(m[1], flush=True)
sys.stdout.close()
shutdown = threading.Event()
def cleanup(_sig, _frame):
p.terminate()
p.wait(30)
shutdown.set()
signal.signal(signal.SIGTERM, cleanup)
signal.signal(signal.SIGINT, cleanup)
shutdown.wait()