This commit is contained in:
2024-12-30 08:01:17 +01:00
parent dfafeecf2c
commit 7894f7d420
218 changed files with 8981 additions and 20 deletions

7
examples/virt/docker/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
docker_registry_example
docker_e1
docker_dev_tools
docker_init
docker_registry
presearch_docker
tf_dashboard

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
mut engine := docker.new(prefix: '', localonly: true)!
mut r := engine.recipe_new(name: 'dev_tools', platform: .alpine)
r.add_from(image: 'alpine', tag: 'latest')!
r.add_package(name: 'git,vim')!
r.add_zinit()!
r.add_sshserver()!
r.build(true)!

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
mut engine := docker.new()!
engine.reset_all()!
println(engine)

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
mut engine := docker.new()!
// engine.reset_all()!
dockerhub_datapath := '/Volumes/FAST/DOCKERHUB'
engine.registry_add(datapath: dockerhub_datapath, ssl: true)!
println(engine)

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
import os
registration_code := os.getenv('PRESEARCH_CODE')
if registration_code == '' {
println("Can't find presearch registration code please run 'export PRESEARCH_CODE=...'")
exit(1)
}
mut engine := docker.new(prefix: '', localonly: true)!
mut recipe := engine.compose_new(name: 'presearch')
mut presearch_node := recipe.service_new(name: 'presearch_node', image: 'presearch/node')!
presearch_node.volume_add('/presearch-node-storage', '/app/node')!
presearch_node.env_add('REGISTRATION_CODE', '${registration_code}')
mut presearch_updater := recipe.service_new(
name: 'presearch_updater'
image: 'presearch/auto-updater'
)!
presearch_updater.volume_add('/var/run/docker.sock', '/var/run/docker.sock')!
recipe.start()!

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
mut engine := docker.new(prefix: '', localonly: true)!
mut recipe := engine.recipe_new(name: 'tf_dashboard', platform: .alpine)
println(' - build dashboard')
recipe.add_from(image: 'nginx', tag: 'alpine')!
recipe.add_nodejsbuilder()!
recipe.add_run(cmd: 'apk add git')!
recipe.add_run(cmd: 'npm i -g yarn')!
recipe.add_run(
cmd: '
git clone https://github.com/threefoldtech/tfgrid-sdk-ts.git /app
cd /app/packages/dashboard
yarn install
yarn lerna run build --no-private
yarn workspace @threefold/dashboard build
'
)!
recipe.add_run(
cmd: '
rm /etc/nginx/conf.d/default.conf
cp /app/packages/dashboard/nginx.conf /etc/nginx/conf.d
apk add --no-cache bash
chmod +x /app/packages/dashboard/scripts/build-env.sh
cp -r /app/packages/dashboard/dist /usr/share/nginx/html
'
)!
recipe.add_run(cmd: 'echo "daemon off;" >> /etc/nginx/nginx.conf')!
recipe.add_cmd(cmd: '/bin/bash -c /app/packages/dashboard/scripts/build-env.sh')!
recipe.add_entrypoint(cmd: 'nginx')!
recipe.build(false)!

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.hetzner
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.builder
import time
import os
console.print_header("Hetzner login.")
//USE IF YOU WANT TO CONFIGURE THE HETZNER, ONLY DO THIS ONCE
//hetzner.configure("test")!
mut cl:=hetzner.get("test")!
for i in 0..5{
println("test cache, first time slow then fast")
cl.servers_list()!
}
println(cl.servers_list()!)
mut serverinfo:= cl.server_info_get(name:"kristof2")!
println(serverinfo)
// cl.server_reset(name:"kristof2",wait:true)!
// cl.server_rescue(name:"kristof2",wait:true)!
console.print_header("SSH login")
mut b := builder.new()!
mut n := b.node_new(ipaddr: serverinfo.server_ip)!
// n.hero_install()!
// n.hero_compile_debug()!
// mut ks:=cl.keys_get()!
// println(ks)

View File

