Skip to main content

xbp_deploy/
oci_build.rs

1//! Optional OCI image build/push adapter (CLI injects docker buildx).
2
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5use std::path::PathBuf;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct OciBuildRequest {
9    pub service: String,
10    /// Full image reference including tag (e.g. `ghcr.io/org/app:1.2.3`).
11    pub image_ref: String,
12    pub dockerfile: Option<String>,
13    /// Build context directory (absolute or relative to project root; adapter resolves).
14    pub context: PathBuf,
15    pub platforms: Vec<String>,
16    pub dry_run: bool,
17    pub project_root: PathBuf,
18    pub service_root: Option<PathBuf>,
19    /// When true, build into the local Docker engine only (`docker build` /
20    /// `buildx --load`) and **do not** push to a remote registry.
21    #[serde(default)]
22    pub local_image: bool,
23}
24
25/// Result of a successful (or dry-run) build/push.
26#[derive(Debug, Clone, Serialize, Deserialize, Default)]
27pub struct OciBuildResult {
28    pub lines: Vec<String>,
29    /// Registry digest after push (`sha256:…`) when known.
30    pub digest: Option<String>,
31    /// Image reference best used for deploy (digest form when available).
32    pub image_ref: Option<String>,
33    /// True when the image was only loaded locally (no registry push).
34    #[serde(default)]
35    pub local_only: bool,
36}
37
38/// Build and push (or load locally) service images before apply/rollout.
39#[async_trait]
40pub trait OciBuildAdapter: Send + Sync {
41    async fn build_and_push(&self, request: OciBuildRequest) -> Result<OciBuildResult, String>;
42}