mirror of
https://github.com/moghtech/komodo.git
synced 2026-09-10 16:01:20 +00:00
from on the new types
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
use monitor_client::entities::{
|
||||
build::{CloudRegistryConfig, ImageRegistry},
|
||||
NoData,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
@@ -6,31 +10,20 @@ use super::{
|
||||
|
||||
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,
|
||||
impl From<Build> for monitor_client::entities::build::Build {
|
||||
fn from(value: Build) -> Self {
|
||||
monitor_client::entities::build::Build {
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
updated_at: value.updated_at,
|
||||
tags: value.tags,
|
||||
info: monitor_client::entities::build::BuildInfo {
|
||||
last_built_at: value.info.last_built_at,
|
||||
},
|
||||
config: value.config.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
@@ -114,6 +107,49 @@ pub struct BuildConfig {
|
||||
pub webhook_enabled: bool,
|
||||
}
|
||||
|
||||
impl From<BuildConfig>
|
||||
for monitor_client::entities::build::BuildConfig
|
||||
{
|
||||
fn from(value: BuildConfig) -> Self {
|
||||
monitor_client::entities::build::BuildConfig {
|
||||
builder_id: value.builder_id,
|
||||
skip_secret_interp: value.skip_secret_interp,
|
||||
version: monitor_client::entities::Version {
|
||||
major: value.version.major,
|
||||
minor: value.version.minor,
|
||||
patch: value.version.patch,
|
||||
},
|
||||
repo: value.repo,
|
||||
branch: value.branch,
|
||||
commit: value.commit,
|
||||
github_account: value.github_account,
|
||||
pre_build: monitor_client::entities::SystemCommand {
|
||||
path: value.pre_build.path,
|
||||
command: value.pre_build.command,
|
||||
},
|
||||
build_path: value.build_path,
|
||||
dockerfile_path: value.dockerfile_path,
|
||||
build_args: value
|
||||
.build_args
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
labels: value.labels.into_iter().map(Into::into).collect(),
|
||||
extra_args: value.extra_args,
|
||||
use_buildx: value.use_buildx,
|
||||
image_registry: if value.docker_account.is_empty() {
|
||||
ImageRegistry::None(NoData {})
|
||||
} else {
|
||||
ImageRegistry::DockerHub(CloudRegistryConfig {
|
||||
account: value.docker_account,
|
||||
organization: value.docker_organization,
|
||||
})
|
||||
},
|
||||
webhook_enabled: value.webhook_enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_branch() -> String {
|
||||
String::from("main")
|
||||
}
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use monitor_client::entities::{
|
||||
build::{CloudRegistryConfig, ImageRegistry},
|
||||
deployment::{
|
||||
Conversion, DeploymentImage, RestartMode, TerminationSignal,
|
||||
TerminationSignalLabel,
|
||||
},
|
||||
NoData,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{resource::Resource, EnvironmentVar, Version};
|
||||
use super::{resource::Resource, EnvironmentVar};
|
||||
|
||||
pub type Deployment = Resource<DeploymentConfig, ()>;
|
||||
|
||||
impl From<Deployment>
|
||||
for monitor_client::entities::deployment::Deployment
|
||||
{
|
||||
fn from(value: Deployment) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
updated_at: value.updated_at,
|
||||
tags: value.tags,
|
||||
info: value.info,
|
||||
config: value.config.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct DeploymentConfig {
|
||||
/// The id of server the deployment is deployed on.
|
||||
@@ -36,7 +58,7 @@ pub struct DeploymentConfig {
|
||||
|
||||
/// Labels attached to various termination signal options.
|
||||
/// Used to specify different shutdown functionality depending on the termination signal.
|
||||
#[serde(default = "default_term_signal_labels")]
|
||||
#[serde(default)]
|
||||
pub term_signal_labels: Vec<TerminationSignalLabel>,
|
||||
|
||||
/// The default termination signal to use to stop the deployment. Defaults to SigTerm (default docker signal).
|
||||
@@ -88,12 +110,45 @@ pub struct DeploymentConfig {
|
||||
pub extra_args: Vec<String>,
|
||||
}
|
||||
|
||||
fn default_send_alerts() -> bool {
|
||||
true
|
||||
impl From<DeploymentConfig>
|
||||
for monitor_client::entities::deployment::DeploymentConfig
|
||||
{
|
||||
fn from(value: DeploymentConfig) -> Self {
|
||||
Self {
|
||||
server_id: value.server_id,
|
||||
send_alerts: value.send_alerts,
|
||||
image: value.image,
|
||||
image_registry: if value.docker_account.is_empty() {
|
||||
ImageRegistry::None(NoData {})
|
||||
} else {
|
||||
ImageRegistry::DockerHub(CloudRegistryConfig {
|
||||
account: value.docker_account,
|
||||
..Default::default()
|
||||
})
|
||||
},
|
||||
skip_secret_interp: value.skip_secret_interp,
|
||||
redeploy_on_build: value.redeploy_on_build,
|
||||
term_signal_labels: value.term_signal_labels,
|
||||
termination_signal: value.termination_signal,
|
||||
termination_timeout: value.termination_timeout,
|
||||
ports: value.ports,
|
||||
volumes: value.volumes,
|
||||
environment: value
|
||||
.environment
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
labels: value.labels.into_iter().map(Into::into).collect(),
|
||||
network: value.network,
|
||||
restart: value.restart,
|
||||
command: value.command,
|
||||
extra_args: value.extra_args,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_term_signal_labels() -> Vec<TerminationSignalLabel> {
|
||||
vec![TerminationSignalLabel::default()]
|
||||
fn default_send_alerts() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_termination_timeout() -> i32 {
|
||||
@@ -103,197 +158,3 @@ fn default_termination_timeout() -> i32 {
|
||||
fn default_network() -> String {
|
||||
String::from("host")
|
||||
}
|
||||
|
||||
impl Default for DeploymentConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
server_id: Default::default(),
|
||||
send_alerts: default_send_alerts(),
|
||||
image: Default::default(),
|
||||
docker_account: Default::default(),
|
||||
skip_secret_interp: Default::default(),
|
||||
redeploy_on_build: Default::default(),
|
||||
term_signal_labels: default_term_signal_labels(),
|
||||
termination_signal: Default::default(),
|
||||
termination_timeout: default_termination_timeout(),
|
||||
ports: Default::default(),
|
||||
volumes: Default::default(),
|
||||
environment: Default::default(),
|
||||
labels: Default::default(),
|
||||
network: default_network(),
|
||||
restart: Default::default(),
|
||||
command: Default::default(),
|
||||
extra_args: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
#[serde(tag = "type", content = "params")]
|
||||
pub enum DeploymentImage {
|
||||
/// Deploy any external image.
|
||||
Image {
|
||||
/// The docker image, can be from any registry that works with docker and that the host server can reach.
|
||||
#[serde(default)]
|
||||
image: String,
|
||||
},
|
||||
|
||||
/// Deploy a monitor build.
|
||||
Build {
|
||||
/// The id of the build
|
||||
#[serde(default, alias = "build")]
|
||||
build_id: String,
|
||||
/// Use a custom / older version of the image produced by the build.
|
||||
/// if version is 0.0.0, this means `latest` image.
|
||||
#[serde(default)]
|
||||
version: Version,
|
||||
},
|
||||
}
|
||||
|
||||
impl Default for DeploymentImage {
|
||||
fn default() -> Self {
|
||||
Self::Image {
|
||||
image: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Clone, Default, PartialEq,
|
||||
)]
|
||||
pub struct Conversion {
|
||||
/// reference on the server.
|
||||
pub local: String,
|
||||
/// reference in the container.
|
||||
pub container: String,
|
||||
}
|
||||
|
||||
/// A summary of a docker container on a server.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct ContainerSummary {
|
||||
/// Name of the container.
|
||||
pub name: String,
|
||||
/// Id of the container.
|
||||
pub id: String,
|
||||
/// The image the container is based on.
|
||||
pub image: String,
|
||||
/// The docker labels on the container.
|
||||
pub labels: HashMap<String, String>,
|
||||
/// The state of the container, like `running` or `not_deployed`
|
||||
pub state: DeploymentState,
|
||||
/// The status string of the docker container.
|
||||
pub status: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct DockerContainerStats {
|
||||
#[serde(alias = "Name")]
|
||||
pub name: String,
|
||||
#[serde(alias = "CPUPerc")]
|
||||
pub cpu_perc: String,
|
||||
#[serde(alias = "MemPerc")]
|
||||
pub mem_perc: String,
|
||||
#[serde(alias = "MemUsage")]
|
||||
pub mem_usage: String,
|
||||
#[serde(alias = "NetIO")]
|
||||
pub net_io: String,
|
||||
#[serde(alias = "BlockIO")]
|
||||
pub block_io: String,
|
||||
#[serde(alias = "PIDs")]
|
||||
pub pids: String,
|
||||
}
|
||||
|
||||
/// Variants de/serialized from/to snake_case.
|
||||
///
|
||||
/// Eg.
|
||||
/// - NotDeployed -> not_deployed
|
||||
/// - Restarting -> restarting
|
||||
/// - Running -> running.
|
||||
#[derive(
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Hash,
|
||||
Eq,
|
||||
Clone,
|
||||
Copy,
|
||||
Default,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DeploymentState {
|
||||
#[default]
|
||||
Unknown,
|
||||
NotDeployed,
|
||||
Created,
|
||||
Restarting,
|
||||
Running,
|
||||
Removing,
|
||||
Paused,
|
||||
Exited,
|
||||
Dead,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Hash,
|
||||
Eq,
|
||||
Clone,
|
||||
Copy,
|
||||
Default,
|
||||
)]
|
||||
pub enum RestartMode {
|
||||
#[default]
|
||||
#[serde(rename = "no")]
|
||||
NoRestart,
|
||||
#[serde(rename = "on-failure")]
|
||||
OnFailure,
|
||||
#[serde(rename = "always")]
|
||||
Always,
|
||||
#[serde(rename = "unless-stopped")]
|
||||
UnlessStopped,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Hash,
|
||||
Eq,
|
||||
Clone,
|
||||
Copy,
|
||||
Default,
|
||||
)]
|
||||
#[serde(rename_all = "UPPERCASE")]
|
||||
pub enum TerminationSignal {
|
||||
#[serde(alias = "1")]
|
||||
SigHup,
|
||||
#[serde(alias = "2")]
|
||||
SigInt,
|
||||
#[serde(alias = "3")]
|
||||
SigQuit,
|
||||
#[default]
|
||||
#[serde(alias = "15")]
|
||||
SigTerm,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq,
|
||||
)]
|
||||
pub struct TerminationSignalLabel {
|
||||
pub signal: TerminationSignal,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
||||
pub struct DeploymentActionState {
|
||||
pub deploying: bool,
|
||||
pub stopping: bool,
|
||||
pub starting: bool,
|
||||
pub removing: bool,
|
||||
pub renaming: bool,
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod build;
|
||||
pub mod resource;
|
||||
pub mod deployment;
|
||||
pub mod resource;
|
||||
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Clone, Default, PartialEq,
|
||||
@@ -29,4 +29,15 @@ pub struct SystemCommand {
|
||||
pub struct EnvironmentVar {
|
||||
pub variable: String,
|
||||
pub value: String,
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EnvironmentVar>
|
||||
for monitor_client::entities::EnvironmentVar
|
||||
{
|
||||
fn from(value: EnvironmentVar) -> Self {
|
||||
monitor_client::entities::EnvironmentVar {
|
||||
variable: value.variable,
|
||||
value: value.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user