Update caddy gateway example

This commit is contained in:
Scott Yeager
2025-03-12 17:08:24 -07:00
parent 46069ba924
commit 413b805823
2 changed files with 18 additions and 16 deletions

View File

@@ -6,10 +6,8 @@ import freeflowuniverse.herolib.installers.threefold.griddriver
import os import os
import time import time
griddriver.install()! v := deployer.get()!
v := tfgrid3deployer.get()!
println('cred: ${v}') println('cred: ${v}')
deployment_name := 'vm_caddy1' deployment_name := 'vm_caddy1'
tfgrid3deployer.delete_deployment(deployment_name)! deployer.delete_deployment(deployment_name)!

View File

@@ -7,14 +7,17 @@ import freeflowuniverse.herolib.installers.threefold.griddriver
import os import os
import time import time
res2 := tfgrid3deployer.filter_nodes()! // res2 := deployer.filter_nodes()!
println(res2) // println(res2)
exit(0) // exit(0)
v := tfgrid3deployer.get()! const vm_node = u32(2009)
const gw_node = u32(1)
v := deployer.get()!
println('cred: ${v}') println('cred: ${v}')
deployment_name := 'vm_caddy1' deployment_name := 'vm_caddy1'
mut deployment := tfgrid3deployer.new_deployment(deployment_name)! mut deployment := deployer.new_deployment(deployment_name)!
deployment.add_machine( deployment.add_machine(
name: 'vm_caddy1' name: 'vm_caddy1'
cpu: 1 cpu: 1
@@ -22,16 +25,17 @@ deployment.add_machine(
planetary: false planetary: false
public_ip4: false public_ip4: false
size: 10 // 10 gig size: 10 // 10 gig
mycelium: tfgrid3deployer.Mycelium{} mycelium: deployer.Mycelium{}
nodes: [vm_node]
) )
deployment.deploy()! deployment.deploy()!
vm1 := deployment.vm_get('vm_caddy1')! vm1 := deployment.vm_get('vm_caddy1')!
println('vm1 info: ${vm1}') println('vm1 info: ${vm1}')
vm1_public_ip4 := vm1.public_ip4.all_before('/') vm1_ip := vm1.mycelium_ip
deployment.add_webname(name: 'gwnamecaddy', backend: 'http://${vm1_public_ip4}:80') deployment.add_webname(node_id: gw_node, name: 'gwnamecaddy', backend: 'http://[${vm1_ip}]:80')
deployment.deploy()! deployment.deploy()!
gw1 := deployment.webname_get('gwnamecaddy')! gw1 := deployment.webname_get('gwnamecaddy')!
println('gw info: ${gw1}') println('gw info: ${gw1}')
@@ -44,7 +48,7 @@ mut is_ssh_up := false
for { for {
if retries < max_retries { if retries < max_retries {
// Try to SSH into the machine // Try to SSH into the machine
ssh_check_cmd := 'ssh -o "StrictHostKeyChecking no" root@${vm1_public_ip4} -o ConnectTimeout=10 echo "SSH server is up"' ssh_check_cmd := 'ssh -o "StrictHostKeyChecking no" root@${vm1_ip} -o ConnectTimeout=10 echo "SSH server is up"'
ssh_check_res := os.execute(ssh_check_cmd) ssh_check_res := os.execute(ssh_check_cmd)
if ssh_check_res.exit_code == 0 { if ssh_check_res.exit_code == 0 {
@@ -61,17 +65,17 @@ if !is_ssh_up {
panic('Failed to connect to the SSH server after ${max_retries} attempts.') panic('Failed to connect to the SSH server after ${max_retries} attempts.')
} }
cp_cmd := 'scp -o "StrictHostKeyChecking no" ${os.dir(@FILE)}/install_caddy.sh ${os.dir(@FILE)}/Caddyfile root@${vm1_public_ip4}:~' cp_cmd := 'scp -o "StrictHostKeyChecking no" ${os.dir(@FILE)}/install_caddy.sh ${os.dir(@FILE)}/Caddyfile root@[${vm1_ip}]:~'
res1 := os.execute(cp_cmd) res1 := os.execute(cp_cmd)
if res1.exit_code != 0 { if res1.exit_code != 0 {
panic('failed to copy files: ${res1.output}') panic('failed to copy files: ${res1.output}')
} }
cmd := 'ssh root@${vm1_public_ip4} -o "StrictHostKeyChecking no" -t "chmod +x ~/install_caddy.sh && ~/install_caddy.sh"' cmd := 'ssh root@${vm1_ip} -o "StrictHostKeyChecking no" -t "chmod +x ~/install_caddy.sh && ~/install_caddy.sh"'
res := os.execute(cmd) res := os.execute(cmd)
if res.exit_code != 0 { if res.exit_code != 0 {
panic('failed to install and run caddy: ${res.output}') panic('failed to install and run caddy: ${res.output}')
} }
println('To access the machine, run the following command:') println('To access the machine, run the following command:')
println('ssh root@${vm1_public_ip4}') println('ssh root@${vm1_ip}')