Update caddy gateway example
This commit is contained in:
@@ -6,10 +6,8 @@ import freeflowuniverse.herolib.installers.threefold.griddriver
|
||||
import os
|
||||
import time
|
||||
|
||||
griddriver.install()!
|
||||
|
||||
v := tfgrid3deployer.get()!
|
||||
v := deployer.get()!
|
||||
println('cred: ${v}')
|
||||
|
||||
deployment_name := 'vm_caddy1'
|
||||
tfgrid3deployer.delete_deployment(deployment_name)!
|
||||
deployer.delete_deployment(deployment_name)!
|
||||
|
||||
@@ -7,14 +7,17 @@ import freeflowuniverse.herolib.installers.threefold.griddriver
|
||||
import os
|
||||
import time
|
||||
|
||||
res2 := tfgrid3deployer.filter_nodes()!
|
||||
println(res2)
|
||||
exit(0)
|
||||
// res2 := deployer.filter_nodes()!
|
||||
// println(res2)
|
||||
// exit(0)
|
||||
|
||||
v := tfgrid3deployer.get()!
|
||||
const vm_node = u32(2009)
|
||||
const gw_node = u32(1)
|
||||
|
||||
v := deployer.get()!
|
||||
println('cred: ${v}')
|
||||
deployment_name := 'vm_caddy1'
|
||||
mut deployment := tfgrid3deployer.new_deployment(deployment_name)!
|
||||
mut deployment := deployer.new_deployment(deployment_name)!
|
||||
deployment.add_machine(
|
||||
name: 'vm_caddy1'
|
||||
cpu: 1
|
||||
@@ -22,16 +25,17 @@ deployment.add_machine(
|
||||
planetary: false
|
||||
public_ip4: false
|
||||
size: 10 // 10 gig
|
||||
mycelium: tfgrid3deployer.Mycelium{}
|
||||
mycelium: deployer.Mycelium{}
|
||||
nodes: [vm_node]
|
||||
)
|
||||
deployment.deploy()!
|
||||
|
||||
vm1 := deployment.vm_get('vm_caddy1')!
|
||||
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()!
|
||||
gw1 := deployment.webname_get('gwnamecaddy')!
|
||||
println('gw info: ${gw1}')
|
||||
@@ -44,7 +48,7 @@ mut is_ssh_up := false
|
||||
for {
|
||||
if retries < max_retries {
|
||||
// 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)
|
||||
|
||||
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.')
|
||||
}
|
||||
|
||||
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)
|
||||
if res1.exit_code != 0 {
|
||||
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)
|
||||
if res.exit_code != 0 {
|
||||
panic('failed to install and run caddy: ${res.output}')
|
||||
}
|
||||
|
||||
println('To access the machine, run the following command:')
|
||||
println('ssh root@${vm1_public_ip4}')
|
||||
println('ssh root@${vm1_ip}')
|
||||
|
||||
Reference in New Issue
Block a user