From 402fef475a8e036c9db2bf84cdfd7556cb6f2093 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 16 Dec 2022 20:38:26 +0100 Subject: [PATCH] fix: actually use path setting when building --- src/agent/daemon.v | 3 ++- src/build/build.v | 30 ++---------------------------- src/build/queue.v | 13 ++----------- src/build/shell.v | 2 ++ src/build/shell_test.v | 2 ++ src/client/jobs.v | 2 +- src/models/builds.v | 18 ++++++++++++++++++ src/models/targets.v | 15 +++++++++++++++ 8 files changed, 44 insertions(+), 41 deletions(-) create mode 100644 src/models/builds.v diff --git a/src/agent/daemon.v b/src/agent/daemon.v index 8fa3816..c55d0db 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 c6aa7f1..712c93b 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 7902173..e74529c 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 c459a99..16f93b5 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 e44c5ff..e23d964 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 a545499..784639e 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 0000000..926a53c --- /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 cb60650..af3cb0d 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: