WIP: Add progenitor client
Some checks failed
ci/woodpecker/pr/ci Pipeline failed

This commit is contained in:
Daniel Lundin 2024-12-14 22:47:40 +01:00
parent a4097b7cc3
commit 9b29a7fe9e
Signed by: dln
SSH key fingerprint: SHA256:dQy1Xj3UiqJYpKR5ggQ2bxgz4jCH8IF+k3AB8o0kmdI
12 changed files with 1883 additions and 38 deletions

967
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2,11 +2,13 @@
resolver = "2"
members = [
"agent",
"client",
"controller",
"xtask",
]
default-members = [
"agent",
"client",
"controller",
"xtask",
]
@ -36,9 +38,11 @@ opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "trace"] }
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }
opentelemetry-semantic-conventions = "0.27.0"
opentelemetry-stdout = "0.27.0"
progenitor = "0.8.0"
reqwest = { version = "0.12.9", features = ["json", "stream", "rustls-tls"] }
schemars = "0.8.21"
semver = "1.0.23"
serde = "1.0.215"
serde = { version = "1.0.215", features = ["derive"] }
slog = "2.7.0"
slog-async = "2.8.0"
tokio = { version = "1.41.1", features = ["full"] }
@ -53,3 +57,4 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
"env-filter",
"fmt",
] }
uuid = { version = "1", features = [ "serde", "v4" ] }

View file

@ -7,6 +7,7 @@ license = "MPL-2.0"
[dependencies]
anyhow.workspace = true
clap.workspace = true
patagia-client = { path = "../client" }
tokio.workspace = true
tracing.workspace = true
tracing-chrome.workspace = true

View file

@ -19,6 +19,11 @@ async fn main() -> Result<()> {
tracing::info!("Patagia Agent");
let client = patagia_client::Client::new("http://localhost:9474");
let result = client.version().await?;
tracing::info!("Result: {:?}", result);
sleep(Duration::from_secs(3)).await;
Ok(())
}

View file

@ -8,7 +8,7 @@
"/version": {
"get": {
"summary": "Fetch version info.",
"operationId": "api_version",
"operationId": "version",
"responses": {
"200": {
"description": "successful operation",

863
buildomat.json Normal file
View file

@ -0,0 +1,863 @@
{
"openapi": "3.0.3",
"info": {
"title": "Buildomat",
"version": "1.0"
},
"paths": {
"/v1/control/hold": {
"post": {
"operationId": "control_hold",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"enum": [
null
]
}
}
}
}
}
}
},
"/v1/control/resume": {
"post": {
"operationId": "control_resume",
"responses": {
"200": {
"description": "successful operation"
}
}
}
},
"/v1/task/{Task}": {
"get": {
"operationId": "task_get",
"parameters": [
{
"in": "path",
"name": "Task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/Task"
}
}
}
}
}
}
},
"/v1/tasks": {
"get": {
"operationId": "tasks_get",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"title": "Array_of_Task",
"type": "array",
"items": {
"$ref": "#/components/schemas/Task"
}
}
}
}
}
}
},
"post": {
"operationId": "task_submit",
"requestBody": {
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/TaskSubmit"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/TaskSubmitResult"
}
}
}
}
}
}
},
"/v1/tasks/{task}/events": {
"get": {
"operationId": "task_events_get",
"parameters": [
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
},
{
"in": "query",
"name": "minseq",
"schema": {
"type": "integer",
"format": "uint",
"minimum": 0
},
"style": "form"
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"title": "Array_of_TaskEvent",
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskEvent"
}
}
}
}
}
}
}
},
"/v1/tasks/{task}/outputs": {
"get": {
"operationId": "task_outputs_get",
"parameters": [
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"title": "Array_of_TaskOutput",
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskOutput"
}
}
}
}
}
}
}
},
"/v1/tasks/{task}/outputs/{output}": {
"get": {
"operationId": "task_output_download",
"parameters": [
{
"in": "path",
"name": "output",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
},
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"responses": {}
}
},
"/v1/users": {
"post": {
"operationId": "user_create",
"requestBody": {
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/UserCreate"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/UserCreateResult"
}
}
}
}
}
}
},
"/v1/whoami": {
"get": {
"operationId": "whoami",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WhoamiResult"
}
}
}
}
}
}
},
"/v1/whoami/name": {
"put": {
"operationId": "whoami_put_name",
"requestBody": {
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
},
"responses": {
"200": {
"description": "successful operation"
}
}
}
},
"/v1/worker/bootstrap": {
"post": {
"operationId": "worker_bootstrap",
"requestBody": {
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkerBootstrap"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkerBootstrapResult"
}
}
}
}
}
}
},
"/v1/worker/ping": {
"get": {
"operationId": "worker_ping",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkerPingResult"
}
}
}
}
}
}
},
"/v1/worker/task/{task}/append": {
"post": {
"operationId": "worker_task_append",
"parameters": [
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"requestBody": {
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkerAppendTask"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation"
}
}
}
},
"/v1/worker/task/{task}/chunk": {
"post": {
"operationId": "worker_task_upload_chunk",
"parameters": [
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"requestBody": {
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/UploadedChunk"
}
}
}
}
}
}
},
"/v1/worker/task/{task}/complete": {
"post": {
"operationId": "worker_task_complete",
"parameters": [
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"requestBody": {
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkerCompleteTask"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "successful operation"
}
}
}
},
"/v1/worker/task/{task}/output": {
"post": {
"operationId": "worker_task_add_output",
"parameters": [
{
"in": "path",
"name": "task",
"required": true,
"schema": {
"type": "string"
},
"style": "simple"
}
],
"requestBody": {
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkerAddOutput"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "successful creation"
}
}
}
},
"/v1/workers": {
"get": {
"operationId": "workers_list",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/WorkersResult"
}
}
}
}
}
}
},
"/v1/workers/recycle": {
"post": {
"operationId": "workers_recycle",
"responses": {
"200": {
"description": "successful operation"
}
}
}
}
},
"components": {
"schemas": {
"Task": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"output_rules": {
"type": "array",
"items": {
"type": "string"
}
},
"script": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"id",
"name",
"output_rules",
"script",
"state"
]
},
"TaskEvent": {
"type": "object",
"properties": {
"payload": {
"type": "string"
},
"seq": {
"type": "integer",
"format": "uint",
"minimum": 0
},
"stream": {
"type": "string"
},
"time": {
"type": "string",
"format": "date-time"
}
},
"required": [
"payload",
"seq",
"stream",
"time"
]
},
"TaskOutput": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"path": {
"type": "string"
},
"size": {
"type": "integer",
"format": "uint64",
"minimum": 0
}
},
"required": [
"id",
"path",
"size"
]
},
"TaskSubmit": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"output_rules": {
"type": "array",
"items": {
"type": "string"
}
},
"script": {
"type": "string"
}
},
"required": [
"name",
"script"
]
},
"TaskSubmitResult": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
]
},
"UploadedChunk": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
]
},
"UserCreate": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
},
"UserCreateResult": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"token": {
"type": "string"
}
},
"required": [
"id",
"name",
"token"
]
},
"WhoamiResult": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
]
},
"Worker": {
"type": "object",
"properties": {
"deleted": {
"type": "boolean"
},
"id": {
"type": "string"
},
"instance_id": {
"type": "string"
},
"lastping": {
"type": "string",
"format": "date-time"
},
"recycle": {
"type": "boolean"
},
"tasks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WorkerTask"
}
}
},
"required": [
"deleted",
"id",
"recycle",
"tasks"
]
},
"WorkerAddOutput": {
"type": "object",
"properties": {
"chunks": {
"type": "array",
"items": {
"type": "string"
}
},
"path": {
"type": "string"
},
"size": {
"type": "integer",
"format": "int64"
}
},
"required": [
"chunks",
"path",
"size"
]
},
"WorkerAppendTask": {
"type": "object",
"properties": {
"payload": {
"type": "string"
},
"stream": {
"type": "string"
},
"time": {
"type": "string",
"format": "date-time"
}
},
"required": [
"payload",
"stream",
"time"
]
},
"WorkerBootstrap": {
"type": "object",
"properties": {
"bootstrap": {
"type": "string"
},
"token": {
"type": "string"
}
},
"required": [
"bootstrap",
"token"
]
},
"WorkerBootstrapResult": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
]
},
"WorkerCompleteTask": {
"type": "object",
"properties": {
"failed": {
"type": "boolean"
}
},
"required": [
"failed"
]
},
"WorkerPingResult": {
"type": "object",
"properties": {
"poweroff": {
"type": "boolean"
},
"task": {
"$ref": "#/components/schemas/WorkerPingTask"
}
},
"required": [
"poweroff"
]
},
"WorkerPingTask": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"output_rules": {
"type": "array",
"items": {
"type": "string"
}
},
"script": {
"type": "string"
}
},
"required": [
"id",
"output_rules",
"script"
]
},
"WorkerTask": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"owner": {
"type": "string"
}
},
"required": [
"id",
"name",
"owner"
]
},
"WorkersResult": {
"type": "object",
"properties": {
"workers": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Worker"
}
}
},
"required": [
"workers"
]
},
"ObjWithOptionArray": {
"type": "object",
"properties": {
"things": {
"type": "array",
"items": {
"nullable": true,
"allOf": [
{
"$ref": "#/components/schemas/Task"
}
]
}
},
"stranger-things": {
"type": "array",
"items": {
"nullable": true,
"allOf": [
{
"$ref": "#/components/schemas/Task"
}
],
"oneOf": [
{}
]
}
}
},
"required": [
"things",
"stranger-things"
]
}
}
}
}

13
client/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "patagia-client"
version = "0.0.1"
license = "MPL-2.0"
edition = "2021"
[dependencies]
anyhow.workspace = true
progenitor.workspace = true
reqwest.workspace = true
schemars.workspace = true
serde.workspace = true
chrono = { version = "0.4.0", default-features = false, features = ["serde"] }

3
client/src/lib.rs Normal file
View file

@ -0,0 +1,3 @@
use progenitor::generate_api;
generate_api!(spec = "../api.json", derives = [schemars::JsonSchema],);

View file

@ -10,6 +10,6 @@ type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
pub fn api() -> Result<ControllerApiDescription> {
let mut api = ControllerApiDescription::new();
api.register(version::api_version)?;
api.register(version::version)?;
Ok(api)
}

View file

@ -29,7 +29,7 @@ struct VersionInfo {
),
err(Debug),
)]
pub async fn api_version(
pub(crate) async fn version(
rqctx: RequestContext<Arc<ControllerContext>>,
) -> Result<HttpResponseOk<VersionInfo>, HttpError> {
let ver = VersionInfo {

View file

@ -3,11 +3,11 @@
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1731808107,
"narHash": "sha256-HSx5EDsO07KULW4bNPVeGVAfpQqzwwS005vqISdOzNg=",
"lastModified": 1733749954,
"narHash": "sha256-2Ug80Uf/oUujxgh02Iy5vTG0V+Ab9+YUHuRLRY0ayiY=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "8e353a172f1baf11c0c917cfc9ae3c5eff8b9d06",
"rev": "ec9ce28714bb38d77a2223e7266df705500a7f11",
"type": "github"
},
"original": {
@ -18,11 +18,11 @@
},
"crane": {
"locked": {
"lastModified": 1731974733,
"narHash": "sha256-enYSSZVVl15FI5p+0Y5/Ckf5DZAvXe6fBrHxyhA/njc=",
"lastModified": 1733688869,
"narHash": "sha256-KrhxxFj1CjESDrL5+u/zsVH0K+Ik9tvoac/oFPoxSB8=",
"owner": "ipetkov",
"repo": "crane",
"rev": "3cb338ce81076ce5e461cf77f7824476addb0e1c",
"rev": "604637106e420ad99907cae401e13ab6b452e7d9",
"type": "github"
},
"original": {
@ -66,11 +66,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1731797254,
"narHash": "sha256-df3dJApLPhd11AlueuoN0Q4fHo/hagP75LlM5K1sz9g=",
"lastModified": 1734017764,
"narHash": "sha256-msOfmyJSjAHgIygI/JD0Ae3JsDv4rT54Nlfr5t6MQMQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"rev": "64e9404f308e0f0a0d8cdd7c358f74e34802494b",
"type": "github"
},
"original": {
@ -98,11 +98,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1731890469,
"narHash": "sha256-D1FNZ70NmQEwNxpSSdTXCSklBH1z2isPR84J6DQrJGs=",
"lastModified": 1733097829,
"narHash": "sha256-9hbb1rqGelllb4kVUCZ307G2k3/UhmA8PPGBoyuWaSw=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5083ec887760adfe12af64830a66807423a859a7",
"rev": "2c15aa59df0017ca140d9ba302412298ab4bf22a",
"type": "github"
},
"original": {
@ -128,11 +128,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1732328983,
"narHash": "sha256-RHt12f/slrzDpSL7SSkydh8wUE4Nr4r23HlpWywed9E=",
"lastModified": 1734143514,
"narHash": "sha256-1+r8wYucn8kp9d/IBW1uYGs31QQmSZURElsiOTx65xM=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "ed8aa5b64f7d36d9338eb1d0a3bb60cf52069a72",
"rev": "81fe5c27cb281a9b796d7ad05ad9179e5bd0c78d",
"type": "github"
},
"original": {
@ -161,11 +161,11 @@
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1732292307,
"narHash": "sha256-5WSng844vXt8uytT5djmqBCkopyle6ciFgteuA9bJpw=",
"lastModified": 1733761991,
"narHash": "sha256-s4DalCDepD22jtKL5Nw6f4LP5UwoMcPzPZgHWjAfqbQ=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "705df92694af7093dfbb27109ce16d828a79155f",
"rev": "0ce9d149d99bc383d1f2d85f31f6ebd146e46085",
"type": "github"
},
"original": {

View file

@ -49,6 +49,7 @@
nativeBuildInputs = with pkgs; [
clang_18
mold
openssl
];
sourceAndFixtures = path: type: (craneLib.filterCargoSources path type);
@ -156,11 +157,16 @@
);
openapi =
pkgs.runCommand "openapi" (commonArgs // {
src = fileSetForCrate ./xtask;
}) ''
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
'';
pkgs.runCommand "openapi"
(
commonArgs
// {
src = fileSetForCrate ./xtask;
}
)
''
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
'';
};
# For `nix fmt`
@ -179,11 +185,13 @@
cargo-watch
hyperfine
just
pkg-config
rust-dev-toolchain
watchexec
];
# RUST_BACKTRACE = 1;
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
shellHook = ''
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer
echo
echo " Welcome to the Patagia development environment! "
echo "Run 'just' to see available commands."