fixes in vm_caddy example
This commit is contained in:
@@ -69,7 +69,7 @@ fn do() ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.install()!
|
base.redis_install()!
|
||||||
|
|
||||||
// herocmds.cmd_bootstrap(mut cmd)
|
// herocmds.cmd_bootstrap(mut cmd)
|
||||||
// herocmds.cmd_run(mut cmd)
|
// herocmds.cmd_run(mut cmd)
|
||||||
|
|||||||
@@ -5,26 +5,39 @@ set -e
|
|||||||
|
|
||||||
# Check if the script is run as root
|
# Check if the script is run as root
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Please run this script as root or using sudo."
|
echo "This script must be run as root. Use sudo."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Update package lists and install prerequisites
|
||||||
|
echo "Installing prerequisites..."
|
||||||
|
apt update -y
|
||||||
|
apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
|
||||||
|
|
||||||
|
# Add Caddy's GPG key
|
||||||
|
echo "Adding Caddy's GPG key..."
|
||||||
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||||
|
|
||||||
|
# Add Caddy's APT repository
|
||||||
|
echo "Adding Caddy's APT repository..."
|
||||||
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
|
||||||
|
|
||||||
|
# Update package lists to include Caddy's repository
|
||||||
echo "Updating package lists..."
|
echo "Updating package lists..."
|
||||||
apt update -y
|
apt update -y
|
||||||
|
|
||||||
echo "Installing prerequisites..."
|
# Install Caddy
|
||||||
apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
|
|
||||||
|
|
||||||
echo "Adding Caddy repository..."
|
|
||||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | apt-key add -
|
|
||||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
|
|
||||||
|
|
||||||
echo "Updating package lists for Caddy..."
|
|
||||||
apt update -y
|
|
||||||
|
|
||||||
echo "Installing Caddy..."
|
echo "Installing Caddy..."
|
||||||
apt install -y caddy
|
apt install -y caddy
|
||||||
|
|
||||||
|
# Confirm installation
|
||||||
|
echo "Caddy installation completed successfully!"
|
||||||
|
echo "You can check the Caddy version with: caddy version"
|
||||||
|
|
||||||
|
# Use user's Caddyfile
|
||||||
|
mv ~/Caddyfile /etc/caddy/Caddyfile
|
||||||
|
|
||||||
|
# Monitor Caddy service with Zinit
|
||||||
echo "exec: caddy run --config /etc/caddy/Caddyfile" > /etc/zinit/caddy.yaml
|
echo "exec: caddy run --config /etc/caddy/Caddyfile" > /etc/zinit/caddy.yaml
|
||||||
zinit monitor caddy
|
zinit monitor caddy
|
||||||
|
echo "Caddy service monitored"
|
||||||
@@ -11,11 +11,10 @@ installer.install()!
|
|||||||
|
|
||||||
v := tfgrid3deployer.get()!
|
v := tfgrid3deployer.get()!
|
||||||
println('cred: ${v}')
|
println('cred: ${v}')
|
||||||
deployment_name := 'vm_gw_caddy'
|
deployment_name := 'vm_caddy1'
|
||||||
|
|
||||||
mut deployment := tfgrid3deployer.new_deployment(deployment_name)!
|
mut deployment := tfgrid3deployer.new_deployment(deployment_name)!
|
||||||
deployment.add_machine(
|
deployment.add_machine(
|
||||||
name: 'vm_caddy'
|
name: 'vm_caddy1'
|
||||||
cpu: 1
|
cpu: 1
|
||||||
memory: 2
|
memory: 2
|
||||||
planetary: true
|
planetary: true
|
||||||
@@ -25,12 +24,15 @@ deployment.add_machine(
|
|||||||
)
|
)
|
||||||
deployment.deploy()!
|
deployment.deploy()!
|
||||||
|
|
||||||
vm1 := deployment.vm_get('vm_caddy')!
|
vm1 := deployment.vm_get('vm_caddy1')!
|
||||||
println('vm1 info: ${vm1}')
|
println('vm1 info: ${vm1}')
|
||||||
|
|
||||||
vm1_public_ip4 := vm1.public_ip4.all_before('/')
|
vm1_public_ip4 := vm1.public_ip4.all_before('/')
|
||||||
deployment.add_webname(name: 'mywebname', backend: 'http://${vm1_public_ip4}:80')
|
|
||||||
deployment.deploy()!
|
deployment_name2 := 'vm_caddy_gw'
|
||||||
|
mut deployment2 := tfgrid3deployer.new_deployment(deployment_name2)!
|
||||||
|
deployment2.add_webname(name: 'mywebname', backend: 'http://${vm1_public_ip4}:80')
|
||||||
|
deployment2.deploy()!
|
||||||
|
|
||||||
// Retry logic to wait for the SSH server to be up
|
// Retry logic to wait for the SSH server to be up
|
||||||
max_retries := 10
|
max_retries := 10
|
||||||
@@ -57,13 +59,13 @@ 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 "UserKnownHostsFile=/dev/null" ${os.dir(@FILE)}/install_caddy.sh root@${vm1_public_ip4}:~ && mkdir -p /etc/caddy && scp -o "UserKnownHostsFile=/dev/null" ${os.dir(@FILE)}/Caddyfile root@${vm1_public_ip4}:/etc/caddy/'
|
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)
|
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} -t "chmod +x ~/install_caddy.sh && ~/setup.sh" -o "UserKnownHostsFile=/dev/null"'
|
cmd := 'ssh root@${vm1_public_ip4} -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}')
|
||||||
|
|||||||
@@ -138,8 +138,8 @@ pub fn (mut self Context) hero_config_set(cat string, name string, content_ stri
|
|||||||
config_file.write(content)!
|
config_file.write(content)!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Context) hero_config_exists(cat string, name string) !bool {
|
pub fn (mut self Context) hero_config_exists(cat string, name string) bool {
|
||||||
path := '${self.path()!.path}/${cat}__${name}.yaml'
|
path := '${os.home_dir()}/hero/context/${self.config.name}/${cat}__${name}.yaml'
|
||||||
return os.exists(path)
|
return os.exists(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,65 +5,65 @@ import freeflowuniverse.herolib.core.playbook
|
|||||||
import freeflowuniverse.herolib.ui
|
import freeflowuniverse.herolib.ui
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
pub struct TFGridClient[T] {
|
// pub struct TFGridClient[T] {
|
||||||
base.BaseConfig[T]
|
// base.BaseConfig[T]
|
||||||
}
|
// }
|
||||||
|
|
||||||
@[params]
|
// @[params]
|
||||||
pub struct Config {
|
// pub struct Config {
|
||||||
pub mut:
|
// pub mut:
|
||||||
mnemonics string @[secret]
|
// mnemonics string @[secret]
|
||||||
network string
|
// network string
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn get(instance string, cfg Config) !TFGridClient[Config] {
|
// pub fn get(instance string, cfg Config) !TFGridClient[Config] {
|
||||||
mut self := TFGridClient[Config]{}
|
// mut self := TFGridClient[Config]{}
|
||||||
if cfg.mnemonics.len > 0 {
|
// if cfg.mnemonics.len > 0 {
|
||||||
// first the type of the instance, then name of instance, then action
|
// // first the type of the instance, then name of instance, then action
|
||||||
self.init('tfgridclient', instance, .set, cfg)!
|
// self.init('tfgridclient', instance, .set, cfg)!
|
||||||
} else {
|
// } else {
|
||||||
self.init('tfgridclient', instance, .get)!
|
// self.init('tfgridclient', instance, .get)!
|
||||||
}
|
// }
|
||||||
return self
|
// return self
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn heroplay(mut plbook playbook.PlayBook) ! {
|
// pub fn heroplay(mut plbook playbook.PlayBook) ! {
|
||||||
for mut action in plbook.find(filter: 'tfgridclient.define')! {
|
// for mut action in plbook.find(filter: 'tfgridclient.define')! {
|
||||||
mut p := action.params
|
// mut p := action.params
|
||||||
instance := p.get_default('instance', 'default')!
|
// instance := p.get_default('instance', 'default')!
|
||||||
mut cl := get(instance)!
|
// mut cl := get(instance)!
|
||||||
mut cfg := cl.config_get()!
|
// mut cfg := cl.config_get()!
|
||||||
cfg.mnemonics = p.get('mnemonics')!
|
// cfg.mnemonics = p.get('mnemonics')!
|
||||||
cfg.network = p.get('network')!
|
// cfg.network = p.get('network')!
|
||||||
cl.config_save()!
|
// cl.config_save()!
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn (mut self TFGridClient[Config]) config_interactive() ! {
|
// pub fn (mut self TFGridClient[Config]) config_interactive() ! {
|
||||||
mut myui := ui.new()!
|
// mut myui := ui.new()!
|
||||||
// console.clear()
|
// // console.clear()
|
||||||
console.print_debug('\n## Configure TFGrid client')
|
// console.print_debug('\n## Configure TFGrid client')
|
||||||
console.print_debug('==========================')
|
// console.print_debug('==========================')
|
||||||
console.print_debug('## Instance: ${self.instance}')
|
// console.print_debug('## Instance: ${self.instance}')
|
||||||
console.print_debug('==========================\n\n')
|
// console.print_debug('==========================\n\n')
|
||||||
|
|
||||||
mut cfg := self.config()!
|
// mut cfg := self.config()!
|
||||||
|
|
||||||
// self.instance = myui.ask_question(
|
// // self.instance = myui.ask_question(
|
||||||
// question: 'name for configuration instance'
|
// // question: 'name for configuration instance'
|
||||||
// default: self.instance
|
// // default: self.instance
|
||||||
// )!
|
// // )!
|
||||||
|
|
||||||
cfg.mnemonics = myui.ask_question(
|
// cfg.mnemonics = myui.ask_question(
|
||||||
question: 'please enter your mnemonics here'
|
// question: 'please enter your mnemonics here'
|
||||||
minlen: 24
|
// minlen: 24
|
||||||
default: cfg.mnemonics
|
// default: cfg.mnemonics
|
||||||
)!
|
// )!
|
||||||
|
|
||||||
cfg.network = myui.ask_dropdown(
|
// cfg.network = myui.ask_dropdown(
|
||||||
question: 'choose environment'
|
// question: 'choose environment'
|
||||||
items: envs.values()
|
// items: envs.values()
|
||||||
)!
|
// )!
|
||||||
|
|
||||||
self.config_save()!
|
// self.config_save()!
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -137,11 +137,10 @@ fn (mut self TFDeployment) set_nodes() ! {
|
|||||||
|
|
||||||
for mut webname in self.webnames {
|
for mut webname in self.webnames {
|
||||||
nodes := filter_nodes(
|
nodes := filter_nodes(
|
||||||
domain: true
|
domain: true
|
||||||
status: 'up'
|
status: 'up'
|
||||||
healthy: true
|
healthy: true
|
||||||
node_id: webname.requirements.node_id
|
node_id: webname.requirements.node_id
|
||||||
features: ['zmachine']
|
|
||||||
)!
|
)!
|
||||||
|
|
||||||
if nodes.len == 0 {
|
if nodes.len == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user