add 1.6 build schema for 1.7 migration

This commit is contained in:
mbecker20
2024-06-08 15:35:31 -07:00
parent 648a04be88
commit 5c3294241d
4 changed files with 241 additions and 0 deletions
+1
View File
@@ -1 +1,2 @@
pub mod v0;
pub mod v1_6;
+155
View File
@@ -0,0 +1,155 @@
use serde::{Deserialize, Serialize};
use super::{
resource::Resource, EnvironmentVar, SystemCommand, Version,
};
pub type Build = Resource<BuildConfig, BuildInfo>;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuildListItemInfo {
/// Unix timestamp in milliseconds of last build
pub last_built_at: i64,
/// The current version of the build
pub version: Version,
/// The Github repo used as the source of the build
pub repo: String,
/// The branch of the repo
pub branch: String,
/// State of the build. Reflects whether most recent build successful.
pub state: BuildState,
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
pub enum BuildState {
/// Last build successful (or never built)
Ok,
/// Last build failed
Failed,
/// Currently building
Building,
/// Other case
#[default]
Unknown,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct BuildInfo {
pub last_built_at: i64,
}
/// The build configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuildConfig {
/// Which builder is used to build the image.
#[serde(default, alias = "builder")]
pub builder_id: String,
/// Whether to skip secret interpolation in the build_args.
#[serde(default)]
pub skip_secret_interp: bool,
/// The current version of the build.
#[serde(default)]
pub version: Version,
/// The Github repo used as the source of the build.
#[serde(default)]
pub repo: String,
/// The branch of the repo.
#[serde(default = "default_branch")]
pub branch: String,
/// Optionally set a specific commit hash.
#[serde(default)]
pub commit: String,
/// The github account used to clone (used to access private repos).
/// Empty string is public clone (only public repos).
#[serde(default)]
pub github_account: String,
/// The dockerhub account used to push the image to dockerhub.
/// Empty string means no dockerhub push (server local build).
#[serde(default)]
pub docker_account: String,
/// The docker organization which the image should be pushed under.
/// Empty string means no organization.
#[serde(default)]
pub docker_organization: String,
/// The optional command run after repo clone and before docker build.
#[serde(default)]
pub pre_build: SystemCommand,
/// The path of the docker build context relative to the root of the repo.
/// Default: "." (the root of the repo).
#[serde(default = "default_build_path")]
pub build_path: String,
/// The path of the dockerfile relative to the build path.
#[serde(default = "default_dockerfile_path")]
pub dockerfile_path: String,
/// Docker build arguments
#[serde(default)]
pub build_args: Vec<EnvironmentVar>,
/// Docker labels
#[serde(default)]
pub labels: Vec<EnvironmentVar>,
/// Any extra docker cli arguments to be included in the build command
#[serde(default)]
pub extra_args: Vec<String>,
/// Whether to use buildx to build (eg `docker buildx build ...`)
#[serde(default)]
pub use_buildx: bool,
/// Whether incoming webhooks actually trigger action.
#[serde(default = "default_webhook_enabled")]
pub webhook_enabled: bool,
}
fn default_branch() -> String {
String::from("main")
}
fn default_build_path() -> String {
String::from(".")
}
fn default_dockerfile_path() -> String {
String::from("Dockerfile")
}
fn default_webhook_enabled() -> bool {
true
}
impl Default for BuildConfig {
fn default() -> Self {
Self {
builder_id: Default::default(),
skip_secret_interp: Default::default(),
version: Default::default(),
repo: Default::default(),
branch: default_branch(),
commit: Default::default(),
github_account: Default::default(),
docker_account: Default::default(),
docker_organization: Default::default(),
pre_build: Default::default(),
build_path: default_build_path(),
dockerfile_path: default_dockerfile_path(),
build_args: Default::default(),
labels: Default::default(),
extra_args: Default::default(),
use_buildx: Default::default(),
webhook_enabled: default_webhook_enabled(),
}
}
}
+31
View File
@@ -0,0 +1,31 @@
use serde::{Deserialize, Serialize};
pub mod build;
pub mod resource;
#[derive(
Serialize, Deserialize, Debug, Clone, Default, PartialEq,
)]
pub struct Version {
pub major: i32,
pub minor: i32,
pub patch: i32,
}
#[derive(
Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq,
)]
pub struct SystemCommand {
#[serde(default)]
pub path: String,
#[serde(default)]
pub command: String,
}
#[derive(
Serialize, Deserialize, Debug, Clone, Default, PartialEq,
)]
pub struct EnvironmentVar {
pub variable: String,
pub value: String,
}
+54
View File
@@ -0,0 +1,54 @@
use mungos::mongodb::bson::serde_helpers::hex_string_as_object_id;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Resource<Config, Info: Default = ()> {
/// The Mongo ID of the resource.
/// This field is de/serialized from/to JSON as
/// `{ "_id": { "$oid": "..." }, ...(rest of serialized Resource<T>) }`
#[serde(
default,
rename = "_id",
skip_serializing_if = "String::is_empty",
with = "hex_string_as_object_id"
)]
pub id: String,
/// The resource name.
/// This is guaranteed unique among others of the same resource type.
pub name: String,
/// A description for the resource
#[serde(default)]
pub description: String,
/// When description last updated
#[serde(default)]
pub updated_at: i64,
/// Tag Ids
#[serde(default)]
pub tags: Vec<String>,
/// Resource-specific information (not user configurable).
#[serde(default)]
pub info: Info,
/// Resource-specific configuration.
pub config: Config,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ResourceListItem<Info> {
/// The resource id
pub id: String,
/// The resource type, ie `Server` or `Deployment`
// #[serde(rename = "type")]
// pub resource_type: ResourceTargetVariant,
/// The resource name
pub name: String,
/// Tag Ids
pub tags: Vec<String>,
/// Resource specific info
pub info: Info,
}