Files
SnarfCode/scripts/deploy_vaultconfigurator.py

51 lines
1.4 KiB
Python

import paramiko
COMPOSE = """version: '3.8'
services:
app:
image: vaultconfigurator:latest
ports:
- target: 8080
published: 8085
protocol: tcp
mode: ingress
volumes:
- /mnt/nfs_shares/vaultconfigurator/data:/data:ro
- /mnt/nfs_shares/vaultconfigurator/cache:/cache
- /mnt/nfs_shares/vaultconfigurator/bins:/bins
deploy:
replicas: 1
placement:
constraints:
- node.hostname == snshpd4lnxswm01
restart_policy:
condition: any
delay: 5s
max_attempts: 3
resources:
limits:
cpus: '1.0'
memory: 256M
reservations:
cpus: '0.05'
memory: 32M
"""
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("140.44.4.71", username="root", key_filename=r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet", timeout=10)
# Write compose file
cmd = f"cat << 'EOF' > /opt/vaultconfigurator/docker-compose.yml\n{COMPOSE}\nEOF"
stdin, stdout, stderr = client.exec_command(cmd)
print("Write compose:", stdout.read().decode(), stderr.read().decode())
# Deploy stack
cmd = "docker stack deploy -c /opt/vaultconfigurator/docker-compose.yml vaultconfigurator"
stdin, stdout, stderr = client.exec_command(cmd)
print("Deploy stack:", stdout.read().decode(), stderr.read().decode())
client.close()