Auto-Updater
The Packager includes support for auto updates for Rust and Node.js applications by providing APIs for your application to securely update itself by fetching new releases on a remote server, installing updates and restarting itself.
Signing Keys
To securely deliver updates, the Packager signs your application generating a signature that is verified by the updater.
To generate a new keypair, use the CLI signer generate
command:
The command will prompt you for the keypair password.
Do not lose that password, you will need to define it as the CARGO_PACKAGER_SIGN_PRIVATE_KEY_PASSWORD
environment variable for the packager to sign your update packages.
After generating the keys, the CLI prints the private key and the public key.
The private key must be defined as the CARGO_PACKAGER_SIGN_PRIVATE_KEY
environment variable
and must be treated as a secret, DO NOT share it, if it is compromised you will need to replace it immediately.
Along with the private key, the CLI also prints the public key that must be configured in the application to verify updates. The configuration object is documented later in this guide.
Rust
To configure the updater for your Rust application, add the cargo-packager-updater
crate:
Start off by importing packager updater:
Create the updater configuration object, with the endpoint of the remote server hosting your app updates and your signing public key and use the cargo_packager_updater::check_update
API to fetch an update if there is one:
Check out the complete configuration documentation.
Node.js
To configure the updater for your Node.js application, install the @crabnebula/updater
package:
Create the updater configuration object, with the endpoint of the remote server hosting your app updates and your signing public key:
Check out the complete configuration documentation.
Use the checkUpdate
API to fetch an update if there is one:
Configuration
The updater configuration object allows you to define a list of endpoints to connect,
Endpoints
The endpoints
required configuration is a list of URLs that are used to check if a new update is available.
The endpoints are queried in order until a valid response is found (subsequent URLs are used as fallback in case the first one cannot be reached).
Each endpoint can use the {{arch}}
, {{target}}
or {{current_version}}
variables
which are detected and replaced with the appropriate values before making a request to the endpoint:
{{current_version}}
: The version of the app that is requesting the update.{{target}}
: The operating system name (one oflinux
,windows
ormacos
).{{arch}}
: The architecture of the machine (one ofx86_64
,i686
,aarch64
orarmv7
).
for example https://releases.myapp.com/{{target}}/{{arch}}/{{current_version}}
can evaluate to https://releases.myapp.com/windows/x86_64/0.1.0
.
Pubkey
The pubkey
is a required configuration that defines the public key generated with the signer generate
Packager CLI command.
It is used to verify the authenticity of the update, ensuring it was built using your private key.
Windows
Under the windows
object you can define the installerArgs
, a list of string arguments that are given to the NSIS or WiX installers, and the installMode
, an enum (one of basicUi
, quiet
and passive
) which furthers configure the installer (defaults to passive
, a mode that does not require the user to interact with the update installation).