Files
SnarfCode/scripts/deploy_heimdall_fixed.py

67 lines
1.5 KiB
Python

import paramiko
import sys
import time
sys.stdout.reconfigure(encoding='utf-8')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('140.44.4.71', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
def run(cmd):
print(f"\n>>> {cmd}")
_, o, e = c.exec_command(cmd)
res = o.read().decode().strip()
err = e.read().decode().strip()
if res:
print(res)
if err:
print("[stderr]", err)
return res
new_compose = '''version: "3.8"
services:
heimdall:
image: lscr.io/linuxserver/heimdall:latest
ports:
- target: 80
published: 85
mode: ingress
- target: 443
published: 403
mode: ingress
environment:
- PUID=1000
- PGID=1000
- TZ=America/New_York
volumes:
- type: bind
source: /var/lib/docker-data/heimdall/config
target: /config
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.hostname == snshpd4lnxswm01
restart_policy:
condition: on-failure
'''
sftp = c.open_sftp()
with sftp.file('/tmp/heimdall_compose.yml', 'w') as f:
f.write(new_compose)
sftp.close()
# Also save into /var/lib/docker-data/heimdall/compose.yml for persistence
run("cp /tmp/heimdall_compose.yml /var/lib/docker-data/heimdall/compose.yml")
# Redeploy
run("docker stack deploy -c /tmp/heimdall_compose.yml heimdall")
time.sleep(6)
run("docker stack ps heimdall")
run("curl -s -I http://127.0.0.1:85 | head -n 5")
c.close()