Skip to content

Packager

On this page you will find an overview of how to configure Packager auto-updater with CrabNebula Cloud. This will allow you to automatically update your application as soon as you publish a new release on Cloud without having to manually handle the update process.

Packager includes a built-in updater which can be configured to automatically update your application as soon as you publish a new release on Cloud.

Start off by adding the cargo-packager-updater dependency to your project:

Terminal window
cargo add cargo-packager-updater

Afterwards you need to generate a cryptographic key pair which will be used to verify the integrity of the update. New updates will be signed with the private key and the public key will be used to confirm the integrity of the update.

Terminal window
cargo packager signer generate

Save the private key in a secure location as it will be used to sign the new release when you publish it. For the configuration of the updater code you will only need the public key.

In your Rust project navigate to the specific file where you want to add the updater code and add the following imports:

use cargo_packager_updater::{semver::Version, url::Url};

Now add the following code:

let config = cargo_packager_updater::Config {
endpoints: vec![Url::parse("https://cdn.crabnebula.app/update/YOUR_ORG_SLUG/YOUR_APP_SLUG/{{target}}-{{arch}}/{{current_version}}").expect("Failed to parse URL")], // REPLACE: YOUR_ORG_SLUG and YOUR_APP_SLUG of the app in CN Cloud
pubkey: String::from("YOUR_PUBLIC_KEY"), // REPLACE: YOUR_PUBLIC_KEY generated by the signer
..Default::default()
};
let current_version =
Version::parse(env!("CARGO_PKG_VERSION")).expect("Failed to parse version");
println!("Current version: {}", current_version);
if let Some(update) = cargo_packager_updater::check_update(current_version.clone(), config)
.expect("Failed to check for update")
{
update
.download_and_install()
.expect("Failed to download and install update");
println!("Update installed")
} else {
println!("No update available")
}

Make sure to replace YOUR_ORG_SLUG and YOUR_APP_SLUG with the slug of your organization and app on Cloud. Also replace YOUR_PUBLIC_KEY with the public key generated by the signer.

Now as soon as that code is run, the updater will check for updates and if a new update is available, it will be downloaded and installed automatically.