@@ -0,0 +1,9 @@
get the login passwd from:
https://robot.hetzner.com/preferences/index
```bash
curl -u "#ws+JdQtGCdL:..." https://robot-ws.your-server.de/server
```

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.lima
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.installers.virt.lima as limainstaller
import os
limainstaller.install()!
mut virtmanager:=lima.new()!
virtmanager.vm_delete_all()!
// virtmanager.vm_new(reset:true,template:.alpine,name:'alpine',install_hero:false)!
//virtmanager.vm_new(reset:true,template:.arch,name:'arch',install_hero:true)!
virtmanager.vm_new(reset:true,template:.ubuntucloud,name:'hero',install_hero:false)!
mut vm:=virtmanager.vm_get('hero')!
println(vm)
// vm.install_hero()!
// console.print_debug_title("MYVM", vm.str())

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.herocontainers
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.virt.pacman
mut installer:= pacman.get()!
//installer.destroy()!
//installer.install()!
//exit(0)
//interative means will ask for login/passwd
mut engine:=herocontainers.new(install:true,herocompile:false)!
engine.reset_all()!
mut builder_gorust := engine.builder_go_rust()!
//will build nodejs, python build & herolib, hero
//mut builder_hero := engine.builder_hero(reset:true)!
//mut builder_web := engine.builder_heroweb(reset:true)!
builder_gorust.shell()!

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.herocontainers
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.base
// import freeflowuniverse.herolib.builder
import time
import os
mut pm:=herocontainers.new(herocompile:true,install:false)!
mut mybuildcontainer := pm.builder_get("builder_heroweb")!
//bash & python can be executed directly in build container
//any of the herocommands can be executed like this
mybuildcontainer.run(cmd:"installers -n heroweb",runtime:.herocmd)!
// //following will execute heroscript in the buildcontainer
// mybuildcontainer.run(
// cmd:"
// !!play.echo content:'this is just a test'
// !!play.echo content:'this is another test'
// ",
// runtime:.heroscript)!
//there are also shortcuts for this
//mybuildcontainer.hero_copy()!
//mybuildcontainer.shell()!
//mut b2:=pm.builder_get("builderv")!
//b2.shell()!

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.herocontainers
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.base
// import freeflowuniverse.herolib.builder
import time
import os
mut pm:=herocontainers.new(herocompile:false)!
mut b:=pm.builder_new()!
println(b)
// mut mybuildcontainer := pm.builder_get("builderv")!
// mybuildcontainer.clean()!
// mybuildcontainer.commit('localhost/buildersmall')!
b.shell()!

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import os
import flag
import freeflowuniverse.herolib.virt.herocontainers
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.base
// import freeflowuniverse.herolib.builder
import time
mut fp := flag.new_flag_parser(os.args)
fp.application('buildah mdbook example')
fp.limit_free_args(0, 0)! // comment this, if you expect arbitrary texts after the options
fp.skip_executable()
url := fp.string_opt('url', `u`, 'mdbook heroscript url')!
additional_args := fp.finalize() or {
eprintln(err)
println(fp.usage())
return
}
mut pm:=herocontainers.new(herocompile:true,install:false)!
mut mybuildcontainer := pm.builder_get("builder_heroweb")!
// //bash & python can be executed directly in build container
// //any of the herocommands can be executed like this
mybuildcontainer.run(cmd:"installers -n heroweb",runtime:.herocmd)!
mybuildcontainer.run(cmd: 'hero mdbook -u ${url} -o', runtime: .bash)!

View File

View File

@@ -0,0 +1,4 @@
mkdir -p cd /tmp/busyb
cd /tmp/busyb
podman export $(podman create busybox) | tar -C /tmp/busyb -xvf -

View File

@@ -0,0 +1 @@
apt install

View File

@@ -0,0 +1,6 @@
## busybox
- use docker, expand it into a directory

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.installers.virt.cloudhypervisor as cloudhypervisor_installer
import freeflowuniverse.herolib.virt.cloudhypervisor
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.ui.console
import os
mut ci:=cloudhypervisor_installer.get()!
ci.install(reset:true)!
//mut vmm:=cloudhypervisor.new()!
// virtmanager.vm_delete_all()!
// virtmanager.vm_new(reset:true,template:.alpine,name:'alpine',install_hero:true)!
// virtmanager.vm_new(reset:true,template:.ubuntu,name:'ubuntu',install_hero:true)!
// vmm.vm_new(reset:true,template:.arch,name:'arch',install_hero:true)!
// mut vm:=virtmanager.vm_get('ubuntu')!
// vm.install_hero()!
// console.print_debug_title("MYVM", vm.str())

View File

@@ -0,0 +1,49 @@
open vnc://37.27.132.46:5900
some info:
https://simgunz.org/posts/2021-12-12-boot-windows-partition-from-linux-kvm/
## to test rdp works
nc -vz 37.27.132.46 3389
## to install virtio drivers
https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
## status
- the windows 10 works and is installed
## to enable ssh
Open Settings:
Press Win + I
Go to Apps > Optional features
Click "Add a feature"
Search for "OpenSSH Server"
```bash
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Get-Service sshd
ipconfig
```
## how to shrink a disk later
use https://learn.microsoft.com/en-us/sysinternals/downloads/sdelete
then
qemu-img convert -O qcow2 image.qcow2 image2.qcow2
or with commpression:
qemu-img convert -O qcow2 -c image.qcow2 image2.qcow2

