Skip to content

Commit

Permalink
imp(flags): make bools true bools
Browse files Browse the repository at this point in the history
- This affords better help rendering (at the very least)
  • Loading branch information
blaggacao committed Nov 6, 2021
1 parent efde6ef commit 0a4114e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You can try out this tool easily with `nix run`:

In you want to deploy multiple flakes or a subset of profiles with one invocation, instead of calling `deploy <flake>` you can issue `deploy --targets <flake> [<flake> ...]` where `<flake>` is supposed to take the same format as discussed before.

Running in this mode, if any of the deploys fails, the deploy will be aborted and all successful deploys rolled back. `--rollback-succeeded false` can be used to override this behavior, otherwise the `auto-rollback` argument takes precedent.
Running in this mode, if any of the deploys fails, the deploy will be aborted and all successful deploys rolled back. `--rollback-succeeded false` can be used to override this behavior, otherwise the `no-auto-rollback` argument takes precedent.

If you require a signing key to push closures to your server, specify the path to it in the `LOCAL_KEY` environment variable.

Expand All @@ -48,7 +48,7 @@ This type of design (as opposed to more traditional tools like NixOps or morph)

### Magic Rollback

There is a built-in feature to prevent you making changes that might render your machine unconnectable or unusuable, which works by connecting to the machine after profile activation to confirm the machine is still available, and instructing the target node to automatically roll back if it is not confirmed. If you do not disable `magicRollback` in your configuration (see later sections) or with the CLI flag, you will be unable to make changes to the system which will affect you connecting to it (changing SSH port, changing your IP, etc).
There is a built-in feature to prevent you making changes that might render your machine unconnectable or unusuable, which works by connecting to the machine after profile activation to confirm the machine is still available, and instructing the target node to automatically roll back if it is not confirmed. If you do not disable `noMagicRollback` in your configuration (see later sections) or with the CLI flag, you will be unable to make changes to the system which will affect you connecting to it (changing SSH port, changing your IP, etc).

## API

