forked from vieter-v/vieter
Compare commits
3 Commits
9d8491a77a
...
d11ad78bff
| Author | SHA1 | Date |
|---|---|---|
|
|
d11ad78bff | |
|
|
8ecac2ff28 | |
|
|
7eab7afa98 |
|
|
@ -3,10 +3,10 @@ branches: [dev]
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
build:
|
build:
|
||||||
image: 'archlinux:latest'
|
image: 'archlinux:base-devel'
|
||||||
commands:
|
commands:
|
||||||
# Update packages
|
# Update packages
|
||||||
- pacman -Syu --needed --noconfirm base-devel
|
- pacman -Syu
|
||||||
# Create non-root user to perform build & switch to their home
|
# Create non-root user to perform build & switch to their home
|
||||||
- groupadd -g 1000 builder
|
- groupadd -g 1000 builder
|
||||||
- useradd -mg builder builder
|
- useradd -mg builder builder
|
||||||
|
|
@ -17,9 +17,9 @@ pipeline:
|
||||||
- makepkg -s --noconfirm --needed
|
- makepkg -s --noconfirm --needed
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
image: 'archlinux:latest'
|
image: 'curlimages/curl:latest'
|
||||||
commands:
|
commands:
|
||||||
# Publish the package
|
# Publish the package
|
||||||
- 'for pkg in $(ls -1 *.pkg*); do curl -XPOST -T "$pkg" -H "X-API-KEY: $VIETER_API_KEY" https://arch.r8r.be/publish; done'
|
- 'for pkg in $(ls -1 *.pkg*); do curl -XPOST -T "$pkg" -H "X-API-KEY: $VIETER_API_KEY" https://arch.r8r.be/vieter/publish; done'
|
||||||
secrets:
|
secrets:
|
||||||
- vieter_api_key
|
- vieter_api_key
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,14 @@ import docker
|
||||||
import encoding.base64
|
import encoding.base64
|
||||||
import time
|
import time
|
||||||
import git
|
import git
|
||||||
|
import os
|
||||||
|
|
||||||
const container_build_dir = '/build'
|
const container_build_dir = '/build'
|
||||||
|
|
||||||
const build_image_repo = 'vieter-build'
|
const build_image_repo = 'vieter-build'
|
||||||
|
|
||||||
|
const base_image = 'archlinux:latest'
|
||||||
|
|
||||||
fn create_build_image() ?string {
|
fn create_build_image() ?string {
|
||||||
commands := [
|
commands := [
|
||||||
// Update repos & install required packages
|
// Update repos & install required packages
|
||||||
|
|
@ -26,7 +29,7 @@ fn create_build_image() ?string {
|
||||||
cmds_str := base64.encode_str(commands.join('\n'))
|
cmds_str := base64.encode_str(commands.join('\n'))
|
||||||
|
|
||||||
c := docker.NewContainer{
|
c := docker.NewContainer{
|
||||||
image: 'archlinux:latest'
|
image: base_image
|
||||||
env: ['BUILD_SCRIPT=$cmds_str']
|
env: ['BUILD_SCRIPT=$cmds_str']
|
||||||
entrypoint: ['/bin/sh', '-c']
|
entrypoint: ['/bin/sh', '-c']
|
||||||
cmd: ['echo \$BUILD_SCRIPT | base64 -d | /bin/sh -e']
|
cmd: ['echo \$BUILD_SCRIPT | base64 -d | /bin/sh -e']
|
||||||
|
|
@ -60,27 +63,34 @@ fn create_build_image() ?string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(conf Config) ? {
|
fn build(conf Config) ? {
|
||||||
// We get the repos list from the Vieter instance
|
build_arch := os.uname().machine
|
||||||
repos := git.get_repos(conf.address, conf.api_key) ?
|
|
||||||
|
// We get the repos map from the Vieter instance
|
||||||
|
repos_map := git.get_repos(conf.address, conf.api_key) ?
|
||||||
|
|
||||||
|
// We filter out any repos that aren't allowed to be built on this
|
||||||
|
// architecture
|
||||||
|
filtered_repos := repos_map.keys().map(repos_map[it]).filter(it.arch.contains(build_arch))
|
||||||
|
|
||||||
// No point in doing work if there's no repos present
|
// No point in doing work if there's no repos present
|
||||||
if repos.len == 0 {
|
if filtered_repos.len == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we create a base image which has updated repos n stuff
|
// First, we create a base image which has updated repos n stuff
|
||||||
image_id := create_build_image() ?
|
image_id := create_build_image() ?
|
||||||
|
|
||||||
for _, repo in repos {
|
for repo in filtered_repos {
|
||||||
// TODO what to do with PKGBUILDs that build multiple packages?
|
// TODO what to do with PKGBUILDs that build multiple packages?
|
||||||
commands := [
|
commands := [
|
||||||
'git clone --single-branch --depth 1 --branch $repo.branch $repo.url repo',
|
'git clone --single-branch --depth 1 --branch $repo.branch $repo.url repo',
|
||||||
'cd repo',
|
'cd repo',
|
||||||
'makepkg --nobuild --nodeps',
|
'makepkg --nobuild --nodeps',
|
||||||
'source PKGBUILD',
|
'source PKGBUILD',
|
||||||
// The build container checks whether the package is already present on the server
|
// The build container checks whether the package is already
|
||||||
'curl --head --fail $conf.address/\$pkgname-\$pkgver-\$pkgrel-\$(uname -m).pkg.tar.zst && exit 0',
|
// present on the server
|
||||||
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $conf.address/publish; done',
|
'curl --head --fail $conf.address/$repo.repo/$build_arch/\$pkgname-\$pkgver-\$pkgrel-${build_arch}.pkg.tar.zst && exit 0',
|
||||||
|
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $conf.address/$repo.repo/publish; done',
|
||||||
]
|
]
|
||||||
|
|
||||||
// We convert the list of commands into a base64 string, which then gets
|
// We convert the list of commands into a base64 string, which then gets
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,14 @@ pub fn cmd() cli.Command {
|
||||||
},
|
},
|
||||||
cli.Command{
|
cli.Command{
|
||||||
name: 'add'
|
name: 'add'
|
||||||
required_args: 2
|
required_args: 4
|
||||||
usage: 'url branch arch...'
|
usage: 'url branch repo arch...'
|
||||||
description: 'Add a new repository.'
|
description: 'Add a new repository.'
|
||||||
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 := env.load<Config>(config_file) ?
|
conf := env.load<Config>(config_file) ?
|
||||||
|
|
||||||
add(conf, cmd.args[0], cmd.args[1], cmd.args[2..]) ?
|
add(conf, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3..]) ?
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cli.Command{
|
cli.Command{
|
||||||
|
|
@ -56,12 +56,12 @@ fn list(conf Config) ? {
|
||||||
repos := get_repos(conf.address, conf.api_key) ?
|
repos := get_repos(conf.address, conf.api_key) ?
|
||||||
|
|
||||||
for id, details in repos {
|
for id, details in repos {
|
||||||
println('${id[..8]}\t$details.url\t$details.branch\t$details.arch')
|
println('${id[..8]}\t$details.url\t$details.branch\t$details.repo\t$details.arch')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add(conf Config, url string, branch string, arch []string) ? {
|
fn add(conf Config, url string, branch string, repo string, arch []string) ? {
|
||||||
res := add_repo(conf.address, conf.api_key, url, branch, arch) ?
|
res := add_repo(conf.address, conf.api_key, url, branch, repo, arch) ?
|
||||||
|
|
||||||
println(res.message)
|
println(res.message)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,36 +4,47 @@ import json
|
||||||
import response { Response }
|
import response { Response }
|
||||||
import net.http
|
import net.http
|
||||||
|
|
||||||
// get_repos returns the current list of repos.
|
fn send_request<T>(method http.Method, address string, url string, api_key string, params map[string]string) ?Response<T> {
|
||||||
pub fn get_repos(address string, api_key string) ?map[string]GitRepo {
|
mut full_url := '$address$url'
|
||||||
mut req := http.new_request(http.Method.get, '$address/api/repos', '') ?
|
|
||||||
|
if params.len > 0 {
|
||||||
|
params_str := params.keys().map('$it=${params[it]}').join('&')
|
||||||
|
|
||||||
|
full_url = "$full_url?$params_str"
|
||||||
|
}
|
||||||
|
|
||||||
|
mut req := http.new_request(method, full_url, '') ?
|
||||||
req.add_custom_header('X-API-Key', api_key) ?
|
req.add_custom_header('X-API-Key', api_key) ?
|
||||||
|
|
||||||
res := req.do() ?
|
res := req.do() ?
|
||||||
data := json.decode(Response<map[string]GitRepo>, res.text) ?
|
data := json.decode(Response<T>, res.text) ?
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
// get_repos returns the current list of repos.
|
||||||
|
pub fn get_repos(address string, api_key string) ?map[string]GitRepo {
|
||||||
|
data := send_request<map[string]GitRepo>(http.Method.get, address, '/api/repos', api_key, {}) ?
|
||||||
|
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
// add_repo adds a new repo to the server.
|
// add_repo adds a new repo to the server.
|
||||||
pub fn add_repo(address string, api_key string, url string, branch string, arch []string) ?Response<string> {
|
pub fn add_repo(address string, api_key string, url string, branch string, repo string, arch []string) ?Response<string> {
|
||||||
mut req := http.new_request(http.Method.post, '$address/api/repos?url=$url&branch=$branch&arch=${arch.join(',')}',
|
params := {
|
||||||
'') ?
|
'url': url
|
||||||
req.add_custom_header('X-API-Key', api_key) ?
|
'branch': branch
|
||||||
|
'repo': repo
|
||||||
res := req.do() ?
|
'arch': arch.join(',')
|
||||||
data := json.decode(Response<string>, res.text) ?
|
}
|
||||||
|
data := send_request<string>(http.Method.post, address, '/api/repos', api_key, params) ?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove_repo removes the repo with the given ID from the server.
|
// remove_repo removes the repo with the given ID from the server.
|
||||||
pub fn remove_repo(address string, api_key string, id string) ?Response<string> {
|
pub fn remove_repo(address string, api_key string, id string) ?Response<string> {
|
||||||
mut req := http.new_request(http.Method.delete, '$address/api/repos/$id', '') ?
|
data := send_request<string>(http.Method.delete, address, '/api/repos/$id', api_key, {}) ?
|
||||||
req.add_custom_header('X-API-Key', api_key) ?
|
|
||||||
|
|
||||||
res := req.do() ?
|
|
||||||
data := json.decode(Response<string>, res.text) ?
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ pub mut:
|
||||||
// On which architectures the package is allowed to be built. In reality,
|
// On which architectures the package is allowed to be built. In reality,
|
||||||
// this controls which builders will periodically build the image.
|
// this controls which builders will periodically build the image.
|
||||||
arch []string
|
arch []string
|
||||||
|
// Which repo the builder should publish packages to
|
||||||
|
repo string
|
||||||
}
|
}
|
||||||
|
|
||||||
// patch_from_params patches a GitRepo from a map[string]string, usually
|
// patch_from_params patches a GitRepo from a map[string]string, usually
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue