microsandbox_core/models.rs
1//! Database models for Microsandbox.
2
3use chrono::{DateTime, Utc};
4
5//--------------------------------------------------------------------------------------------------
6// Types: Sandbox
7//--------------------------------------------------------------------------------------------------
8
9/// A sandbox is an active virtual machine that is managed by Microsandbox.
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub struct Sandbox {
12 /// The unique identifier for the sandbox.
13 pub id: i64,
14
15 /// The name of the sandbox.
16 pub name: String,
17
18 /// The Microsandbox configuration filename that defines the sandbox.
19 pub config_file: String,
20
21 /// The last modified date and time of the Microsandbox configuration file.
22 pub config_last_modified: DateTime<Utc>,
23
24 /// The status of the sandbox.
25 pub status: String,
26
27 /// The PID of the supervisor process for the sandbox.
28 pub supervisor_pid: u32,
29
30 /// The PID of the microVM process for the sandbox.
31 pub microvm_pid: u32,
32
33 /// The paths to the root filesystems for the sandbox.
34 pub rootfs_paths: String,
35
36 /// The ID of the group that the sandbox belongs to.
37 pub group_id: Option<u32>,
38
39 /// The IP address of the group that the sandbox belongs to.
40 pub group_ip: Option<String>,
41
42 /// When the sandbox was created
43 pub created_at: DateTime<Utc>,
44
45 /// When the sandbox was last modified
46 pub modified_at: DateTime<Utc>,
47}
48
49//--------------------------------------------------------------------------------------------------
50// Types: OCI
51//--------------------------------------------------------------------------------------------------
52
53/// Represents an OCI container image in the database
54#[derive(Debug, Clone)]
55pub struct Image {
56 /// Unique identifier for the image
57 pub id: i64,
58
59 /// Reference string for the image (e.g. "library/ubuntu:latest")
60 pub reference: String,
61
62 /// Size of the image in bytes
63 pub size_bytes: i64,
64
65 /// When the image was last used
66 pub last_used_at: Option<DateTime<Utc>>,
67
68 /// When the image was created
69 pub created_at: DateTime<Utc>,
70
71 /// When the image was last modified
72 pub modified_at: DateTime<Utc>,
73}
74
75/// Represents an OCI image index in the database
76#[derive(Debug, Clone)]
77pub struct Index {
78 /// Unique identifier for the index
79 pub id: i64,
80
81 /// ID of the image this index belongs to
82 pub image_id: i64,
83
84 /// Schema version for the index
85 pub schema_version: i64,
86
87 /// Media type of the index
88 pub media_type: String,
89
90 /// Operating system platform
91 pub platform_os: Option<String>,
92
93 /// Architecture platform
94 pub platform_arch: Option<String>,
95
96 /// Platform variant
97 pub platform_variant: Option<String>,
98
99 /// JSON string containing annotations
100 pub annotations_json: Option<String>,
101
102 /// When the index was created
103 pub created_at: DateTime<Utc>,
104
105 /// When the index was last modified
106 pub modified_at: DateTime<Utc>,
107}
108
109/// Represents an OCI image manifest in the database
110#[derive(Debug, Clone)]
111pub struct Manifest {
112 /// Unique identifier for the manifest
113 pub id: i64,
114
115 /// Optional ID of the index this manifest belongs to
116 pub index_id: Option<i64>,
117
118 /// ID of the image this manifest belongs to
119 pub image_id: i64,
120
121 /// Schema version for the manifest
122 pub schema_version: i64,
123
124 /// Media type of the manifest
125 pub media_type: String,
126
127 /// JSON string containing annotations
128 pub annotations_json: Option<String>,
129
130 /// When the manifest was created
131 pub created_at: DateTime<Utc>,
132
133 /// When the manifest was last modified
134 pub modified_at: DateTime<Utc>,
135}
136
137/// Represents an OCI image configuration in the database
138#[derive(Debug, Clone)]
139pub struct Config {
140 /// Unique identifier for the config
141 pub id: i64,
142
143 /// ID of the manifest this config belongs to
144 pub manifest_id: i64,
145
146 /// Media type of the config
147 pub media_type: String,
148
149 /// When the image was created
150 pub created: Option<DateTime<Utc>>,
151
152 /// Architecture of the image
153 pub architecture: String,
154
155 /// Operating system of the image
156 pub os: String,
157
158 /// Operating system variant
159 pub os_variant: Option<String>,
160
161 /// JSON string containing environment variables
162 pub config_env_json: Option<String>,
163
164 /// JSON string containing command
165 pub config_cmd_json: Option<String>,
166
167 /// Working directory
168 pub config_working_dir: Option<String>,
169
170 /// JSON string containing entrypoint
171 pub config_entrypoint_json: Option<String>,
172
173 /// JSON string containing volumes
174 pub config_volumes_json: Option<String>,
175
176 /// JSON string containing exposed ports
177 pub config_exposed_ports_json: Option<String>,
178
179 /// User to run as
180 pub config_user: Option<String>,
181
182 /// Type of root filesystem
183 pub rootfs_type: String,
184
185 /// JSON string containing rootfs diff IDs
186 pub rootfs_diff_ids_json: Option<String>,
187
188 /// JSON string containing history
189 pub history_json: Option<String>,
190
191 /// When the config was created
192 pub created_at: DateTime<Utc>,
193
194 /// When the config was last modified
195 pub modified_at: DateTime<Utc>,
196}
197
198/// Represents a layer in an OCI container image
199#[derive(Debug, Clone)]
200pub struct Layer {
201 /// Unique identifier for the layer
202 pub id: i64,
203
204 /// Media type of the layer
205 pub media_type: String,
206
207 /// Digest (hash) of the compressed layer
208 pub digest: String,
209
210 /// Diff ID (hash) of the uncompressed layer
211 pub diff_id: String,
212
213 /// Size of the layer in bytes
214 pub size_bytes: i64,
215
216 /// Time when the record was created
217 pub created_at: DateTime<Utc>,
218
219 /// Time when the record was last modified
220 pub modified_at: DateTime<Utc>,
221}