Skip to content

virt.podman #

BuildAH & Podman

#!/usr/bin/env -S  v -n -cg -w -enable-globals run

import freeflowuniverse.crystallib.virt.podman
import freeflowuniverse.crystallib.ui.console
import freeflowuniverse.crystallib.builder

//interative means will ask for login/passwd

console.print_header("BUILDAH Demo.")

//if herocompile on, then will forced compile hero, which might be needed in debug mode for hero 
// to execute hero scripts inside build container
mut pm:=podman.new(herocompile=true)!
//mut b:=pm.builder_new(name:"test")!

//create 
pm.builderv_create()!

//get the container
//mut b2:=pm.builder_get("builderv")!
//b2.shell()!


buildah tricks

#buildah ls
#buildah images

result is something like

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
a9946633d4e7     *                  scratch                          base
86ff0deb00bf     *     4feda76296d6 localhost/builder:latest         base_go_rust

some tricks

#buildah run --terminal --env TERM=xterm base /bin/bash
orbuildah run --terminal --env TERM=xterm base_go_rust /bin/bash

to check inside the container about diskusage

pacman -Su ncdu
ncdu

fn new #

fn new(args_ NewArgs) !CEngine

enum BuildPlatformType #

enum BuildPlatformType {
	linux_arm64
	linux_amd64
}

enum RunTime #

enum RunTime {
	bash
	python
	heroscript
	herocmd
	v
}

struct BAHShellArgs #

@[params]
struct BAHShellArgs {
pub mut:
	cmd string
}

// open ssh shell to the cobtainer pub fn (mut container Container) ssh_shell(cmd string) ! { container.engine.node.shell(cmd)! }

struct Builder #

@[heap]
struct Builder {
pub mut:
	id            string
	builder       bool
	imageid       string
	imagename     string
	containername string
	engine        &CEngine @[skip; str: skip]
	// hero_in_container bool //once the hero has been installed this is on, does it once per session
	// created         time.Time
	// ssh_enabled     bool // if yes make sure ssh is enabled to the container
	// ipaddr          IPAddress
	// forwarded_ports []string
	// mounts          []ContainerVolume
	// ssh_port        int // ssh port on node that is used to get ssh
	// ports           []string
	// networks        []string
	// labels          map[string]string       @[str: skip]
	// image           &Image            @[str: skip]
	// engine          &CEngine           @[str: skip]
	// status          ContainerStatus
	// memsize         int // in MB
	// command         string
}

need to fill in what is relevant

fn (Builder) run #

fn (mut self Builder) run(cmd Command) !

fn (Builder) copy #

fn (mut self Builder) copy(src string, dest string) !

fn (Builder) hero_copy #

fn (mut self Builder) hero_copy() !

copies the hero from host into guest

fn (Builder) hero_execute_cmd #

fn (mut self Builder) hero_execute_cmd(cmd string) !

copies the hero from host into guest and then execute the heroscript or commandline

fn (Builder) hero_execute_script #

fn (mut self Builder) hero_execute_script(cmd string) !

fn (Builder) shell #

fn (mut self Builder) shell() !

fn (Builder) clean #

fn (mut self Builder) clean() !

fn (Builder) delete #

fn (mut self Builder) delete() !

fn (Builder) inspect #

fn (mut self Builder) inspect() !BuilderInfo

fn (Builder) mount_to_path #

fn (mut self Builder) mount_to_path() !string

mount the build container to a path and return

fn (Builder) commit #

fn (mut self Builder) commit(image_name string) !

fn (Builder) set_entrypoint #

fn (self Builder) set_entrypoint(entrypoint string) !

fn (Builder) set_workingdir #

fn (self Builder) set_workingdir(workdir string) !

fn (Builder) set_cmd #

fn (self Builder) set_cmd(command string) !

struct BuilderNewArgs #

@[params]
struct BuilderNewArgs {
pub mut:
	name string @[required]
	from string = 'docker.io/archlinux:latest'
	// arch_scratch bool // means start from scratch with arch linux
	delete bool = true
}

