mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-29 12:43:26 -05:00
implement conversion from legacy -> next for build, deployment, server
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use monitor_types::entities::build::{BuildConfig, BuildInfo};
|
||||
use mungos::mongodb::bson::serde_helpers::hex_string_as_object_id;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Command, EnvironmentVar, PermissionsMap};
|
||||
use super::{
|
||||
unix_from_monitor_ts, Command, EnvironmentVar, PermissionsMap,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct Build {
|
||||
@@ -107,6 +110,16 @@ impl Version {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Version> for monitor_types::entities::Version {
|
||||
fn from(value: Version) -> Self {
|
||||
Self {
|
||||
major: value.major,
|
||||
minor: value.minor,
|
||||
patch: value.patch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Clone, PartialEq, Default,
|
||||
)]
|
||||
@@ -147,3 +160,84 @@ pub struct AwsBuilderBuildConfig {
|
||||
|
||||
pub assign_public_ip: Option<bool>,
|
||||
}
|
||||
|
||||
impl TryFrom<Build> for monitor_types::entities::build::Build {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(value: Build) -> Result<Self, Self::Error> {
|
||||
let (
|
||||
build_path,
|
||||
dockerfile_path,
|
||||
build_args,
|
||||
extra_args,
|
||||
use_buildx,
|
||||
) = value
|
||||
.docker_build_args
|
||||
.map(|args| {
|
||||
(
|
||||
args.build_path,
|
||||
args.dockerfile_path.unwrap_or_default(),
|
||||
args.build_args
|
||||
.into_iter()
|
||||
.map(|arg| {
|
||||
monitor_types::entities::EnvironmentVar {
|
||||
variable: arg.variable,
|
||||
value: arg.value,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
args.extra_args,
|
||||
args.use_buildx,
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let build = Self {
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
permissions: value
|
||||
.permissions
|
||||
.into_iter()
|
||||
.map(|(id, p)| (id, p.into()))
|
||||
.collect(),
|
||||
updated_at: unix_from_monitor_ts(&value.updated_at)?,
|
||||
tags: Vec::new(),
|
||||
info: BuildInfo {
|
||||
last_built_at: unix_from_monitor_ts(
|
||||
&value.last_built_at,
|
||||
)?,
|
||||
},
|
||||
config: BuildConfig {
|
||||
builder_id: String::new(),
|
||||
skip_secret_interp: value.skip_secret_interp,
|
||||
version: value.version.into(),
|
||||
repo: value.repo.unwrap_or_default(),
|
||||
branch: value.branch.unwrap_or_default(),
|
||||
github_account: value
|
||||
.github_account
|
||||
.unwrap_or_default(),
|
||||
docker_account: value
|
||||
.docker_account
|
||||
.unwrap_or_default(),
|
||||
docker_organization: value
|
||||
.docker_organization
|
||||
.unwrap_or_default(),
|
||||
pre_build: value
|
||||
.pre_build
|
||||
.map(|command| {
|
||||
monitor_types::entities::SystemCommand {
|
||||
path: command.path,
|
||||
command: command.command,
|
||||
}
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
build_path,
|
||||
dockerfile_path,
|
||||
build_args,
|
||||
extra_args,
|
||||
use_buildx,
|
||||
},
|
||||
};
|
||||
Ok(build)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use mungos::mongodb::bson::serde_helpers::hex_string_as_object_id;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::legacy::v0::unix_from_monitor_ts;
|
||||
|
||||
use super::{Command, EnvironmentVar, PermissionsMap, Version};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
@@ -98,6 +100,17 @@ pub struct TerminationSignalLabel {
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
impl From<TerminationSignalLabel>
|
||||
for monitor_types::entities::deployment::TerminationSignalLabel
|
||||
{
|
||||
fn from(value: TerminationSignalLabel) -> Self {
|
||||
Self {
|
||||
signal: value.signal.into(),
|
||||
label: value.label,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct DockerRunArgs {
|
||||
pub image: String,
|
||||
@@ -165,6 +178,17 @@ pub struct Conversion {
|
||||
pub container: String,
|
||||
}
|
||||
|
||||
impl From<Conversion>
|
||||
for monitor_types::entities::deployment::Conversion
|
||||
{
|
||||
fn from(value: Conversion) -> Self {
|
||||
Self {
|
||||
local: value.local,
|
||||
container: value.container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct DockerContainerStats {
|
||||
#[serde(alias = "Name")]
|
||||
@@ -231,6 +255,20 @@ pub enum RestartMode {
|
||||
UnlessStopped,
|
||||
}
|
||||
|
||||
impl From<RestartMode>
|
||||
for monitor_types::entities::deployment::RestartMode
|
||||
{
|
||||
fn from(value: RestartMode) -> Self {
|
||||
use monitor_types::entities::deployment::RestartMode::*;
|
||||
match value {
|
||||
RestartMode::NoRestart => NoRestart,
|
||||
RestartMode::OnFailure => OnFailure,
|
||||
RestartMode::Always => Always,
|
||||
RestartMode::UnlessStopped => UnlessStopped,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize,
|
||||
Deserialize,
|
||||
@@ -255,3 +293,63 @@ pub enum TerminationSignal {
|
||||
#[serde(alias = "15")]
|
||||
SigTerm,
|
||||
}
|
||||
|
||||
impl From<TerminationSignal>
|
||||
for monitor_types::entities::deployment::TerminationSignal
|
||||
{
|
||||
fn from(value: TerminationSignal) -> Self {
|
||||
use monitor_types::entities::deployment::TerminationSignal::*;
|
||||
match value {
|
||||
TerminationSignal::SigHup => SigHup,
|
||||
TerminationSignal::SigInt => SigInt,
|
||||
TerminationSignal::SigQuit => SigQuit,
|
||||
TerminationSignal::SigTerm => SigTerm,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Deployment>
|
||||
for monitor_types::entities::deployment::Deployment
|
||||
{
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(value: Deployment) -> Result<Self, Self::Error> {
|
||||
let image = if let Some(build_id) = value.build_id {
|
||||
monitor_types::entities::deployment::DeploymentImage::Build { build_id, version: value.build_version.unwrap_or_default().into() }
|
||||
} else {
|
||||
monitor_types::entities::deployment::DeploymentImage::Image { image: value.docker_run_args.image }
|
||||
};
|
||||
let deployment = Self {
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
permissions: value
|
||||
.permissions
|
||||
.into_iter()
|
||||
.map(|(id, p)| (id, p.into()))
|
||||
.collect(),
|
||||
updated_at: unix_from_monitor_ts(&value.updated_at)?,
|
||||
tags: Vec::new(),
|
||||
info: (),
|
||||
config: monitor_types::entities::deployment::DeploymentConfig {
|
||||
server_id: value.server_id,
|
||||
send_alerts: true,
|
||||
image,
|
||||
skip_secret_interp: value.skip_secret_interp,
|
||||
redeploy_on_build: value.redeploy_on_build,
|
||||
term_signal_labels: value.term_signal_labels.into_iter().map(|t| t.into()).collect(),
|
||||
termination_signal: value.termination_signal.into(),
|
||||
termination_timeout: value.termination_timeout,
|
||||
ports: value.docker_run_args.ports.into_iter().map(|p| p.into()).collect(),
|
||||
volumes: value.docker_run_args.volumes.into_iter().map(|v| v.into()).collect(),
|
||||
environment: value.docker_run_args.environment.into_iter().map(|e| e.into()).collect(),
|
||||
network: value.docker_run_args.network,
|
||||
restart: value.docker_run_args.restart.into(),
|
||||
process_args: value.docker_run_args.post_image.unwrap_or_default(),
|
||||
container_user: value.docker_run_args.container_user.unwrap_or_default(),
|
||||
extra_args: value.docker_run_args.extra_args,
|
||||
docker_account: value.docker_run_args.docker_account.unwrap_or_default(),
|
||||
},
|
||||
};
|
||||
Ok(deployment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,15 @@ pub struct EnvironmentVar {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl From<EnvironmentVar> for monitor_types::entities::EnvironmentVar {
|
||||
fn from(value: EnvironmentVar) -> Self {
|
||||
Self {
|
||||
variable: value.variable,
|
||||
value: value.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct UserCredentials {
|
||||
pub username: String,
|
||||
@@ -174,6 +183,20 @@ impl Default for &PermissionLevel {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PermissionLevel>
|
||||
for monitor_types::entities::PermissionLevel
|
||||
{
|
||||
fn from(value: PermissionLevel) -> Self {
|
||||
use monitor_types::entities::PermissionLevel::*;
|
||||
match value {
|
||||
PermissionLevel::None => None,
|
||||
PermissionLevel::Read => Read,
|
||||
PermissionLevel::Execute => Execute,
|
||||
PermissionLevel::Update => Update,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, PartialEq, Hash, Eq, Clone, Copy,
|
||||
)]
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||
use mungos::mongodb::bson::serde_helpers::hex_string_as_object_id;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{PermissionsMap, Timelength};
|
||||
use super::{unix_from_monitor_ts, PermissionsMap, Timelength};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Server {
|
||||
@@ -285,3 +285,40 @@ pub struct SystemInformation {
|
||||
pub host_name: Option<String>,
|
||||
pub cpu_brand: String,
|
||||
}
|
||||
|
||||
impl TryFrom<Server> for monitor_types::entities::server::Server {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(value: Server) -> Result<Self, Self::Error> {
|
||||
let server = Self {
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
permissions: value
|
||||
.permissions
|
||||
.into_iter()
|
||||
.map(|(id, p)| (id, p.into()))
|
||||
.collect(),
|
||||
updated_at: unix_from_monitor_ts(&value.updated_at)?,
|
||||
tags: Vec::new(),
|
||||
info: (),
|
||||
config: monitor_types::entities::server::ServerConfig {
|
||||
address: value.address,
|
||||
enabled: value.enabled,
|
||||
auto_prune: value.auto_prune,
|
||||
send_unreachable_alerts: true,
|
||||
send_cpu_alerts: true,
|
||||
send_mem_alerts: true,
|
||||
send_disk_alerts: true,
|
||||
send_temp_alerts: true,
|
||||
region: value.region.unwrap_or_default(),
|
||||
cpu_warning: value.cpu_alert,
|
||||
cpu_critical: value.cpu_alert,
|
||||
mem_warning: value.mem_alert,
|
||||
mem_critical: value.mem_alert,
|
||||
disk_warning: value.disk_alert,
|
||||
disk_critical: value.disk_alert,
|
||||
},
|
||||
};
|
||||
Ok(server)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user