Expand Down Expand Up @@ -166,17 +166,15 @@ This is a set of options that can be put in any of the above definitions, with t
# This defaults to `false`
fastConnection = false;
# If the previous profile should be re-activated if activation fails.
# This defaults to `true`
autoRollback = true;
# If the previous profile should NOT be re-activated if activation fails.
noAutoRollback = true;
# See the earlier section about Magic Rollback for more information.
# This defaults to `true`
magicRollback = true;
# See the earlier section about Magic Rollback for more information, disable with this attr.
noMagicRollback = true;
# The path which deploy-rs will use for temporary files, this is currently only used by `magicRollback` to create an inotify watcher in for confirmations
# The path which deploy-rs will use for temporary files, this is currently only used by the magic rollback to create an inotify watcher in for confirmations
# If not specified, this will default to `/tmp`
# (if `magicRollback` is in use, this _must_ be writable by `user`)
# (if magic rollback is in use, this _must_ be writable by `user`)
tempPath = "/home/someuser/.deploy-rs";
}
```
Expand Down
4 changes: 2 additions & 2 deletions interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"fastConnection": {
"type": "boolean"
},
"autoRollback": {
"noAutoRollback": {
"type": "boolean"
},
"magicRollback": {
"noMagicRollback": {
"type": "boolean"
},
"confirmTimeout": {
Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async fn run_deploy(

// Run all deployments
// In case of an error rollback any previoulsy made deployment.
// Rollbacks adhere to the global seeting to auto_rollback and secondary
// Rollbacks adhere to the global seeting to no_auto_rollback and secondary
// the profile's configuration
for deploy_data in &parts {
if let Err(e) = deploy::deploy::deploy_profile(
Expand All @@ -226,13 +226,13 @@ async fn run_deploy(
if cmd_flags.dry_activate {
info!("dry run, not rolling back");
}
if cmd_flags.rollback_succeeded && cmd_settings.auto_rollback.unwrap_or(true) {
if cmd_flags.rollback_succeeded && !cmd_settings.no_auto_rollback {
info!("Revoking previous deploys");
// revoking all previous deploys
// (adheres to profile configuration if not set explicitely by
// the command line)
for deploy_data in &succeeded {
if deploy_data.merged_settings.auto_rollback.unwrap_or(true) {
if !deploy_data.merged_settings.no_auto_rollback {
deploy::deploy::revoke(
&deploy_data.node_name,
&deploy_data.profile_name,
Expand Down
24 changes: 12 additions & 12 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub struct ActivateCommand<'a> {
profile_path: &'a str,
temp_path: &'a str,
closure: &'a str,
auto_rollback: bool,
no_auto_rollback: bool,
confirm_timeout: u16,
magic_rollback: bool,
no_magic_rollback: bool,
debug_logs: bool,
log_dir: Option<&'a str>,
dry_activate: bool,
Expand All @@ -50,9 +50,9 @@ impl<'a> ActivateCommand<'a> {
profile_path: &d.profile_path,
temp_path: &d.temp_path,
closure: &d.profile.profile_settings.path,
auto_rollback: d.merged_settings.auto_rollback.unwrap_or(true),
no_auto_rollback: d.merged_settings.no_auto_rollback,
confirm_timeout: d.merged_settings.confirm_timeout.unwrap_or(30),
magic_rollback: d.merged_settings.magic_rollback.unwrap_or(true),
no_magic_rollback: d.merged_settings.no_magic_rollback,
debug_logs: d.flags.debug_logs,
log_dir: d.flags.log_dir.as_deref(),
dry_activate: d.flags.dry_activate,
Expand All @@ -77,11 +77,11 @@ impl<'a> ActivateCommand<'a> {

cmd = format!("{} --confirm-timeout {}", cmd, self.confirm_timeout);

if self.magic_rollback {
if !self.no_magic_rollback {
cmd = format!("{} --magic-rollback", cmd);
}

if self.auto_rollback {
if !self.no_auto_rollback {
cmd = format!("{} --auto-rollback", cmd);
}

Expand All @@ -102,11 +102,11 @@ fn test_activation_command_builder() {
let sudo = Some("sudo -u test");
let profile_path = "/blah/profiles/test";
let closure = "/nix/store/blah/etc";
let auto_rollback = true;
let no_auto_rollback = false;
let dry_activate = false;
let temp_path = "/tmp";
let confirm_timeout = 30;
let magic_rollback = true;
let no_magic_rollback = false;
let debug_logs = true;
let log_dir = Some("/tmp/something.txt");

Expand All @@ -115,10 +115,10 @@ fn test_activation_command_builder() {
sudo,
profile_path,
closure,
auto_rollback,
no_auto_rollback,
temp_path,
confirm_timeout,
magic_rollback,
no_magic_rollback,
debug_logs,
log_dir,
dry_activate
Expand Down Expand Up @@ -352,15 +352,15 @@ pub async fn deploy_profile(
);
}
let dry_activate = &activate.dry_activate.clone();
let magic_rollback = &activate.magic_rollback.clone();
let no_magic_rollback = &activate.no_magic_rollback.clone();

let activate_cmd = activate.build();

debug!("Constructed activation command: {}", activate_cmd);

let mut ssh_activate_cmd = ssh.build();

if !*magic_rollback || *dry_activate {
if *no_magic_rollback || *dry_activate {
let ssh_activate_exit_status = ssh_activate_cmd
.arg(activate_cmd)
.status()
Expand Down
2 changes: 1 addition & 1 deletion src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> CopyCommand<'a> {
pub fn from_data(d: &'a data::DeployData) -> Self {
CopyCommand {
closure: d.profile.profile_settings.path.as_str(),
fast_connection: d.merged_settings.fast_connection.unwrap_or(false),
fast_connection: d.merged_settings.fast_connection,
check_sigs: &d.flags.checksigs,
ssh_uri: d.ssh_uri.as_str(),
ssh_opts: d
Expand Down
18 changes: 11 additions & 7 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ pub struct GenericSettings {
/// Override if the connecting to the target node should be considered fast
#[clap(long)]
#[serde(rename(deserialize = "fastConnection"))]
pub fast_connection: Option<bool>,
/// Override if a rollback should be attempted if activation fails
#[merge(strategy = merge::bool::overwrite_false)]
pub fast_connection: bool,
/// Do not attempt rollback if activation fails
#[clap(long)]
#[serde(rename(deserialize = "autoRollback"))]
pub auto_rollback: Option<bool>,
#[serde(rename(deserialize = "noAutoRollback"))]
#[merge(strategy = merge::bool::overwrite_false)]
pub no_auto_rollback: bool,
/// How long activation should wait for confirmation (if using magic-rollback)
#[clap(long)]
#[serde(rename(deserialize = "confirmTimeout"))]
Expand All @@ -43,9 +45,11 @@ pub struct GenericSettings {
#[clap(long)]
#[serde(rename(deserialize = "tempPath"))]
pub temp_path: Option<String>,
/// Do not do a magic rollback (see documentation)
#[clap(long)]
#[serde(rename(deserialize = "magicRollback"))]
pub magic_rollback: Option<bool>,
#[serde(rename(deserialize = "noMagicRollback"))]
#[merge(strategy = merge::bool::overwrite_false)]
pub no_magic_rollback: bool,
}

impl GenericSettings {
Expand All @@ -67,7 +71,7 @@ impl GenericSettings {

#[derive(Deserialize, Debug, Clone)]
pub struct NodeSettings {
pub hostname: String,
pub hostname: Option<String>,
pub profiles: HashMap<String, Profile>,
#[serde(
skip_serializing_if = "Vec::is_empty",
Expand Down

0 comments on commit 0a4114e

Please sign in to comment.