Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ humantime = "2"
hyper = { version = "1.7", features = ["full"] }
hyper-util = { version = "0.1" }
indicatif = "0.18"
inquire = "0.9.4"
ipnet = "2.8"
iptables = { git = "https://github.com/metalbear-co/rust-iptables.git", rev = "e66c7332e361df3c61a194f08eefe3f40763d624" }
itertools = "0.14.0"
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+mirrord-up-init.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `mirrord up init`, an interactive wizard that generates a skeleton `mirrord-up.yaml`.
15 changes: 15 additions & 0 deletions mirrord/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,21 @@ pub(super) struct UpArgs {
/// If not provided, a key is generated automatically from the system username.
#[arg(long)]
pub key: Option<String>,

/// Subcommand. When absent, `mirrord up` runs the sessions defined in
/// the config file. With a subcommand, the flags above are ignored.
#[command(subcommand)]
pub command: Option<UpSubcommand>,
}

#[derive(Subcommand, Debug)]
pub(super) enum UpSubcommand {
/// Launch an interactive wizard that generates a skeleton mirrord-up.yaml.
Init {
/// Default path for the generated config (overrideable in the wizard).
#[arg(short = 'o', long, value_hint = ValueHint::FilePath, default_value = "mirrord-up.yaml")]
output: PathBuf,
},
}
/// `mirrord attach` args.
#[cfg(windows)]
Expand Down
11 changes: 9 additions & 2 deletions mirrord/cli/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ use std::io::ErrorKind;

use miette::Diagnostic;
use mirrord_config::config::EnvKey;
use mirrord_up::{UpError, load_up_config};
use mirrord_up::{InitError, UpError, load_up_config, run_wizard};
use thiserror::Error;

use crate::config::UpArgs;
use crate::config::{UpArgs, UpSubcommand};

#[derive(Debug, Error, Diagnostic)]
pub enum UpCliError {
#[error(transparent)]
Up(#[from] UpError),

#[error(transparent)]
Init(#[from] InitError),

#[error("mirrord-up.yaml file not found.")]
#[diagnostic(help(
"Please create a mirrord-up.yaml file or specify its exact path with `mirrord up -f <file path.yaml>`"
Expand All @@ -29,6 +32,10 @@ pub enum UpCliError {

/// The `mirrord up` command handler.
pub(crate) async fn up_command(args: UpArgs) -> Result<(), UpCliError> {
if let Some(UpSubcommand::Init { output }) = args.command {
return Ok(run_wizard(output)?);
}

let up_config = match load_up_config(&args.config_file) {
Ok(cfg) => cfg,
Err(UpError::Io(err)) if err.kind() == ErrorKind::NotFound => {
Expand Down
1 change: 1 addition & 0 deletions mirrord/up/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ strum_macros.workspace = true
strum.workspace = true
tokio = { workspace = true, features = ["process"] }
clap.workspace = true
inquire.workspace = true

[lints]
workspace = true
Expand Down
32 changes: 18 additions & 14 deletions mirrord/up/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use mirrord_config::{
};
use serde::{Deserialize, Serialize};
use strum::VariantArray;
use strum_macros::{IntoStaticStr, VariantArray};
use strum_macros::{Display, IntoStaticStr, VariantArray};

/// Incoming traffic mode for a service.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, VariantArray, IntoStaticStr)]
#[derive(
Clone, Debug, Default, Serialize, Deserialize, PartialEq, VariantArray, IntoStaticStr, Display,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum ServiceMode {
Expand Down Expand Up @@ -44,7 +46,9 @@ If no filter is provided, a header filter matching the regex `baggage: .*mirrord

/// Specifies if this service should be run with `mirrord exec` or
/// `mirrord container`
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default, IntoStaticStr)]
#[derive(
Clone, Debug, Serialize, Deserialize, PartialEq, Default, IntoStaticStr, Display, VariantArray,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum RunType {
Expand All @@ -67,9 +71,9 @@ pub struct RunConfig {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct CommonConfig {
accept_invalid_certificates: Option<bool>,
operator: Option<bool>,
telemetry: Option<bool>,
pub(crate) accept_invalid_certificates: Option<bool>,
pub(crate) operator: Option<bool>,
pub(crate) telemetry: Option<bool>,
}

/// Separate from [`mirrord_config::target::TargetConfig`] because we
Expand All @@ -79,8 +83,8 @@ pub struct CommonConfig {
#[serde(deny_unknown_fields)]
pub struct TargetConfig {
#[serde(deserialize_with = "mirrord_config::util::string_or_struct_option")]
path: Option<Target>,
namespace: Option<String>,
pub(crate) path: Option<Target>,
pub(crate) namespace: Option<String>,
}

impl From<TargetConfig> for mirrord_config::target::TargetConfig {
Expand All @@ -97,21 +101,21 @@ impl From<TargetConfig> for mirrord_config::target::TargetConfig {
#[serde(deny_unknown_fields)]
pub struct ServiceConfig {
#[serde(default)]
target: TargetConfig,
pub(crate) target: TargetConfig,

#[serde(default)]
env: EnvConfig,
pub(crate) env: EnvConfig,

#[serde(default)]
default_mode: ServiceMode,
pub(crate) default_mode: ServiceMode,

#[serde(default)]
http_filter: HttpFilterConfig,
pub(crate) http_filter: HttpFilterConfig,

#[serde(default)]
ignore_ports: HashSet<u16>,
pub(crate) ignore_ports: HashSet<u16>,

run: RunConfig,
pub(crate) run: RunConfig,
}

/// Resolved top-level `mirrord-up.yaml` configuration.
Expand Down
Loading
Loading