From 112f5eecb2b73e6318ca24d3cb6edd1dfd42e26b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Jan 2025 11:13:11 +0100 Subject: [PATCH] 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 Co-authored-by: mariobassem --- examples/installers/buildah.vsh | 11 +++ lib/installers/virt/buildah/.heroscript | 3 +- lib/installers/virt/buildah/buildah_actions.v | 70 ++++--------------- .../virt/buildah/buildah_factory_.v | 52 +++++++++++--- lib/installers/virt/buildah/buildah_model.v | 6 +- 5 files changed, 72 insertions(+), 70 deletions(-) create mode 100755 examples/installers/buildah.vsh diff --git a/examples/installers/buildah.vsh b/examples/installers/buildah.vsh new file mode 100755 index 00000000..a5ca6978 --- /dev/null +++ b/examples/installers/buildah.vsh @@ -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()! diff --git a/lib/installers/virt/buildah/.heroscript b/lib/installers/virt/buildah/.heroscript index b3cadebe..405414b2 100644 --- a/lib/installers/virt/buildah/.heroscript +++ b/lib/installers/virt/buildah/.heroscript @@ -1,4 +1,3 @@ - !!hero_code.generate_installer name:'buildah' classname:'BuildahInstaller' @@ -10,4 +9,4 @@ reset:0 startupmanager:0 hasconfig:0 - build:1 \ No newline at end of file + build:0 \ No newline at end of file diff --git a/lib/installers/virt/buildah/buildah_actions.v b/lib/installers/virt/buildah/buildah_actions.v index dd0e9581..7e941bc1 100644 --- a/lib/installers/virt/buildah/buildah_actions.v +++ b/lib/installers/virt/buildah/buildah_actions.v @@ -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 { - return true - } - return false +fn installed() !bool { + osal.execute_silent('buildah -v') or { return false } + + return true } -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')! } diff --git a/lib/installers/virt/buildah/buildah_factory_.v b/lib/installers/virt/buildah/buildah_factory_.v index 846eab53..f659ae7e 100644 --- a/lib/installers/virt/buildah/buildah_factory_.v +++ b/lib/installers/virt/buildah/buildah_factory_.v @@ -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 { - destroy()! - } - if !(installed_()!) { - install_()! +pub fn (mut self BuildahInstaller) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! } } -pub fn destroy() ! { - destroy_()! +pub fn (mut self BuildahInstaller) destroy() ! { + switch(self.name) + destroy()! } -pub fn build() ! { - build_()! +// switch instance to be used for buildah +pub fn switch(name string) { + buildah_default = name } diff --git a/lib/installers/virt/buildah/buildah_model.v b/lib/installers/virt/buildah/buildah_model.v index e2195c0f..6e8d67ae 100644 --- a/lib/installers/virt/buildah/buildah_model.v +++ b/lib/installers/virt/buildah/buildah_model.v @@ -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()! }