diff --git a/src/agent/daemon.v b/src/agent/daemon.v index 8fa38166..c55d0db9 100644 --- a/src/agent/daemon.v +++ b/src/agent/daemon.v @@ -2,7 +2,8 @@ module agent import log import sync.stdatomic -import build { BuildConfig } +import build +import models { BuildConfig } import client import time import os diff --git a/src/build/build.v b/src/build/build.v index c6aa7f11..712c93b3 100644 --- a/src/build/build.v +++ b/src/build/build.v @@ -6,7 +6,7 @@ import time import os import strings import util -import models { Target } +import models { BuildConfig, Target } const ( container_build_dir = '/build' @@ -16,23 +16,6 @@ const ( '/usr/local/bin', '/usr/bin/site_perl', '/usr/bin/vendor_perl', '/usr/bin/core_perl'] ) -pub struct BuildConfig { -pub: - target_id int - kind string - url string - branch string - path string - repo string - base_image string - force bool -} - -// str return a single-line string representation of a build log -pub fn (c BuildConfig) str() string { - return '{ target: $c.target_id, kind: $c.kind, url: $c.url, branch: $c.branch, path: $c.path, repo: $c.repo, base_image: $c.base_image, force: $c.force }' -} - // 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 @@ -112,16 +95,7 @@ pub: // build_target builds the given target. Internally it calls `build_config`. pub fn build_target(address string, api_key string, base_image_id string, target &Target, force bool) !BuildResult { - config := BuildConfig{ - target_id: target.id - kind: target.kind - url: target.url - branch: target.branch - path: target.path - repo: target.repo - base_image: base_image_id - force: force - } + config := target.as_build_config(base_image_id, force) return build_config(address, api_key, config) } diff --git a/src/build/queue.v b/src/build/queue.v index 79021730..e74529ca 100644 --- a/src/build/queue.v +++ b/src/build/queue.v @@ -1,6 +1,6 @@ module build -import models { Target } +import models { BuildConfig, Target } import cron.expression { CronExpression, parse_expression } import time import datatypes { MinHeap } @@ -80,16 +80,7 @@ pub fn (mut q BuildJobQueue) insert(input InsertConfig) ! { mut job := BuildJob{ created: time.now() single: input.single - config: BuildConfig{ - target_id: input.target.id - kind: input.target.kind - url: input.target.url - branch: input.target.branch - repo: input.target.repo - // TODO make this configurable - base_image: q.default_base_image - force: input.force - } + config: input.target.as_build_config(q.default_base_image, input.force) } if !input.now { diff --git a/src/build/shell.v b/src/build/shell.v index c459a993..16f93b54 100644 --- a/src/build/shell.v +++ b/src/build/shell.v @@ -1,5 +1,7 @@ module build +import models { BuildConfig } + // 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. diff --git a/src/build/shell_test.v b/src/build/shell_test.v index e44c5ff1..e23d964d 100644 --- a/src/build/shell_test.v +++ b/src/build/shell_test.v @@ -1,5 +1,7 @@ module build +import models { BuildConfig } + fn test_create_build_script_git() { config := BuildConfig{ target_id: 1 diff --git a/src/client/jobs.v b/src/client/jobs.v index a545499b..784639e2 100644 --- a/src/client/jobs.v +++ b/src/client/jobs.v @@ -1,6 +1,6 @@ module client -import build { BuildConfig } +import models { BuildConfig } // poll_jobs requests a list of new build jobs from the server. pub fn (c &Client) poll_jobs(arch string, max int) ![]BuildConfig { diff --git a/src/models/builds.v b/src/models/builds.v new file mode 100644 index 00000000..926a53c2 --- /dev/null +++ b/src/models/builds.v @@ -0,0 +1,18 @@ +module models + +pub struct BuildConfig { +pub: + target_id int + kind string + url string + branch string + path string + repo string + base_image string + force bool +} + +// str return a single-line string representation of a build log +pub fn (c BuildConfig) str() string { + return '{ target: $c.target_id, kind: $c.kind, url: $c.url, branch: $c.branch, path: $c.path, repo: $c.repo, base_image: $c.base_image, force: $c.force }' +} diff --git a/src/models/targets.v b/src/models/targets.v index cb60650c..af3cb0df 100644 --- a/src/models/targets.v +++ b/src/models/targets.v @@ -52,6 +52,21 @@ pub fn (t &Target) str() string { return str } +// as_build_config converts a Target into a BuildConfig, given some extra +// needed information. +pub fn (t &Target) as_build_config(base_image string, force bool) BuildConfig { + return BuildConfig{ + target_id: t.id + kind: t.kind + url: t.url + branch: t.branch + path: t.path + repo: t.repo + base_image: base_image + force: force + } +} + [params] pub struct TargetFilter { pub mut: