Files
herolib/examples/threefold/tfgrid3deployer/vm_gw_caddy/vm_gw_caddy.vsh
Mahmoud Emad 2e14b7b7af fix: improve git url parsing and deployment
- Improve the parsing of Git URLs to correctly handle paths and branches.
- Fix an issue where the `griddriver` installer was not correctly
- installed.
- Fix a bug in the `IPAddress` `ping` function.
- Update the `GitLocation` struct to correctly handle branches and
- tags.
- Fix a bug in the `GitRepo` `checkout` function.
- Improve the `gitlocation_from_url` function to handle various Git
- URL formats.
- Update the `livekit` installer to use the correct source command.
- Update the `golang` installer to use the correct `go version`
- command.
- Update the `griddriver` installer to use the correct version
- command.

Co-authored-by: supermario <mariobassem12@gmail.com>
2025-01-02 13:35:36 +02:00

79 lines
2.3 KiB
GLSL
Executable File

#!/usr/bin/env -S v -gc none -no-retry-compilation -d use_openssl -enable-globals -cg run
//#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals -cg run
import freeflowuniverse.herolib.threefold.gridproxy
import freeflowuniverse.herolib.threefold.tfgrid3deployer
import freeflowuniverse.herolib.installers.threefold.griddriver
import os
import time
griddriver.install()!
v := tfgrid3deployer.get()!
println('cred: ${v}')
deployment_name := 'vm_caddy1'
mut deployment := tfgrid3deployer.new_deployment(deployment_name)!
deployment.add_machine(
name: 'vm_caddy1'
cpu: 1
memory: 2
planetary: false
public_ip4: true
size: 10 // 10 gig
mycelium: tfgrid3deployer.Mycelium{}
)
deployment.deploy()!
vm1 := deployment.vm_get('vm_caddy1')!
println('vm1 info: ${vm1}')
vm1_public_ip4 := vm1.public_ip4.all_before('/')
deployment_name2 := 'vm_caddy_gw'
mut deployment2 := tfgrid3deployer.new_deployment(deployment_name2)!
deployment2.add_webname(name: 'gwnamecaddy', backend: 'http://${vm1_public_ip4}:80')
deployment2.deploy()!
gw1 := deployment2.webname_get('gwnamecaddy')!
println('gw info: ${gw1}')
// Retry logic to wait for the SSH server to be up
max_retries := 10
mut retries := 0
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_res := os.execute(ssh_check_cmd)
if ssh_check_res.exit_code == 0 {
is_ssh_up = true
break
}
retries++
println('SSH server not up, retrying in 5 seconds... (Attempt ${retries}/${max_retries})')
time.sleep(time.second * 5)
}
}
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}:~'
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"'
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}')