Skip to main content

zlayer_types/api/
build.rs

1//! Build API DTOs.
2//!
3//! Wire types for the build endpoints. These are the request/response
4//! shapes consumed by both the daemon and SDK clients.
5
6use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9
10/// Build request for JSON API
11#[derive(Debug, Default, Deserialize, utoipa::ToSchema)]
12pub struct BuildRequest {
13    /// Use runtime template instead of Dockerfile
14    #[serde(default)]
15    pub runtime: Option<String>,
16    /// Build arguments (ARG values)
17    #[serde(default)]
18    pub build_args: HashMap<String, String>,
19    /// Target stage for multi-stage builds
20    #[serde(default)]
21    pub target: Option<String>,
22    /// Tags to apply to the image
23    #[serde(default)]
24    pub tags: Vec<String>,
25    /// Disable cache
26    #[serde(default)]
27    pub no_cache: bool,
28    /// Push to registry after build
29    #[serde(default)]
30    pub push: bool,
31}
32
33/// Build status response
34#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
35pub struct BuildStatus {
36    /// Unique build ID
37    pub id: String,
38    /// Current build status
39    pub status: BuildStateEnum,
40    /// Image ID (if completed)
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub image_id: Option<String>,
43    /// Error message (if failed)
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub error: Option<String>,
46    /// When the build started (ISO 8601)
47    pub started_at: String,
48    /// When the build completed (ISO 8601)
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub completed_at: Option<String>,
51}
52
53/// Build state enumeration
54#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, utoipa::ToSchema)]
55#[serde(rename_all = "snake_case")]
56pub enum BuildStateEnum {
57    /// Build is queued
58    Pending,
59    /// Build is running
60    Running,
61    /// Build completed successfully
62    Complete,
63    /// Build failed
64    Failed,
65}
66
67/// Runtime template information
68#[derive(Debug, Serialize, utoipa::ToSchema)]
69pub struct TemplateInfo {
70    /// Template name (e.g., "node20")
71    pub name: String,
72    /// Human-readable description
73    pub description: String,
74    /// Files that indicate this runtime should be used
75    pub detect_files: Vec<String>,
76}
77
78/// Trigger build response
79#[derive(Debug, Serialize, utoipa::ToSchema)]
80pub struct TriggerBuildResponse {
81    /// Unique build ID for tracking
82    pub build_id: String,
83    /// Human-readable message
84    pub message: String,
85}
86
87/// Build event wrapper for SSE serialization
88#[derive(Debug, Clone, Serialize)]
89pub struct BuildEventWrapper {
90    /// Event type
91    #[serde(rename = "type")]
92    pub event_type: String,
93    /// Event data
94    pub data: serde_json::Value,
95}
96
97/// Build request with server-side context path
98#[derive(Debug, Deserialize, utoipa::ToSchema)]
99pub struct BuildRequestWithContext {
100    /// Path to the build context on the server
101    pub context_path: String,
102    /// Use runtime template instead of Dockerfile
103    #[serde(default)]
104    pub runtime: Option<String>,
105    /// Build arguments
106    #[serde(default)]
107    pub build_args: HashMap<String, String>,
108    /// Target stage
109    #[serde(default)]
110    pub target: Option<String>,
111    /// Tags to apply
112    #[serde(default)]
113    pub tags: Vec<String>,
114    /// Disable cache
115    #[serde(default)]
116    pub no_cache: bool,
117    /// Push after build
118    #[serde(default)]
119    pub push: bool,
120}
121
122impl From<BuildRequestWithContext> for BuildRequest {
123    fn from(req: BuildRequestWithContext) -> Self {
124        Self {
125            runtime: req.runtime,
126            build_args: req.build_args,
127            target: req.target,
128            tags: req.tags,
129            no_cache: req.no_cache,
130            push: req.push,
131        }
132    }
133}