-
-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rust): Implement upgrade and uninstall commands #5171
base: develop
Are you sure you want to change the base?
feat(rust): Implement upgrade and uninstall commands #5171
Conversation
@BradLewis this is awesome, thank you for spending time on this. I'll try the commands and leave some thoughts soon |
3418080
to
c153f5c
Compare
Okay I've refactored the implementation quite a bit and improved the error handling as well. This split the upgrade and uninstall process for For upgrade:
For installation it follows a similar pattern, with everything being backed up and restored if anything goes wrong. Let me know what you think, and if you like this approach I'll open this as a non-draft PR 🙂 |
2b9ee3e
to
78760ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @BradLewis I left a bunch of comments and suggestions for you to consider. Next I would like to test your PR a bit on my machine to double-check that it is also working for me. How have you tested it so far?
if let Ok(r) = resp { | ||
if let Ok(upgrade) = r.json::<UpgradeFile>().await { | ||
if let Some(message) = upgrade.upgrade_message { | ||
eprintln!("\n{}", message.yellow()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use the opts.terminal
instead of eprintln
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also part of the original code that checked for the latest version from the version.json
file on GitHub, I just moved it to this file. I can refactor this as part of this PR as well if you would like.
I could also rework this to not use the version.json
file and instead just pull the latest version from the GitHub releases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can refactor this as part of this PR as well if you would like.
I see. Yes that would be nice. We are trying to move away from bare printlns
in order to completely control the rendering in the terminal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also rework this to not use the version.json file and instead just pull the latest version from the GitHub releases?
I don't understand that part. Are you talking about the upgrade.json
file? I actually tried to download it from https://github.com/build-trust/ockam/releases/download/ockam_v0.90.0/upgrade.json
and it comes back empty. Is that the same for you too? Because then this means that we also need to fix that part somewhere in our release process (FYI @metaclips)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah exactly. I mentioned it in the description for this PR, but I found that the upgrade.json
were never really up-to-date. You can play around with it by changing the version
in the Cargo.toml
file. Currently I only no suggestions for 0.89.0
, 0.88.0
and 0.87.0
. If I set it to 0.86.0
then it informs me that there is an update available, but that the latest version is 0.87.0
.
Currently it pulls this information from the release of the version that the user is using, meaning these files would need to be updated every release to be effective.
That's why I ended up just pulling the latest version from the release instead of just using the version.json
file.
78760ec
to
8feee2a
Compare
9f82eeb
to
f8f4e2a
Compare
So for testing I've been setting the version to something lower, eg From there I just make sure all the nodes have restarted and if it was installed via the script, that all the environment files were updated correctly. I will say this is definitely one that needs to be tested thoroughly given all the changes it can make on the end users machine. I split the logic into 3 flows (installation via One thing I haven't been able to test is the upgrade via |
fn upgrade_check_is_disabled() -> bool { | ||
get_env_with_default("OCKAM_DISABLE_UPGRADE_CHECK", false).unwrap_or(false) | ||
fn upgrade_ockam(opts: &CommandGlobalOpts) -> miette::Result<()> { | ||
let stopped_nodes_names = stop_all_running_nodes(opts)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be safer to move this at least after let installer = get_installer(opts)?;
? Or, even better, right before restarting the nodes. I'm not sure what will happen to running processes after doing the upgrade (are they killed after removing the current binary version?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if you run the upgrade without stopping the nodes, everything will still be running, so we could only do the restart cycle after the upgrade has run successfully just to ensure the nodes get upgraded to the latest version.
As an aside to this, with all the changes made with the nodes logic since the 0.90.0
release, the nodes will no longer be restarted correctly on this branch. I'm pretty sure this is just due to the nodes trying to be restarted with the 0.90.0
version after you run the upgrade? I created a new branch https://github.com/BradLewis/ockam/tree/bradlewis/upgrade-test that is just sitting on the latest release just to test this and everything is restarted as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting... can you share more details on how to reproduce the restart problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
- Create a node using
ockam node create n
using any version ofockam
. - Change the version in the
Cargo.toml
file forockam_command
to something below0.90.0
. - Run
cargo run upgrade --yes
to "upgrade" the ockam binary to the latest version. This should just replace the one intarget/debug/ockam
with the latest one from github. - Everything appears to run smoothly, however if you run
cargo run node list
, you'll see that the node is stopped.
I'm pretty sure this is because it's trying to restart the nodes using the 0.90.0
release binary, but the "new" nodes are not compatible with that version.
If you run ockam node list
you'll see that it thinks there are no nodes on the system
❯ ockam node list
┌───────────────────┐
│ Nodes │
└───────────────────┘
! No nodes found on this system.
❯ cargo run node list
Finished dev [unoptimized + debuginfo] target(s) in 0.20s
Running `/Users/bradlewis/repos/ockam/target/debug/ockam node list`
┌───────────────────┐
│ Nodes │
└───────────────────┘
│ Node n (default) UP
│ Process id 21821
│ Node m UP
│ Process id 22503
You can also easily reproduce this behaviour by first creating a node with release 0.90.0
, then a new one with cargo run
and then listing the nodes
❯ ockam node create n
Creating Node n...
✔︎ Node n created successfully
To see more details on this node, run:
ockam node show
❯ ockam node list
┌───────────────────┐
│ Nodes │
└───────────────────┘
│ Node n (default) UP
│ Process id 26852
❯ cargo run node create m
Finished dev [unoptimized + debuginfo] target(s) in 0.20s
Running `/Users/bradlewis/repos/ockam/target/debug/ockam node create m`
Creating Node m...
✔︎ Node m created successfully
To see more details on this node, run:
ockam node show
❯ cargo run node list
Finished dev [unoptimized + debuginfo] target(s) in 0.20s
Running `/Users/bradlewis/repos/ockam/target/debug/ockam node list`
┌───────────────────┐
│ Nodes │
└───────────────────┘
│ Node n (default) UP
│ Process id 26852
│ Node m UP
│ Process id 27086
❯ ockam node list
┌───────────────────┐
│ Nodes │
└───────────────────┘
! No nodes found on this system.
Given all this I imagine what's happening is that when the nodes are trying to be restarted, they are trying to be restarted with the 0.90.0
binary, but the 0.90.0
binary doesn't see the nodes so nothing happens. Not sure why there isn't any error though.
If I run this all instead on my other branch I created, everything works as you would expect.
f9dd663
to
ded8afc
Compare
ded8afc
to
991c88d
Compare
991c88d
to
ee3a09e
Compare
I've created this as a draft PR for now to get your feedback on this approach. It probably needs more work with things like the error handling and the messages, but I figured it'd be worthwhile getting feedback on the more "happy" paths before working on making that better. Let me know what you think!
Current behavior
Currently there is no way for the user to upgrade or uninstall
ockam
directly through the binary.Proposed changes
Resolves #4916
This PR adds both an
upgrade
anduninstall
command.Upgrade
For the upgrade command it works as follows:
homebrew
. If it was it runsbrew upgrade ockam
. It will then restart all the nodes it stopped in step 2.install.sh
script it will check to see if it can find location of the script by looking at$OCKAM_HOME
or$HOME/.ockam
. If it can't find it then it stops the upgrade.ockam
binary.ockam
using theinstall.sh
script, specifying the specific version and the install path.In order to do this I made some slight changes, namely writing the
install.sh
script to the $OCKAM_HOME folder, and add the$OCKAM_HOME
variable to the environment variable files.I also implemented some logic to fetch the latest versions from the releases on github rather than the
upgrade.json
file as I found that theupgrade.json
file seems to be out of date? (0.87.0
and0.88.0
are empty, and0.86.0
points to0.87.0
etc). Not sure if this is intentional however.Uninstall
For the
uninstall
command,install.sh
script or withhomebrew
.homebrew
, it'll runbrew uninstall ockam
, otherwise it'll delete theockam
binary.$OCKAM_HOME
and then delete the$OCKAM_HOME
directory.I'm not sure about this final step however as it'll delete all the metadata on nodes and whatnot the user has, which could be troublesome if they just wanted to do a simple uninstall/reinstall to fix an issue or something. Let me know what you think of that.
Checks