Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

iog master diff #126

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
86607fb
Refactor data to settings (specificity)
blaggacao Aug 7, 2021
18eba45
Expand environmental variables in sshOpts
nrdxp Aug 10, 2021
e6c50d9
Refactor data structures into thier own module
blaggacao Aug 7, 2021
e7d950a
Refactor implement from_str trait for `Target` data
blaggacao Aug 7, 2021
5fcece6
Refactor move flake parsing into adapter file
blaggacao Aug 8, 2021
7027879
Refactor homologate data structures
blaggacao Aug 8, 2021
29a90ae
Refactor accesor for ssh uri from DeployData
blaggacao Aug 26, 2021
492b4de
Refactor & simplify the target setting resolver
blaggacao Aug 8, 2021
011b351
Refactor merge DeployDefs into DeployData (single view)
blaggacao Aug 11, 2021
ce40968
Refactor & simplify the target setting resolver
blaggacao Aug 26, 2021
6610bad
Refactor create push.rs views into data.rs owned data & cleanup
blaggacao Aug 12, 2021
bea6fe0
run cargo fmt
nrdxp Aug 27, 2021
dad7542
fix clippy lints
nrdxp Aug 27, 2021
03d9974
expose base from activate.custom
manveru Aug 30, 2021
120c31f
update dependencies
nrdxp Nov 4, 2021
cb5aa4a
flake: replace naersk with buildRustPackage
lovesegfault Sep 15, 2021
40ff561
add aarch64-darwin to built systems
pjjw Aug 6, 2021
d630e13
Fix darwin build
balsoft Sep 28, 2021
f508d4b
change external interface to take parsed Opts
nrdxp Nov 5, 2021
c518de4
make Opts fields public for external use
nrdxp Nov 5, 2021
6dbb524
don't require hostname, since we pass in on the fly
nrdxp Nov 5, 2021
efde6ef
improve logging
blaggacao Nov 6, 2021
5075460
imp(flags): make bools true bools
blaggacao Nov 6, 2021
df1b349
imp(hostname): make hostname optional
blaggacao Nov 6, 2021
9dc9229
fix(hostname): accessor resolved values, not raw ones
blaggacao Nov 6, 2021
fee7e09
imp(ip-suffix): implement target ip suffix
blaggacao Nov 6, 2021
5603808
imp(socket): resolve sockets at the entrypoint
blaggacao Nov 6, 2021
5564608
imp tests
blaggacao Nov 6, 2021
0c28e0c
fix ssh uri/socket for nix copy
blaggacao Nov 6, 2021
9553b8c
feat(ssh_opts): concede multiple values to downstream
blaggacao Nov 7, 2021
3a8d4f3
ensure spawned thread exits before main
nrdxp Nov 18, 2021
aebc73d
optionally skip checks from environment
nrdxp Nov 18, 2021
3b9dcd1
flake: update lock and follow fenix nixpkgs
nrdxp Nov 19, 2021
1d3d7a0
clippy: resolve lints
nrdxp Nov 19, 2021
ef7e1f8
Cargo.lock: remove unused dependency
nrdxp Nov 19, 2021
bef8614
nix: ensure package and shell use same toolchain
nrdxp Nov 19, 2021
633b9bc
cargo: use thin lto
nrdxp Nov 19, 2021
e41fd9c
cargo: update deps
nrdxp Nov 19, 2021
5a6db26
flake: use self instead of ./.
nrdxp Nov 19, 2021
1d3a4f4
imp debugging
blaggacao Dec 1, 2021
f70cb4f
fix: fast connection
blaggacao Dec 3, 2021
fe35ea7
fmt: cargo fmt
nrdxp Dec 10, 2021
64ca7a8
flake.lock: update to rust 1.57.0
nrdxp Dec 10, 2021
55b397d
show copy progress
nrdxp Dec 10, 2021
0c02577
cargo: update deps
nrdxp Dec 10, 2021
7267eab
imp: apply source filter
blaggacao Dec 17, 2021
1c60c23
nix: ran nixfmt across flake.nix
craigem Feb 23, 2022
feb44f8
fenix: corrected inputs for fenix and nixpkgs
craigem Feb 23, 2022
dabb79d
build: show command output
nrdxp Aug 16, 2022
9e449da
invert rollback settings
nrdxp Aug 16, 2022
b086e4d
keep going on error
nrdxp Aug 16, 2022
f81eb2b
skip checks by default
nrdxp Aug 18, 2022
4da8eb9
export flake config in the environment
nrdxp Aug 22, 2022
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
Prev Previous commit
Next Next commit
imp(flags): make bools true bools
- This affords better help rendering (at the very least)
  • Loading branch information
blaggacao committed Nov 6, 2021
commit 50754605570ae32d3c1604d7b4a73a528c71e9b2
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

@@ -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

@@ -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";
}
```
4 changes: 2 additions & 2 deletions interface.json
Original file line number Diff line number Diff line change
@@ -21,10 +21,10 @@
"fastConnection": {
"type": "boolean"
},
"autoRollback": {
"noAutoRollback": {
"type": "boolean"
},
"magicRollback": {
"noMagicRollback": {
"type": "boolean"
},
"confirmTimeout": {
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -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(
@@ -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,
24 changes: 12 additions & 12 deletions src/deploy.rs
Original file line number Diff line number Diff line change
@@ -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,
@@ -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,
@@ -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);
}

@@ -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");

@@ -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
@@ -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()
2 changes: 1 addition & 1 deletion src/push.rs
Original file line number Diff line number Diff line change
@@ -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
18 changes: 11 additions & 7 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -29,12 +29,14 @@ pub struct GenericSettings {
pub ssh_opts: Vec<String>,
/// 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
#[serde(rename(deserialize = "fastConnection"), default)]
#[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"), default)]
#[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"))]
@@ -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"), default)]
#[merge(strategy = merge::bool::overwrite_false)]
pub no_magic_rollback: bool,
}

impl GenericSettings {