Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 690b1b68c3 | |||
| 6e619622d2 |
@@ -31,7 +31,7 @@ fn do() ! {
|
||||
mut cmd := Command{
|
||||
name: 'hero'
|
||||
description: 'Your HERO toolset.'
|
||||
version: '1.0.6'
|
||||
version: '1.0.7'
|
||||
}
|
||||
|
||||
// herocmds.cmd_run_add_flags(mut cmd)
|
||||
|
||||
1
examples/virt/podman_buildah/.gitignore
vendored
Normal file
1
examples/virt/podman_buildah/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
buildah_example
|
||||
@@ -1,15 +1,14 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -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
|
||||
import freeflowuniverse.herolib.installers.virt.podman as podman_installer
|
||||
|
||||
mut installer := pacman.get()!
|
||||
|
||||
// installer.destroy()!
|
||||
// installer.install()!
|
||||
mut podman_installer0 := podman_installer.get()!
|
||||
// podman_installer0.destroy()!
|
||||
podman_installer0.install()!
|
||||
|
||||
// exit(0)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import freeflowuniverse.herolib.virt.herocontainers
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.base
|
||||
// import freeflowuniverse.herolib.builder
|
||||
import time
|
||||
import os
|
||||
|
||||
@@ -4,7 +4,7 @@ set -e
|
||||
|
||||
os_name="$(uname -s)"
|
||||
arch_name="$(uname -m)"
|
||||
version='1.0.6'
|
||||
version='1.0.7'
|
||||
|
||||
|
||||
# Base URL for GitHub releases
|
||||
|
||||
@@ -115,11 +115,11 @@ fn install() ! {
|
||||
console.print_header('install ${args.name}')
|
||||
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// mut url := ''
|
||||
// if osal.is_linux_arm() {
|
||||
// if core.is_linux_arm() {
|
||||
// url = 'https://github.com/${args.name}-dev/${args.name}/releases/download/v??{version}/${args.name}_??{version}_linux_arm64.tar.gz'
|
||||
// } else if osal.is_linux_intel() {
|
||||
// } else if core.is_linux_intel() {
|
||||
// url = 'https://github.com/${args.name}-dev/${args.name}/releases/download/v??{version}/${args.name}_??{version}_linux_amd64.tar.gz'
|
||||
// } else if osal.is_osx_arm() {
|
||||
// } else if core.is_osx_arm() {
|
||||
// url = 'https://github.com/${args.name}-dev/${args.name}/releases/download/v??{version}/${args.name}_??{version}_darwin_arm64.tar.gz'
|
||||
// } else if osal.is_osx_intel() {
|
||||
// url = 'https://github.com/${args.name}-dev/${args.name}/releases/download/v??{version}/${args.name}_??{version}_darwin_amd64.tar.gz'
|
||||
|
||||
@@ -54,9 +54,9 @@ pub fn v_analyzer_install(args_ InstallArgs) ! {
|
||||
// if pl == .ubuntu {
|
||||
// }else{
|
||||
// mut url := ''
|
||||
// if osal.is_linux_intel() {
|
||||
// if core.is_linux_intel() {
|
||||
// url = 'https://github.com/vlang/v-analyzer/releases/download/nightly/v-analyzer-linux-x86_64.zip'
|
||||
// } else if osal.is_osx_arm() {
|
||||
// } else if core.is_osx_arm() {
|
||||
// url = 'https://github.com/vlang/v-analyzer/releases/download/nightly/v-analyzer-darwin-arm64.zip'
|
||||
// } else if osal.is_osx_intel() {
|
||||
// url = 'https://github.com/vlang/v-analyzer/releases/download/nightly/v-analyzer-darwin-x86_64.zip'
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
!!hero_code.generate_installer
|
||||
name:'buildah'
|
||||
classname:'BuildahInstaller'
|
||||
singleton:1
|
||||
templates:0
|
||||
default:1
|
||||
title:''
|
||||
supported_platforms:''
|
||||
reset:0
|
||||
startupmanager:0
|
||||
hasconfig:0
|
||||
build:0
|
||||
@@ -1,36 +0,0 @@
|
||||
module buildah
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.core
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
osal.execute_silent('buildah -v') or { return false }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install buildah')
|
||||
if core.platform()! != .ubuntu {
|
||||
return error('Only ubuntu is supported for now')
|
||||
}
|
||||
|
||||
cmd := 'sudo apt-get -y update && sudo apt-get -y install buildah'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
console.print_header('Buildah Installed Successfuly')
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
// mut installer := get()!
|
||||
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
osal.execute_stdout('sudo apt remove --purge -y buildah')!
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
module buildah
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
buildah_global map[string]&BuildahInstaller
|
||||
buildah_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&BuildahInstaller {
|
||||
return &BuildahInstaller{}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self BuildahInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self BuildahInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for buildah
|
||||
pub fn switch(name string) {
|
||||
buildah_default = name
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
module buildah
|
||||
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct BuildahInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ BuildahInstaller) !BuildahInstaller {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
return obj
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
// mut installer := get()!
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
# buildah
|
||||
|
||||
|
||||
|
||||
To get started
|
||||
|
||||
```vlang
|
||||
|
||||
|
||||
import freeflowuniverse.herolib.installers.something. buildah
|
||||
|
||||
mut installer:= buildah.get()!
|
||||
|
||||
installer.start()!
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## example heroscript
|
||||
|
||||
```hero
|
||||
!!buildah.install
|
||||
homedir: '/home/user/buildah'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
title: 'Some Title'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ module pacman
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core
|
||||
import os
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
@@ -19,7 +20,7 @@ fn install_() ! {
|
||||
return
|
||||
}
|
||||
|
||||
if core.platform() != .ubuntu {
|
||||
if core.platform()! != .ubuntu {
|
||||
return error('only ubuntu supported for this installer.')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,87 +1,101 @@
|
||||
module podman
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
|
||||
|
||||
import os
|
||||
|
||||
// Check if Podman is installed
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
console.print_header('Checking if Podman is installed...')
|
||||
result := os.execute('podman -v')
|
||||
return result.exit_code == 0
|
||||
res := os.execute('${osal.profile_path_source_and()!} podman -v')
|
||||
if res.exit_code != 0 {
|
||||
println(res)
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse podman version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) <= texttools.version(r[0].all_after("version")) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
// Install Podman
|
||||
fn install() ! {
|
||||
if installed()! {
|
||||
return error('Podman is already installed.')
|
||||
}
|
||||
console.print_header('install podman')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! || core.is_linux_intel()!{
|
||||
osal.package_install("podman,buildah,crun,mmdebstrap")!
|
||||
return
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-arm64.pkg'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-amd64.pkg'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
console.print_header('Installing Podman...')
|
||||
platform := core.platform()!
|
||||
command := get_platform_command(platform, 'install')!
|
||||
execute_command(command, 'installing Podman')!
|
||||
console.print_header('Podman installed successfully.')
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 9000
|
||||
expand_dir: '/tmp/podman'
|
||||
)!
|
||||
|
||||
//dest.moveup_single_subdir()!
|
||||
|
||||
panic("implement")
|
||||
}
|
||||
|
||||
// Remove Podman
|
||||
|
||||
fn destroy() ! {
|
||||
if !installed()! {
|
||||
return error('Podman is not installed.')
|
||||
}
|
||||
|
||||
console.print_header('Removing Podman...')
|
||||
platform := core.platform()!
|
||||
command := get_platform_command(platform, 'remove')!
|
||||
execute_command(command, 'removing Podman')!
|
||||
console.print_header('Podman removed successfully.')
|
||||
// mut systemdfactory := systemd.new()!
|
||||
// systemdfactory.destroy("zinit")!
|
||||
|
||||
// osal.process_kill_recursive(name:'zinit')!
|
||||
// osal.cmd_delete('zinit')!
|
||||
|
||||
osal.package_remove('
|
||||
podman
|
||||
conmon
|
||||
buildah
|
||||
skopeo
|
||||
runc
|
||||
')!
|
||||
|
||||
// //will remove all paths where go/bin is found
|
||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||
|
||||
osal.rm("
|
||||
podman
|
||||
conmon
|
||||
buildah
|
||||
skopeo
|
||||
runc
|
||||
/var/lib/containers
|
||||
/var/lib/podman
|
||||
/var/lib/buildah
|
||||
/tmp/podman
|
||||
/tmp/conmon
|
||||
")!
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Build Podman (install it)
|
||||
fn build() ! {
|
||||
install()!
|
||||
}
|
||||
|
||||
// Get platform-specific commands for installing/removing Podman
|
||||
fn get_platform_command(platform core.PlatformType, action string) !string {
|
||||
return match platform {
|
||||
.ubuntu {
|
||||
if action == 'install' {
|
||||
'sudo apt-get -y install podman'
|
||||
} else if action == 'remove' {
|
||||
'sudo apt-get -y remove podman'
|
||||
} else {
|
||||
return error('Invalid action: ${action}')
|
||||
}
|
||||
}
|
||||
.arch {
|
||||
if action == 'install' {
|
||||
'sudo pacman -S --noconfirm podman'
|
||||
} else if action == 'remove' {
|
||||
'sudo pacman -R --noconfirm podman'
|
||||
} else {
|
||||
return error('Invalid action: ${action}')
|
||||
}
|
||||
}
|
||||
.osx {
|
||||
if action == 'install' {
|
||||
'brew install podman'
|
||||
} else if action == 'remove' {
|
||||
'brew uninstall podman'
|
||||
} else {
|
||||
return error('Invalid action: ${action}')
|
||||
}
|
||||
}
|
||||
else {
|
||||
return error('Only Ubuntu, Arch, and macOS are supported.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute a shell command and handle errors
|
||||
fn execute_command(command string, operation string) ! {
|
||||
result := os.execute(command)
|
||||
if result.exit_code != 0 {
|
||||
return error('Failed ${operation}: ${result.output}')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +1,124 @@
|
||||
module podman
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
podman_global map[string]&PodmanInstaller
|
||||
podman_default string
|
||||
podman_global map[string]&PodmanInstaller
|
||||
podman_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub struct ArgsGet{
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&PodmanInstaller {
|
||||
return &PodmanInstaller{}
|
||||
pub fn get(args_ ArgsGet) !&PodmanInstaller {
|
||||
return &PodmanInstaller{}
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
|
||||
mut args:=args_
|
||||
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
|
||||
mut other_actions := plbook.find(filter: 'podman.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ["destroy","install","build"]{
|
||||
mut p := other_action.params
|
||||
reset:=p.get_default_false("reset")
|
||||
if other_action.name == "destroy" || reset{
|
||||
console.print_debug("install action podman.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action podman.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat{
|
||||
.zinit{
|
||||
console.print_debug("startupmanager: zinit")
|
||||
return startupmanager.get(cat:.zinit)!
|
||||
}
|
||||
.systemd{
|
||||
console.print_debug("startupmanager: systemd")
|
||||
return startupmanager.get(cat:.systemd)!
|
||||
}else{
|
||||
console.print_debug("startupmanager: auto")
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub struct InstallArgs{
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self PodmanInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || !installed()! {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self PodmanInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for podman
|
||||
|
||||
|
||||
//switch instance to be used for podman
|
||||
pub fn switch(name string) {
|
||||
podman_default = name
|
||||
podman_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -1,10 +1,40 @@
|
||||
module podman
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import os
|
||||
|
||||
pub const version = '4.9.3'
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct PodmanInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
|
||||
|
||||
//your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ PodmanInstaller)!PodmanInstaller{
|
||||
mut mycfg:=mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
//called before start if done
|
||||
fn configure() ! {
|
||||
//mut installer := get()!
|
||||
}
|
||||
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj PodmanInstaller) !string {
|
||||
return encoderhero.encode[PodmanInstaller ](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !PodmanInstaller {
|
||||
mut obj := encoderhero.decode[PodmanInstaller](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -124,6 +124,9 @@ pub fn profile_path_source() !string {
|
||||
// or empty if it doesn't exist
|
||||
pub fn profile_path_source_and() !string {
|
||||
p := profile_path_source() or { return '' }
|
||||
if p.len==0{
|
||||
return ""
|
||||
}
|
||||
return '${p} && '
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,10 @@ pub fn package_install(name_ string) ! {
|
||||
platform_ := core.platform()!
|
||||
cpu := core.cputype()!
|
||||
|
||||
mut sudo_pre:=""
|
||||
if core.sudo_required()! {
|
||||
sudo_pre="sudo "
|
||||
}
|
||||
if platform_ == .osx {
|
||||
if cpu == .arm {
|
||||
exec(cmd: 'arch --arm64 brew install ${name}') or {
|
||||
@@ -64,37 +68,14 @@ pub fn package_install(name_ string) ! {
|
||||
}
|
||||
}
|
||||
} else if platform_ == .ubuntu {
|
||||
// Use sudo if required (based on user's permissions)
|
||||
use_sudo := core.sudo_required()!
|
||||
|
||||
cmd := if use_sudo {
|
||||
'sudo apt install -y ${name} -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --allow-downgrades --allow-remove-essential --allow-change-held-packages'
|
||||
} else {
|
||||
'apt install -y ${name} -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --allow-downgrades --allow-remove-essential --allow-change-held-packages'
|
||||
}
|
||||
exec(cmd: cmd) or {
|
||||
return error('could not install package on Ubuntu: ${name}\nerror:\n${err}')
|
||||
}
|
||||
exec(cmd: 'export DEBIAN_FRONTEND=noninteractive && ${sudo_pre}apt install -y ${name} -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --allow-downgrades --allow-remove-essential --allow-change-held-packages')
|
||||
or { return error('could not install package on Ubuntu: ${name}\nerror:\n${err}')}
|
||||
} else if platform_ == .alpine {
|
||||
// Use sudo if required
|
||||
use_sudo := core.sudo_required()!
|
||||
cmd := if use_sudo {
|
||||
'sudo apk add ${name}'
|
||||
} else {
|
||||
'apk add ${name}'
|
||||
}
|
||||
exec(cmd: cmd) or {
|
||||
exec(cmd: "${sudo_pre}apk add ${name}") or {
|
||||
return error('could not install package on Alpine: ${name}\nerror:\n${err}')
|
||||
}
|
||||
} else if platform_ == .arch {
|
||||
// Use sudo if required
|
||||
use_sudo := core.sudo_required()!
|
||||
cmd := if use_sudo {
|
||||
'sudo pacman --noconfirm -Su ${name}'
|
||||
} else {
|
||||
'pacman --noconfirm -Su ${name}'
|
||||
}
|
||||
exec(cmd: cmd) or {
|
||||
exec(cmd: '${sudo_pre}pacman --noconfirm -Su ${name}') or {
|
||||
return error('could not install package on Arch: ${name}\nerror:\n${err}')
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -179,8 +179,8 @@ pub fn (mut self Builder) clean() ! {
|
||||
#set -x
|
||||
set +e
|
||||
rm -rf /root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/doc
|
||||
pacman -Rns $(pacman -Qtdq) --noconfirm
|
||||
pacman -Scc --noconfirm
|
||||
#pacman -Rns $(pacman -Qtdq) --noconfirm
|
||||
#pacman -Scc --noconfirm
|
||||
rm -rf /var/lib/pacman/sync/*
|
||||
rm -rf /tmp/*
|
||||
rm -rf /var/tmp/*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module herocontainers
|
||||
|
||||
import freeflowuniverse.herolib.osal { exec }
|
||||
import freeflowuniverse.herolib.core
|
||||
|
||||
@[heap]
|
||||
pub struct CEngine {
|
||||
@@ -51,7 +52,7 @@ pub fn (mut e CEngine) reset_all() ! {
|
||||
exec(cmd: 'podman rmi -a -f', stdout: false)!
|
||||
e.builders_delete_all()!
|
||||
osal.done_reset()!
|
||||
if core.platform()! == .arch {
|
||||
if core.platform()! == core.PlatformType.arch {
|
||||
exec(cmd: 'systemctl status podman.socket', stdout: false)!
|
||||
}
|
||||
e.load()!
|
||||
|
||||
@@ -2,7 +2,6 @@ module herocontainers
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.installers.virt.pacman
|
||||
import os
|
||||
|
||||
@[params]
|
||||
@@ -14,17 +13,52 @@ pub struct GetArgs {
|
||||
pub fn (mut e CEngine) builder_base(args GetArgs) !Builder {
|
||||
name := 'base'
|
||||
if !args.reset && e.builder_exists(name)! {
|
||||
|
||||
return e.builder_get(name)!
|
||||
}
|
||||
console.print_header('buildah base build')
|
||||
|
||||
// mut installer:= pacman.get()!
|
||||
// installer.install()!
|
||||
|
||||
mut builder := e.builder_new(name: name, from: 'scratch', delete: true)!
|
||||
mount_path := builder.mount_to_path()!
|
||||
if mount_path.len<4{
|
||||
return error("mount_path needs to be +4 chars")
|
||||
}
|
||||
osal.exec(
|
||||
cmd: 'pacstrap -D -c ${mount_path} base screen bash coreutils curl mc unzip sudo which openssh'
|
||||
cmd: '
|
||||
|
||||
export MOUNT_PATH=\'${mount_path}\'
|
||||
|
||||
mmdebstrap --variant=minbase --components="main,universe" --include="apt,base-files,base-passwd,bash,coreutils" noble \${MOUNT_PATH}
|
||||
|
||||
echo "Binding essential directories..."
|
||||
mount --bind /dev "\${MOUNT_PATH}/dev"
|
||||
mount --bind /proc "\${MOUNT_PATH}/proc"
|
||||
mount --bind /sys "\${MOUNT_PATH}/sys"
|
||||
|
||||
echo "tzdata tzdata/Areas select Europe" | chroot "\${MOUNT_PATH}" debconf-set-selections
|
||||
echo "tzdata tzdata/Zones/Europe select Brussels" | chroot "\${MOUNT_PATH}" debconf-set-selections
|
||||
|
||||
chroot \${MOUNT_PATH} apt update
|
||||
|
||||
# Set up APT for non-interactive installation
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
export DEBCONF_NONINTERACTIVE_SEEN=true
|
||||
|
||||
# Update package lists
|
||||
echo "Updating package lists in chroot..."
|
||||
chroot \${MOUNT_PATH} apt-get update -yq
|
||||
|
||||
# Install required packages
|
||||
echo "Installing essential packages..."
|
||||
chroot \${MOUNT_PATH} apt-get install -yq screen bash coreutils curl mc unzip sudo which openssh-client openssh-server redis
|
||||
|
||||
echo "Cleaning up..."
|
||||
umount "\${MOUNT_PATH}/dev" || true
|
||||
umount "\${MOUNT_PATH}/proc" || true
|
||||
umount "\${MOUNT_PATH}/sys" || true
|
||||
|
||||
'
|
||||
)!
|
||||
// builder.set_entrypoint('redis-server')!
|
||||
builder.commit('localhost/${name}')!
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module herocontainers
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import json
|
||||
|
||||
fn (mut e CEngine) builders_load() ! {
|
||||
@@ -66,12 +66,14 @@ pub fn (mut e CEngine) builder_get(name string) !Builder {
|
||||
}
|
||||
|
||||
pub fn (mut e CEngine) builders_delete_all() ! {
|
||||
console.print_debug("remove all")
|
||||
osal.execute_stdout('buildah rm -a')!
|
||||
e.builders_load()!
|
||||
}
|
||||
|
||||
pub fn (mut e CEngine) builder_delete(name string) ! {
|
||||
if e.builder_exists(name)! {
|
||||
console.print_debug("remove ${name}")
|
||||
osal.execute_stdout('buildah rm ${name}')!
|
||||
e.builders_load()!
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
module herocontainers
|
||||
|
||||
import freeflowuniverse.herolib.installers.virt.podman as podman_installer
|
||||
import freeflowuniverse.herolib.installers.virt.buildah as buildah_installer
|
||||
import freeflowuniverse.herolib.installers.lang.herolib
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
|
||||
@[params]
|
||||
pub struct NewArgs {
|
||||
@@ -22,9 +21,7 @@ pub fn new(args_ NewArgs) !CEngine {
|
||||
|
||||
if args.install {
|
||||
mut podman_installer0 := podman_installer.get()!
|
||||
mut buildah_installer0 := buildah_installer.get()!
|
||||
podman_installer0.install()!
|
||||
buildah_installer0.install()!
|
||||
}
|
||||
|
||||
if args.herocompile {
|
||||
|
||||
35
release.sh
35
release.sh
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Function to get the latest release tag
|
||||
get_latest_release() {
|
||||
curl --silent "https://api.github.com/repos/freeflowuniverse/herolib/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
|
||||
}
|
||||
|
||||
# Show current version
|
||||
echo "Current latest release: $(get_latest_release)"
|
||||
|
||||
# Ask for new version
|
||||
read -p "Enter new version (e.g., 1.0.4): " new_version
|
||||
|
||||
# Validate version format
|
||||
if [[ ! $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "Error: Version must be in format X.Y.Z (e.g., 1.0.4)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Update version in hero.v
|
||||
sed -i.bak "s/version: '[0-9]\+\.[0-9]\+\.[0-9]\+'/version: '$new_version'/" cli/hero.v
|
||||
rm -f cli/hero.v.bak
|
||||
|
||||
# Commit changes
|
||||
git add . -A
|
||||
git commit -m "chore: bump version to $new_version"
|
||||
git pull
|
||||
git push
|
||||
|
||||
# Create and push tag
|
||||
git tag -a "v$new_version" -m "Release version $new_version"
|
||||
git push origin "v$new_version"
|
||||
|
||||
echo "Release v$new_version created and pushed!"
|
||||
60
release.vsh
60
release.vsh
@@ -41,7 +41,7 @@ if !version_re.matches_string(new_version) {
|
||||
|
||||
ourdir := dir(@FILE)
|
||||
|
||||
|
||||
os.chdir(ourdir)!
|
||||
hero_v_path := '${ourdir}/cli/hero.v'
|
||||
|
||||
// Read hero.v
|
||||
@@ -92,12 +92,56 @@ os.rm('${hero_v_path}.backup') or {
|
||||
eprintln('Warning: Could not remove backup file: ${err}')
|
||||
}
|
||||
|
||||
// Git operations
|
||||
os.execute('git add ${hero_v_path}')
|
||||
os.execute('git commit -m "chore: bump version to ${new_version}"')
|
||||
os.execute('git pull')
|
||||
os.execute('git push')
|
||||
os.execute('git tag -a "v${new_version}" -m "Release version ${new_version}"')
|
||||
os.execute('git push origin "v${new_version}"')
|
||||
|
||||
// Update version in install_hero.sh
|
||||
install_hero_path := '${ourdir}/install_hero.sh'
|
||||
install_hero_content := os.read_file(install_hero_path) or {
|
||||
eprintln('Error reading ${install_hero_path}: ${err}')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
// Create backup of install_hero.sh
|
||||
os.cp(install_hero_path, '${install_hero_path}.backup') or {
|
||||
eprintln('Error creating backup of install_hero.sh: ${err}')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
// Replace version in install_hero.sh
|
||||
mut install_hero_lines := install_hero_content.split_into_lines()
|
||||
for i, line in install_hero_lines {
|
||||
if line.contains("version='") {
|
||||
install_hero_lines[i] = "version='${new_version}'"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Write back to install_hero.sh
|
||||
os.write_file(install_hero_path, install_hero_lines.join_lines()) or {
|
||||
eprintln('Error writing to ${install_hero_path}: ${err}')
|
||||
// Restore backup
|
||||
os.cp('${install_hero_path}.backup', install_hero_path) or {
|
||||
eprintln('Error restoring backup of install_hero.sh: ${err}')
|
||||
}
|
||||
exit(1)
|
||||
}
|
||||
|
||||
// Clean up backup of install_hero.sh
|
||||
os.rm('${install_hero_path}.backup') or {
|
||||
eprintln('Warning: Could not remove backup file of install_hero.sh: ${err}')
|
||||
}
|
||||
|
||||
|
||||
cmd:='
|
||||
git remote set-url origin git@github.com:freeflowuniverse/herolib.git
|
||||
git add ${hero_v_path} ${install_hero_path}
|
||||
git commit -m "bump version to ${new_version}"
|
||||
git pull git@github.com:freeflowuniverse/herolib.git main
|
||||
git tag -a "v${new_version}" -m "Release version ${new_version}"
|
||||
git push git@github.com:freeflowuniverse/herolib.git "v${new_version}"
|
||||
'
|
||||
|
||||
println(cmd)
|
||||
|
||||
os.execute_or_panic('${cmd}')
|
||||
|
||||
println('Release v${new_version} created and pushed!')
|
||||
|
||||
Reference in New Issue
Block a user