feat: Add Buildah installer
- Added a Buildah installer to the project. - The installer can install and remove Buildah. - Updated the installer to use the latest Buildah version. Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com> Co-authored-by: mariobassem <mariobassem12@gmail.com>
This commit is contained in:
11
examples/installers/buildah.vsh
Executable file
11
examples/installers/buildah.vsh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.virt.buildah as buildah_installer
|
||||
|
||||
mut buildah := buildah_installer.get()!
|
||||
|
||||
// To install
|
||||
buildah.install()!
|
||||
|
||||
// To remove
|
||||
buildah.destroy()!
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:'buildah'
|
||||
classname:'BuildahInstaller'
|
||||
@@ -10,4 +9,4 @@
|
||||
reset:0
|
||||
startupmanager:0
|
||||
hasconfig:0
|
||||
build:1
|
||||
build:0
|
||||
@@ -2,59 +2,26 @@ module buildah
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.installers.lang.golang
|
||||
import os
|
||||
import freeflowuniverse.herolib.core
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()!} buildah -v')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse herocontainers version, expected 'buildah -v' on 1 row.\n${res.output}")
|
||||
}
|
||||
v := texttools.version(r[0].all_after('version').all_before('(').replace('-dev', ''))
|
||||
if texttools.version(version) == v {
|
||||
fn installed() !bool {
|
||||
osal.execute_silent('buildah -v') or { return false }
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn install_() ! {
|
||||
fn install() ! {
|
||||
console.print_header('install buildah')
|
||||
build()!
|
||||
}
|
||||
if core.platform()! != .ubuntu {
|
||||
return error('Only ubuntu is supported for now')
|
||||
}
|
||||
|
||||
fn build_() ! {
|
||||
console.print_header('build buildah')
|
||||
|
||||
osal.package_install('runc,bats,btrfs-progs,git,go-md2man,libapparmor-dev,libglib2.0-dev,libgpgme11-dev,libseccomp-dev,libselinux1-dev,make,skopeo,libbtrfs-dev')!
|
||||
|
||||
mut g := golang.get()!
|
||||
g.install()!
|
||||
|
||||
cmd := '
|
||||
cd /tmp
|
||||
rm -rf buildah
|
||||
git clone https://github.com/containers/buildah
|
||||
cd buildah
|
||||
make SECURITYTAGS="apparmor seccomp"
|
||||
'
|
||||
cmd := 'sudo apt-get -y update && sudo apt-get -y install buildah'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
// now copy to the default bin path
|
||||
osal.cmd_add(
|
||||
cmdname: 'buildah'
|
||||
source: '/tmp/buildah/bin/buildah'
|
||||
)!
|
||||
|
||||
osal.rm('
|
||||
/tmp/buildah
|
||||
')!
|
||||
console.print_header('Buildah Installed Successfuly')
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
@@ -64,17 +31,6 @@ fn ulist_get() !ulist.UList {
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
fn destroy_() ! {
|
||||
osal.package_remove('
|
||||
buildah
|
||||
')!
|
||||
|
||||
// will remove all paths where go/bin is found
|
||||
osal.profile_path_add_remove(paths2delete: 'go/bin')!
|
||||
|
||||
osal.rm('
|
||||
buildah
|
||||
/var/lib/buildah
|
||||
/tmp/buildah
|
||||
')!
|
||||
fn destroy() ! {
|
||||
osal.execute_stdout('sudo apt remove --purge -y buildah')!
|
||||
}
|
||||
|
||||
@@ -14,29 +14,61 @@ __global (
|
||||
|
||||
/////////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 install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
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()!
|
||||
}
|
||||
if !(installed_()!) {
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy() ! {
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
pub fn build() ! {
|
||||
build_()!
|
||||
// switch instance to be used for buildah
|
||||
pub fn switch(name string) {
|
||||
buildah_default = name
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
module buildah
|
||||
|
||||
pub const version = '1.38.0'
|
||||
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()!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user