View File

@@ -0,0 +1,39 @@
set -ex
cd ~/Downloads
#qemu-img create -f qcow2 windows.qcow2 50G
qemu-system-x86_64 \
-enable-kvm \
-m 6000 \
-cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-smp 4 \
-drive file=windows.iso,media=cdrom \
-vnc :0,password-secret=vnc-password \
-vga std \
-net nic,model=virtio \
-net user \
-net user,hostfwd=tcp::3389-:3389 \
-object secret,id=vnc-password,data=kds007 \
#-drive file=windows.qcow2,format=qcow2,if=virtio \
#-vga qxl \
# -monitor stdio
# -bios /usr/share/OVMF/OVMF_CODE_4M.fd \
# -device qxl-vga,vgamem_mb=32 \
#once virtio installed
# -device virtio-vga,virgl=on,max_vram=16384 \
# -chardev socket,id=chrtpm,path=/tmp/swtpm-sock \
# -tpmdev emulator,id=tpm0,chardev=chrtpm \
# -device tpm-tis,tpmdev=tpm0 \
# -boot order=d \
#-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_CODE_4M.fd \

View File

@@ -0,0 +1,38 @@
set -ex
cd ~/Downloads
swtpm socket --tpmstate dir=/tmp/mytpm1 --ctrl type=unixio,path=/tmp/swtpm-sock --log level=20 &
qemu-system-x86_64 \
-enable-kvm \
-m 8000 \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.secboot.fd \
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
-cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-smp 4 \
-boot order=dc \
-cdrom windows.iso \
-drive file=windows.qcow2,format=qcow2,if=virtio \
-vnc :0,password-secret=vnc-password \
-vga cirrus \
-net nic,model=virtio \
-net user \
-net user,hostfwd=tcp::3389-:3389 \
-chardev socket,id=chrtpm,path=/tmp/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis,tpmdev=tpm0 \
-object secret,id=vnc-password,data=kds007 \
-monitor stdio
# Block format 'qcow2' does not support the option 'bootindex
# -drive file=windows.qcow2,format=qcow2,if=virtio \
# it works without this but then we don't have the UEFI
# -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
# -drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
#it should be /usr/share/OVMF/OVMF_CODE_4M.secboot.fd

View File

@@ -0,0 +1,33 @@
set -ex
cd ~/Downloads
qemu-system-x86_64 \
-enable-kvm \
-m 8000 \
-cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-smp 4 \
-drive file=windows.qcow2,format=qcow2 \
-vnc :0,password-secret=vnc-password \
-vga qxl \
-cdrom virtio-win.iso \
-net nic \
-net user,hostfwd=tcp::3389-:3389,hostfwd=tcp::9922-:22 \
-object secret,id=vnc-password,data=planetfirst007 \
-monitor stdio
#-drive file=windows.qcow2,format=qcow2,if=virtio \
# -net nic,model=virtio \
# Block format 'qcow2' does not support the option 'bootindex
# -drive file=windows.qcow2,format=qcow2,if=virtio \
# it works without this but then we don't have the UEFI
# -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
# -drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
#it should be /usr/share/OVMF/OVMF_CODE_4M.secboot.fd

View File

@@ -0,0 +1,27 @@
set -ex
cd ~/Downloads
qemu-system-x86_64 \
-enable-kvm \
-m 8000 \
-cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-smp 4 \
-drive file=windows3.qcow2,format=qcow2,if=virtio \
-drive file=/dev/null,format=raw,if=virtio \
-vnc :0,password-secret=vnc-password \
-vga qxl \
-device virtio-net-pci,netdev=n1 \
-netdev user,id=n1,hostfwd=tcp::3389-:3389,hostfwd=tcp::9922-:22 \
-object secret,id=vnc-password,data=planetfirst007 \
-monitor stdio
# -netdev user,id=n1,hostfwd=tcp::3389-:3389,hostfwd=tcp::9923-:22 \
# -vga virtio \
# -device virtio-net-pci,netdev=n1 \
# -netdev user,id=n1,hostfwd=tcp::3389-:3389,hostfwd=tcp::9922-:22 \
# -drive file=windows3.qcow2,format=qcow2,if=virtio \