struct CEngine #

@[heap]
struct CEngine {
pub mut:
	sshkeys_allowed []string // all keys here have access over ssh into the machine, when ssh enabled
	images          []Image
	containers      []Container
	builders        []Builder
	buildpath       string
	localonly       bool
	cache           bool = true
	push            bool
	// platform        []BuildPlatformType // used to build
	// registries      []BAHRegistry    // one or more supported BAHRegistries
	prefix string
}

fn (CEngine) builder_base #

fn (mut e CEngine) builder_base(args GetArgs) !Builder

builder machine based on arch and install vlang

fn (CEngine) builder_crystal #

fn (mut e CEngine) builder_crystal(args GetArgs) !Builder

fn (CEngine) builder_delete #

fn (mut e CEngine) builder_delete(name string) !

fn (CEngine) builder_exists #

fn (mut e CEngine) builder_exists(name string) !bool

fn (CEngine) builder_get #

fn (mut e CEngine) builder_get(name string) !Builder

fn (CEngine) builder_go_rust #

fn (mut e CEngine) builder_go_rust(args GetArgs) !Builder

builder machine based on arch and install vlang

fn (CEngine) builder_herodev #

fn (mut e CEngine) builder_herodev(args GetArgs) !Builder

fn (CEngine) builder_heroweb #

fn (mut e CEngine) builder_heroweb(args GetArgs) !Builder

fn (CEngine) builder_js #

fn (mut e CEngine) builder_js(args GetArgs) !Builder

fn (CEngine) builder_js_python #

fn (mut e CEngine) builder_js_python(args GetArgs) !Builder

fn (CEngine) builder_names #

fn (mut e CEngine) builder_names() ![]string

fn (CEngine) builder_new #

fn (mut e CEngine) builder_new(args_ BuilderNewArgs) !Builder

fn (CEngine) builders_delete_all #

fn (mut e CEngine) builders_delete_all() !

fn (CEngine) builders_get #

fn (mut e CEngine) builders_get() ![]Builder

get buildah containers

fn (CEngine) container_delete #

fn (mut e CEngine) container_delete(args ContainerGetArgs) !

fn (CEngine) container_exists #

fn (mut e CEngine) container_exists(args ContainerGetArgs) !bool

fn (CEngine) container_get #

fn (mut e CEngine) container_get(args_ ContainerGetArgs) !&Container

get container from memory, can use match_glob see https://modules.vlang.io/index.html#string.match_glob

fn (CEngine) containers_delete #

fn (mut e CEngine) containers_delete(args ContainerGetArgs) !

remove one or more container

fn (CEngine) containers_get #

fn (mut e CEngine) containers_get(args_ ContainerGetArgs) ![]&Container

get containers from memory params: name string (can also be a glob e.g. use *,? and []) id string image_id string

fn (CEngine) get_free_port #

fn (mut e CEngine) get_free_port() ?int

Get free port

fn (CEngine) image_exists #

fn (mut e CEngine) image_exists(args ImageGetArgs) !bool

fn (CEngine) image_get #

fn (mut e CEngine) image_get(args ImageGetArgs) !Image

find image based on repo and optional tag args: repo string tag string digest string id string id_full

fn (CEngine) image_load #

fn (mut engine CEngine) image_load(path string) !

import podman image back into the local env

fn (CEngine) images_get #

fn (mut e CEngine) images_get() ![]Image

get buildah containers

fn (CEngine) load #

fn (mut e CEngine) load() !

reload the state from system

fn (CEngine) reset_all #

fn (mut e CEngine) reset_all() !

reset all images & containers, CAREFUL!

struct Command #

@[params]
struct Command {
pub mut:
	name               string // to give a name to your command, good to see logs...
	cmd                string
	description        string
	timeout            int  = 3600 // timeout in sec
	stdout             bool = true
	stdout_log         bool = true
	raise_error        bool = true // if false, will not raise an error but still error report
	ignore_error       bool              // means if error will just exit and not raise, there will be no error reporting
	work_folder        string            // location where cmd will be executed
	environment        map[string]string // env variables
	ignore_error_codes []int
	scriptpath         string // is the path where the script will be put which is executed
	scriptkeep         bool   // means we don't remove the script
	debug              bool   // if debug will put +ex in the script which is being executed and will make sure script stays
	shell              bool   // means we will execute it in a shell interactive
	retry              int
	interactive        bool = true
	async              bool
	runtime            osal.RunTime
}

