feat(agent): partially wrote daemon code

This commit is contained in:
Jef Roosens 2022-12-12 22:09:57 +01:00 committed by Chewing_Bever
parent 7ef8d4b846
commit 6f23d690a7
Signed by untrusted user: Jef Roosens
GPG key ID: B75D4F293C7052DB
6 changed files with 116 additions and 13 deletions

View file

@ -103,10 +103,23 @@ pub:
logs string
}
pub fn build_target(address string, api_key string, base_image_id string, target &Target) !BuildResult {
config := BuildConfig{
target_id: target.id
kind: target.kind
url: target.url
branch: target.branch
repo: target.repo
base_image: base_image_id
}
return build_config(address, api_key, config)
}
// build_target 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.
pub fn build_target(address string, api_key string, base_image_id string, target &Target) !BuildResult {
pub fn build_config(address string, api_key string, config BuildConfig) !BuildResult {
mut dd := docker.new_conn()!
defer {
@ -114,14 +127,14 @@ pub fn build_target(address string, api_key string, base_image_id string, target
}
build_arch := os.uname().machine
build_script := create_build_script(address, target, build_arch)
build_script := create_build_script(address, config, build_arch)
// We convert the build script into a base64 string, which then gets passed
// to the container as an env var
base64_script := base64.encode_str(build_script)
c := docker.NewContainer{
image: '$base_image_id'
image: '$config.base_image'
env: [
'BUILD_SCRIPT=$base64_script',
'API_KEY=$api_key',

View file

@ -23,13 +23,13 @@ pub fn echo_commands(cmds []string) []string {
}
// create_build_script generates a shell script that builds a given Target.
fn create_build_script(address string, target &Target, build_arch string) string {
repo_url := '$address/$target.repo'
fn create_build_script(address string, config BuildConfig, build_arch string) string {
repo_url := '$address/$config.repo'
mut commands := [
// This will later be replaced by a proper setting for changing the
// mirrorlist
"echo -e '[$target.repo]\\nServer = $address/\$repo/\$arch\\nSigLevel = Optional' >> /etc/pacman.conf"
"echo -e '[$config.repo]\\nServer = $address/\$repo/\$arch\\nSigLevel = Optional' >> /etc/pacman.conf"
// We need to update the package list of the repo we just added above.
// This should however not pull in a lot of packages as long as the
// builder image is rebuilt frequently.
@ -38,22 +38,22 @@ fn create_build_script(address string, target &Target, build_arch string) string
'su builder',
]
commands << match target.kind {
commands << match config.kind {
'git' {
if target.branch == '' {
if config.branch == '' {
[
"git clone --single-branch --depth 1 '$target.url' repo",
"git clone --single-branch --depth 1 '$config.url' repo",
]
} else {
[
"git clone --single-branch --depth 1 --branch $target.branch '$target.url' repo",
"git clone --single-branch --depth 1 --branch $config.branch '$config.url' repo",
]
}
}
'url' {
[
'mkdir repo',
"curl -o repo/PKGBUILD -L '$target.url'",
"curl -o repo/PKGBUILD -L '$config.url'",
]
}
else {