Skip to content

Commit 9a69e7e

Browse files
ryan-williamsclaude
andcommitted
Use SCP to copy setup script instead of curl from private repo
The repo is private so raw.githubusercontent.com URLs return 404. Now we: - Read the script from the installed package via `importlib.resources` - SCP it to the instance - Then execute it via SSH Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 44ca546 commit 9a69e7e

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/lambda_gha/scripts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Scripts package - contains shell scripts for runner setup

src/lambda_gha/start.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,21 +399,42 @@ def execute_setup_via_ssh(
399399
else:
400400
raise RuntimeError(f"Failed to connect to {ip} via SSH after {max_retries} attempts")
401401

402+
# Read setup script from package (can't curl from private repo)
403+
from importlib.resources import files
404+
scripts_dir = files("lambda_gha.scripts")
405+
setup_script = (scripts_dir / "runner-setup.sh").read_text()
406+
407+
# Write script to temp file for SCP
408+
script_file = tempfile.NamedTemporaryFile(mode='w', suffix='.sh', delete=False)
409+
script_file.write(setup_script)
410+
script_file.close()
411+
os.chmod(script_file.name, stat.S_IRUSR | stat.S_IXUSR) # 0500
412+
413+
# SCP the script to the instance
414+
scp_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"]
415+
if key_file:
416+
scp_opts.extend(["-i", key_file.name])
417+
418+
print(f"Copying setup script to instance...")
419+
scp_result = subprocess.run(
420+
["scp"] + scp_opts + [script_file.name, f"{ssh_user}@{ip}:/tmp/runner-setup.sh"],
421+
capture_output=True,
422+
text=True,
423+
)
424+
if scp_result.returncode != 0:
425+
raise RuntimeError(f"Failed to SCP script: {scp_result.stderr}")
426+
402427
# Build env export commands
403428
env_exports = "\n".join(f'export {k}="{v}"' for k, v in env_vars.items())
404429

405-
# Script URL from GitHub
406-
script_url = f"https://raw.githubusercontent.com/Open-Athena/lambda-gha/{action_sha}/src/lambda_gha/scripts/runner-setup.sh"
407-
408-
# Build the setup command: export vars, fetch script, run it
430+
# Build the setup command: export vars, run script
409431
setup_cmd = f'''
410432
{env_exports}
411-
curl -sSL "{script_url}" -o /tmp/runner-setup.sh
412433
chmod +x /tmp/runner-setup.sh
413434
sudo -E nohup /tmp/runner-setup.sh > /var/log/runner-setup.log 2>&1 &
414435
'''
415436

416-
print(f"Executing setup script from {script_url}...")
437+
print(f"Executing setup script...")
417438
exec_result = subprocess.run(
418439
["ssh"] + ssh_opts + [f"{ssh_user}@{ip}", setup_cmd],
419440
capture_output=True,

0 commit comments

Comments
 (0)