pub fn (mut self Builder) package_install(args PackageInstallArgs) !{ //TODO names := texttools.to_array(args.names) //now check which OS, need to make platform function on container level so we know which platform it is panic("implement") }

struct Container #

@[heap]
struct Container {
pub mut:
	id              string
	name            string
	created         time.Time
	ssh_enabled     bool // if yes make sure ssh is enabled to the container
	ipaddr          IPAddress
	forwarded_ports []string
	mounts          []utils.ContainerVolume
	ssh_port        int // ssh port on node that is used to get ssh
	ports           []string
	networks        []string
	labels          map[string]string @[str: skip]
	image           &Image            @[str: skip]
	engine          &CEngine          @[skip; str: skip]
	status          utils.ContainerStatus
	memsize         int // in MB
	command         string
}

fn (Container) start #

fn (mut container Container) start() !

create/start container (first need to get a podmancontainer before we can start)

fn (Container) halt #

fn (mut container Container) halt() !

delete podman container

fn (Container) delete #

fn (mut container Container) delete() !

delete podman container

fn (Container) save2image #

fn (mut container Container) save2image(image_repo string, image_tag string) !string

save the podman container to image

fn (Container) export #

fn (mut container Container) export(path string) !

export podman to tgz

fn (Container) shell #

fn (mut container Container) shell(args BAHShellArgs) !

open shell to the container using podman, is interactive, cannot use in script

fn (Container) execute #

fn (mut container Container) execute(cmd_ string, silent bool) !

struct ContainerCreateArgs #

@[params]
struct ContainerCreateArgs {
	name             string
	hostname         string
	forwarded_ports  []string          // ["80:9000/tcp", "1000, 10000/udp"]
	mounted_volumes  []string          // ["/root:/root", ]
	env              map[string]string // map of environment variables that will be passed to the container
	privileged       bool
	remove_when_done bool = true // remove the container when it shuts down
pub mut:
	image_repo string
	image_tag  string
	command    string = '/bin/bash'
}

struct ContainerGetArgs #

@[params]
struct ContainerGetArgs {
pub mut:
	name     string
	id       string
	image_id string
	// tag    string
	// digest string
}

struct ContainerGetError #

struct ContainerGetError {
	Error
pub:
	args     ContainerGetArgs
	notfound bool
	toomany  bool
}

fn (ContainerGetError) msg #

fn (err ContainerGetError) msg() string

fn (ContainerGetError) code #

fn (err ContainerGetError) code() int

struct GetArgs #

@[params]
struct GetArgs {
	reset bool
}

struct Image #

@[heap]
struct Image {
pub mut:
	repo    string
	id      string
	id_full string
	tag     string
	digest  string
	size    int // size in MB
	created time.Time
	engine  &CEngine @[skip; str: skip]
}

fn (Image) delete #

fn (mut image Image) delete(force bool) !

delete podman image

fn (Image) export #

fn (mut image Image) export(path string) !string

export podman image to tar.gz

struct ImageGetArgs #

@[params]
struct ImageGetArgs {
pub:
	repo    string
	tag     string
	digest  string
	id      string
	id_full string
}

struct ImageGetError #

struct ImageGetError {
	Error
pub:
	args     ImageGetArgs
	notfound bool
	toomany  bool
}

struct NewArgs #

@[params]
struct NewArgs {
pub mut:
	install     bool = true
	reset       bool
	herocompile bool
}

struct PackageInstallArgs #

@[params]
struct PackageInstallArgs {
pub mut:
	names string
	// TODO:/..
}

struct RunArgs #

@[params]
struct RunArgs {
pub mut:
	cmd string
	// TODO:/..
}