Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate container creation to tools #67724

Merged
merged 16 commits into from
Feb 19, 2025
6 changes: 6 additions & 0 deletions .github/actions/ssh-tunnel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ OkZFOjhCOjI3OjFDOjFBOkJEOjUxOjQ2OjE4OjBBOjhFOjVBOjI1OjQzOjQzOjZGOkRBXHJcbmE9c2V0
dXA6YWN0aXZlXHJcbiIsICJ0eXBlIjogImFuc3dlciJ9
-- Message received --
```

SSH to your local port.

```
ssh -o StrictHostKeychecking=no -o TCPKeepAlive=no -o StrictHostKeyChecking=no -vv -p 5222 runner@localhost
```
83 changes: 54 additions & 29 deletions .github/actions/ssh-tunnel/rtcforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import logging
import os
import signal
import sys
import textwrap
import time
Expand Down Expand Up @@ -77,6 +78,42 @@ def print_pastable(data, message="offer"):
sys.stdout.flush()


async def read_from_stdin():
loop = asyncio.get_event_loop()
line = await loop.run_in_executor(
None, input, "-- Please enter a message from remote party --\n"
)
data = line
while line:
try:
line = await loop.run_in_executor(None, input)
except EOFError:
break
data += line
print("-- Message received --")
return data


class Channels:
def __init__(self, channels=None):
if channels is None:
channels = []
self.channels = channels

def add(self, channel):
self.channels.append(channel)

def close(self):
for channel in self.channels:
channel.close()


class ProxyConnection:
def __init__(self, pc, channel):
self.pc = pc
self.channel = channel


class ProxyClient:

def __init__(self, args, channel):
Expand Down Expand Up @@ -219,29 +256,7 @@ def on_message(message):
log.exception("WTF")


class ProxyConnection:
def __init__(self, pc, channel):
self.pc = pc
self.channel = channel


async def read_from_stdin():
loop = asyncio.get_event_loop()
line = await loop.run_in_executor(
None, input, "-- Please enter a message from remote party --\n"
)
data = line
while line:
try:
line = await loop.run_in_executor(None, input)
except EOFError:
break
data += line
print("-- Message received --")
return data


async def run_answer(pc, args):
async def run_answer(stop, pc, args):
"""
Top level offer answer server.
"""
Expand Down Expand Up @@ -270,11 +285,11 @@ def on_datachannel(channel):
elif obj is BYE:
print("Exiting")

while True:
while not stop.is_set():
await asyncio.sleep(0.3)


async def run_offer(pc, args):
async def run_offer(stop, pc, args):
"""
Top level offer server this will estabilsh a data channel and start a tcp
server on the port provided. New connections to the server will start the
Expand Down Expand Up @@ -324,10 +339,14 @@ def on_open():
elif obj is BYE:
print("Exiting")

while True:
while not stop.is_set():
await asyncio.sleep(0.3)


async def signal_handler(stop, pc):
stop.set()


if __name__ == "__main__":
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Expand All @@ -343,16 +362,22 @@ def on_open():
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)

stop = asyncio.Event()
pc = RTCPeerConnection()
if args.role == "offer":
coro = run_offer(pc, args)
coro = run_offer(stop, pc, args)
else:
coro = run_answer(pc, args)
coro = run_answer(stop, pc, args)

# run event loop
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
for signame in ("SIGINT", "SIGTERM"):
loop.add_signal_handler(
getattr(signal, signame),
lambda: asyncio.create_task(signal_handler(stop, pc)),
)

try:
loop.run_until_complete(coro)
except KeyboardInterrupt:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ssh-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ jobs:
- name: Checkout Source Code
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Setup Python Tools Scripts
uses: ./.github/actions/setup-python-tools-scripts
with:
cache-prefix: ssh-debug

- name: Install Nox
run: |
python3 -m pip install 'nox==2022.8.7'
env:
PIP_INDEX_URL: https://pypi.org/simple

- uses: ./.github/actions/ssh-tunnel
with:
public_key: ${{ inputs.public_key }}
Expand Down
Loading
Loading