Skip to content

agent #

Constants #

const log_file_name = 'vieter.agent.log'
const (
	build_empty   = 0
	build_running = 1
	build_done    = 2
)

fn agent_init #

fn agent_init(logger log.Log, conf Config) AgentDaemon

agent_init initializes a new agent

fn agent #

pub fn agent(conf Config) !

agent starts an agent service

fn cmd #

pub fn cmd() cli.Command

cmd returns the cli module that handles the cron daemon.

fn new_image_manager #

fn new_image_manager(max_image_age int) ImageManager

new_image_manager initializes a new image manager.

struct AgentDaemon #

struct AgentDaemon {
	logger shared log.Log
	conf   Config
	client client.Client
mut:
	images ImageManager
// Atomic variables used to detect when a build has finished; length is
// conf.max_concurrent_builds. This approach is used as the difference
// between a recently finished build and an empty build slot is important
// for knowing whether the agent is currently "active".
	atomics []u64
// Channel used to send builds to worker threads
	build_channel chan BuildConfig
}

fn (AgentDaemon) builder_thread #

fn (mut d AgentDaemon) builder_thread(ch chan BuildConfig, builder_index int)

builder_thread is a thread that constantly listens for builds to process

fn (AgentDaemon) ldebug #

pub fn (mut d AgentDaemon) ldebug(msg string)

ldebug create a log message with the debug level

fn (AgentDaemon) lerror #

pub fn (mut d AgentDaemon) lerror(msg string)

lerror create a log message with the error level

fn (AgentDaemon) lfatal #

pub fn (mut d AgentDaemon) lfatal(msg string)

lfatal create a log message with the fatal level

fn (AgentDaemon) linfo #

pub fn (mut d AgentDaemon) linfo(msg string)

linfo create a log message with the info level

fn (AgentDaemon) lwarn #

pub fn (mut d AgentDaemon) lwarn(msg string)

lwarn create a log message with the warn level

fn (AgentDaemon) run #

pub fn (mut d AgentDaemon) run()

run starts the actual agent daemon. This function will run forever.

fn (AgentDaemon) run_build #

fn (mut d AgentDaemon) run_build(build_index int, config BuildConfig)

run_build actually starts the build process for a given target.

fn (AgentDaemon) update_atomics #

fn (mut d AgentDaemon) update_atomics() (int, int)

update_atomics checks for each build whether it's completed, and sets it to empty again if so. The return value is a tuple (finished, empty) where finished is how many builds were just finished and thus set to empty, and empty is how many build slots were already empty. The amount of running builds can then be calculated by substracting these two values from the total allowed concurrent builds.

struct Config #

struct Config {
pub:
	log_level string = 'WARN'
// Architecture that the agent represents
	arch                    string
	api_key                 string
	address                 string
	data_dir                string
	max_concurrent_builds   int = 1
	polling_frequency       int = 30
	image_rebuild_frequency int = 1440
}

struct ImageManager #

struct ImageManager {
	max_image_age int [required]
mut:
// For each base image, one or more builder images can exist at the same
// time
	images map[string][]string [required]
// For each base image, we track when its newest image was built
	timestamps map[string]time.Time [required]
}

An ImageManager is a utility that creates builder images from given base images, updating these builder images if they've become too old. This structure can manage images from any number of base images, paving the way for configurable base images per target/repository.

fn (ImageManager) get #

pub fn (m &ImageManager) get(base_image string) string

get returns the name of the newest image for the given base image. Note that this function should only be called after a first call to refresh_image.

fn (ImageManager) up_to_date #

pub fn (mut m ImageManager) up_to_date(base_image string) bool

up_to_date returns true if the last known builder image exists and is up to date. If this function returns true, the last builder image may be used to perform a build.

fn (ImageManager) refresh_image #

fn (mut m ImageManager) refresh_image(base_image string) !

refresh_image builds a new builder image from the given base image. This function should only be called if up_to_date returned false.

fn (ImageManager) clean_old_images #

fn (mut m ImageManager) clean_old_images()

clean_old_images removes all older builder images that are no longer in use.
The function will always leave at least one builder image, namely the newest one.