feat: add option to force-build package
parent
8a2f720bdf
commit
f6c5e7c246
|
@ -24,6 +24,7 @@ pub:
|
||||||
branch string
|
branch string
|
||||||
repo string
|
repo string
|
||||||
base_image string
|
base_image string
|
||||||
|
force bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_build_image creates a builder image given some base image which can
|
// create_build_image creates a builder image given some base image which can
|
||||||
|
@ -104,7 +105,7 @@ pub:
|
||||||
}
|
}
|
||||||
|
|
||||||
// build_target builds the given target. Internally it calls `build_config`.
|
// 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) !BuildResult {
|
pub fn build_target(address string, api_key string, base_image_id string, target &Target, force bool) !BuildResult {
|
||||||
config := BuildConfig{
|
config := BuildConfig{
|
||||||
target_id: target.id
|
target_id: target.id
|
||||||
kind: target.kind
|
kind: target.kind
|
||||||
|
@ -112,6 +113,7 @@ pub fn build_target(address string, api_key string, base_image_id string, target
|
||||||
branch: target.branch
|
branch: target.branch
|
||||||
repo: target.repo
|
repo: target.repo
|
||||||
base_image: base_image_id
|
base_image: base_image_id
|
||||||
|
force: force
|
||||||
}
|
}
|
||||||
|
|
||||||
return build_config(address, api_key, config)
|
return build_config(address, api_key, config)
|
||||||
|
|
|
@ -63,14 +63,22 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
|
||||||
'cd repo',
|
'cd repo',
|
||||||
'makepkg --nobuild --syncdeps --needed --noconfirm',
|
'makepkg --nobuild --syncdeps --needed --noconfirm',
|
||||||
'source PKGBUILD',
|
'source PKGBUILD',
|
||||||
|
]
|
||||||
|
|
||||||
|
if !config.force {
|
||||||
// The build container checks whether the package is already present on
|
// The build container checks whether the package is already present on
|
||||||
// the server.
|
// the server.
|
||||||
|
commands << [
|
||||||
'curl -s --head --fail $repo_url/$build_arch/\$pkgname-\$pkgver-\$pkgrel && exit 0',
|
'curl -s --head --fail $repo_url/$build_arch/\$pkgname-\$pkgver-\$pkgrel && exit 0',
|
||||||
// If the above curl command succeeds, we don't need to rebuild the
|
// If the above curl command succeeds, we don't need to rebuild the
|
||||||
// package. However, because we're in a su shell, the exit command will
|
// package. However, because we're in a su shell, the exit command will
|
||||||
// drop us back into the root shell. Therefore, we must check whether
|
// drop us back into the root shell. Therefore, we must check whether
|
||||||
// we're in root so we don't proceed.
|
// we're in root so we don't proceed.
|
||||||
'[ "\$(id -u)" == 0 ] && exit 0',
|
'[ "\$(id -u)" == 0 ] && exit 0',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
commands << [
|
||||||
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $repo_url/publish; done',
|
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $repo_url/publish; done',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import os
|
||||||
import build
|
import build
|
||||||
|
|
||||||
// build locally builds the target with the given id.
|
// build locally builds the target with the given id.
|
||||||
fn build(conf Config, target_id int) ! {
|
fn build(conf Config, target_id int, force bool) ! {
|
||||||
c := client.new(conf.address, conf.api_key)
|
c := client.new(conf.address, conf.api_key)
|
||||||
target := c.get_target(target_id)!
|
target := c.get_target(target_id)!
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ fn build(conf Config, target_id int) ! {
|
||||||
image_id := build.create_build_image(conf.base_image)!
|
image_id := build.create_build_image(conf.base_image)!
|
||||||
|
|
||||||
println('Running build...')
|
println('Running build...')
|
||||||
res := build.build_target(conf.address, conf.api_key, image_id, target)!
|
res := build.build_target(conf.address, conf.api_key, image_id, target, force)!
|
||||||
|
|
||||||
println('Removing build image...')
|
println('Removing build image...')
|
||||||
|
|
||||||
|
|
|
@ -182,11 +182,18 @@ pub fn cmd() cli.Command {
|
||||||
required_args: 1
|
required_args: 1
|
||||||
usage: 'id'
|
usage: 'id'
|
||||||
description: 'Build the target with the given id & publish it.'
|
description: 'Build the target with the given id & publish it.'
|
||||||
|
flags: [
|
||||||
|
cli.Flag{
|
||||||
|
name: 'force'
|
||||||
|
description: 'Build the target without checking whether it needs to be renewed.'
|
||||||
|
flag: cli.FlagType.bool
|
||||||
|
},
|
||||||
|
]
|
||||||
execute: fn (cmd cli.Command) ! {
|
execute: fn (cmd cli.Command) ! {
|
||||||
config_file := cmd.flags.get_string('config-file')!
|
config_file := cmd.flags.get_string('config-file')!
|
||||||
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
|
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
|
||||||
|
|
||||||
build(conf, cmd.args[0].int())!
|
build(conf, cmd.args[0].int(), cmd.flags.get_bool('force')!)!
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -79,7 +79,7 @@ fn (mut d Daemon) run_build(build_index int, sb ScheduledBuild) {
|
||||||
mut status := 0
|
mut status := 0
|
||||||
|
|
||||||
res := build.build_target(d.client.address, d.client.api_key, d.builder_images.last(),
|
res := build.build_target(d.client.address, d.client.api_key, d.builder_images.last(),
|
||||||
&sb.target) or {
|
&sb.target, false) or {
|
||||||
d.ldebug('build_target error: $err.msg()')
|
d.ldebug('build_target error: $err.msg()')
|
||||||
status = 1
|
status = 1
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ arch = "x86_64"
|
||||||
|
|
||||||
address = "http://localhost:8000"
|
address = "http://localhost:8000"
|
||||||
|
|
||||||
global_schedule = '* *'
|
# global_schedule = '* *'
|
||||||
api_update_frequency = 2
|
api_update_frequency = 2
|
||||||
image_rebuild_frequency = 1
|
image_rebuild_frequency = 1
|
||||||
max_concurrent_builds = 3
|
max_concurrent_builds = 3
|
||||||
|
|
Loading…
Reference in New Issue