2022-06-14 20:38:20 +02:00
|
|
|
module targets
|
2022-05-16 17:12:37 +02:00
|
|
|
|
|
|
|
import client
|
2022-06-22 09:18:47 +02:00
|
|
|
import vieter_v.docker
|
2022-05-16 17:12:37 +02:00
|
|
|
import os
|
|
|
|
import build
|
|
|
|
|
2022-06-14 20:38:20 +02:00
|
|
|
// build locally builds the target with the given id.
|
2022-06-17 16:23:47 +02:00
|
|
|
fn build(conf Config, target_id int) ? {
|
2022-05-16 17:12:37 +02:00
|
|
|
c := client.new(conf.address, conf.api_key)
|
2022-06-17 16:23:47 +02:00
|
|
|
target := c.get_target(target_id)?
|
2022-05-16 17:12:37 +02:00
|
|
|
|
|
|
|
build_arch := os.uname().machine
|
|
|
|
|
|
|
|
println('Creating base image...')
|
|
|
|
image_id := build.create_build_image(conf.base_image)?
|
|
|
|
|
|
|
|
println('Running build...')
|
2022-06-17 16:23:47 +02:00
|
|
|
res := build.build_target(conf.address, conf.api_key, image_id, target)?
|
2022-05-16 17:12:37 +02:00
|
|
|
|
|
|
|
println('Removing build image...')
|
|
|
|
|
|
|
|
mut dd := docker.new_conn()?
|
|
|
|
|
|
|
|
defer {
|
|
|
|
dd.close() or {}
|
|
|
|
}
|
|
|
|
|
|
|
|
dd.remove_image(image_id)?
|
|
|
|
|
|
|
|
println('Uploading logs to Vieter...')
|
2022-06-17 16:23:47 +02:00
|
|
|
c.add_build_log(target.id, res.start_time, res.end_time, build_arch, res.exit_code,
|
2022-05-16 17:12:37 +02:00
|
|
|
res.logs)?
|
|
|
|
}
|