use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub struct GitOpsConfig {
pub enabled: bool,
pub provider: GitOpsProvider,
pub repository: RepositoryConfig,
pub sync: SyncConfig,
pub cd_pipeline: CDPipelineConfig,
}
impl Default for GitOpsConfig {
fn default() -> Self {
Self {
enabled: true,
provider: GitOpsProvider::ArgoCD,
repository: RepositoryConfig::default(),
sync: SyncConfig::default(),
cd_pipeline: CDPipelineConfig::default(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GitOpsProvider {
ArgoCD,
Flux,
Tekton,
Jenkins,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RepositoryConfig {
pub url: String,
pub branch: String,
pub path: String,
pub credentials: GitCredentials,
}
impl Default for RepositoryConfig {
fn default() -> Self {
Self {
url: "https://github.com/oxirs/oxirs-deploy.git".to_string(),
branch: "main".to_string(),
path: "kubernetes".to_string(),
credentials: GitCredentials::default(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitCredentials {
pub credential_type: GitCredentialType,
pub username: Option<String>,
pub password: Option<String>,
pub ssh_private_key: Option<String>,
}
impl Default for GitCredentials {
fn default() -> Self {
Self {
credential_type: GitCredentialType::Token,
username: None,
password: None,
ssh_private_key: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GitCredentialType {
Token,
UsernamePassword,
SSH,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncConfig {
pub auto_sync: bool,
pub sync_interval: Duration,
pub prune: bool,
pub self_heal: bool,
}
impl Default for SyncConfig {
fn default() -> Self {
Self {
auto_sync: true,
sync_interval: Duration::from_secs(180),
prune: true,
self_heal: true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CDPipelineConfig {
pub enabled: bool,
pub stages: Vec<PipelineStage>,
pub deployment_strategy: DeploymentStrategy,
}
impl Default for CDPipelineConfig {
fn default() -> Self {
Self {
enabled: true,
stages: vec![
PipelineStage {
name: "build".to_string(),
stage_type: StageType::Build,
commands: vec![
"docker build -t oxirs/stream:${GIT_COMMIT} .".to_string(),
"docker push oxirs/stream:${GIT_COMMIT}".to_string(),
],
},
PipelineStage {
name: "test".to_string(),
stage_type: StageType::Test,
commands: vec![
"cargo test --all".to_string(),
"helm lint charts/oxirs-stream".to_string(),
],
},
PipelineStage {
name: "deploy-staging".to_string(),
stage_type: StageType::Deploy,
commands: vec![
"helm upgrade --install oxirs-stream-staging charts/oxirs-stream --namespace staging".to_string(),
],
},
],
deployment_strategy: DeploymentStrategy::RollingUpdate,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipelineStage {
pub name: String,
pub stage_type: StageType,
pub commands: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum StageType {
Build,
Test,
Deploy,
Approve,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeploymentStrategy {
RollingUpdate,
BlueGreen,
Canary,
Recreate,
}