Skip to content

build #

Constants #

const (
	container_build_dir = '/build'
	build_image_repo    = 'vieter-build'
// Contents of PATH variable in build containers
	path_dirs           = ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin',
		'/usr/local/bin', '/usr/bin/site_perl', '/usr/bin/vendor_perl', '/usr/bin/core_perl']
)

fn build_target #

pub fn build_target(address string, api_key string, base_image_id string, target &Target, force bool, timeout int) !BuildResult

build_target builds the given target. Internally it calls build_config.

fn build_config #

pub fn build_config(address string, api_key string, config BuildConfig) !BuildResult

build_config builds, packages & publishes a given Arch package based on the provided target. The base image ID should be of an image previously created by create_build_image. It returns the logs of the container.

fn escape_shell_string #

fn escape_shell_string(s string) string

escape_shell_string escapes any characters that could be interpreted incorrectly by a shell. The resulting value should be safe to use inside an echo statement.

fn echo_commands #

pub fn echo_commands(cmds []string) []string

echo_commands takes a list of shell commands & prepends each one with an echo call displaying said command.

fn new_job_queue #

pub fn new_job_queue(default_schedule &cron.Expression, default_base_image string, default_build_timeout int) BuildJobQueue

new_job_queue initializes a new job queue

fn create_build_image #

pub fn create_build_image(base_image string) !string

create_build_image creates a builder image given some base image which can then be used to build & package Arch images. It mostly just updates the system, install some necessary packages & creates a non-root user to run makepkg with. The base image should be some Linux distribution that uses Pacman as its package manager.

fn create_build_script #

fn create_build_script(address string, config BuildConfig, build_arch string) string

create_build_script generates a shell script that builds a given Target.

struct BuildJobQueue #

pub struct BuildJobQueue {
// Schedule to use for targets without explicitely defined cron expression
	default_schedule &cron.Expression
// Base image to use for targets without defined base image
	default_base_image string
// After how many minutes a build should be forcefully cancelled
	default_build_timeout int
mut:
	mutex shared util.Dummy
// For each architecture, a priority queue is tracked
	queues map[string]MinHeap[BuildJob]
// When a target is removed from the server or edited, its previous build
// configs will be invalid. This map allows for those to be simply skipped
// by ignoring any build configs created before this timestamp.
	invalidated map[int]time.Time
}

The build job queue is responsible for managing the list of scheduled builds for each architecture. Agents receive jobs from this queue.

fn (BuildJobQueue) insert_all #

pub fn (mut q BuildJobQueue) insert_all(target Target) !

insert_all executes insert for each architecture of the given Target.

fn (BuildJobQueue) insert #

pub fn (mut q BuildJobQueue) insert(input InsertConfig) !

insert a new target's job into the queue for the given architecture. This job will then be endlessly rescheduled after being pop'ed, unless removed explicitely.

fn (BuildJobQueue) reschedule #

fn (mut q BuildJobQueue) reschedule(job BuildJob, arch string)

reschedule the given job by calculating the next timestamp and re-adding it to its respective queue. This function is called by the pop functions after having pop'ed the job.

fn (BuildJobQueue) pop_invalid #

fn (mut q BuildJobQueue) pop_invalid(arch string)

pop_invalid pops all invalid jobs.

fn (BuildJobQueue) peek #

pub fn (mut q BuildJobQueue) peek(arch string) ?BuildJob

peek shows the first job for the given architecture that's ready to be executed, if present.

fn (BuildJobQueue) pop #

pub fn (mut q BuildJobQueue) pop(arch string) ?BuildJob

pop removes the first job for the given architecture that's ready to be executed from the queue and returns it, if present.

fn (BuildJobQueue) pop_n #

pub fn (mut q BuildJobQueue) pop_n(arch string, n int) []BuildJob

pop_n tries to pop at most n available jobs for the given architecture.

fn (BuildJobQueue) invalidate #

pub fn (mut q BuildJobQueue) invalidate(target_id int)

invalidate a target's old build jobs.

struct BuildJob #

struct BuildJob {
pub mut:
// Time at which this build job was created/queued
	created time.Time
// Next timestamp from which point this job is allowed to be executed
	timestamp time.Time
// Required for calculating next timestamp after having pop'ed a job
	ce &cron.Expression = unsafe { nil }
// Actual build config sent to the agent
	config BuildConfig
// Whether this is a one-time job
	single bool
}

fn (BuildJob) < #

fn (r1 BuildJob) < (r2 BuildJob) bool

Allows BuildJob structs to be sorted according to their timestamp in MinHeaps

struct BuildResult #

pub struct BuildResult {
pub:
	start_time time.Time
	end_time   time.Time
	exit_code  int
	logs       string
}

struct InsertConfig #

[params]
pub struct InsertConfig {
	target Target [required]
	arch   string [required]
	single bool
	force  bool
	now    bool
}