Deploying Rust Applications
Zeabur supports all types of Rust applications in principle—it will automatically look for executables by default. If your project has multiple executables, you can specify the executable file name in the "Service Name" field (or use ZBPACK_RUST_ENTRY
).
If you don't have a project on hand, you can fork the zeabur/axum-template (opens in a new tab) repository to your GitHub account and try deploying it on Zeabur.
Supported Project Types
- Single Executable Project: A Rust project with only
src/main.rs
as the entry point. Zeabur will automatically find the first executable produced aftercargo install
. - Multiple Executables Project: If your project has other executables in
src/bin
besidessrc/main.rs
, specify the name of the final artifact you want to run in the "Service Name" field or configure it inzbpack.json
:You can also use the environment variable{ "rust": { "entry": "your-entry" } }
ZBPACK_RUST_ENTRY
to achieve the same effect. - Cargo Workspace Monorepo: If your project consists of multiple crates, specify the name of the final artifact you want to run in the "Service Name" field. By default,
cargo install
will install all projects under the workspace. Besides using the aboveZBPACK_RUST_ENTRY
method to specify the executable name, you can also directly specify the location of this application workspace inzbpack.json
. If your application is in therest-api
folder at the repository root directory, you can configure it as follows:You can also use the environment variable{ "rust": { "app_dir": "rest-api" } }
ZBPACK_RUST_APP_DIR
to achieve the same effect.
If the specified executable does not exist, it will default to auto-detection mode. "Auto-detection" will look for all compiled executables and run the first found file. Because this mode can easily guess wrong in multi-project scenarios, it's recommended to specify the correct "Service Name" for more complex project scenarios. Check the following section for how to find and specify it.
Finding the Final Artifact Name
The final artifact can be found in target/release
of your project. To find the filename:
-
You need the Rust toolchain to compile the project. Download it from the official Rust website (opens in a new tab).
-
Clone the project you want to deploy and navigate to the project directory.
-
Run
cargo build --release
to compile the project.$ cargo run --release Compiling zeabur v0.1.0 (/project) Finished release [optimized] target(s) in 0.65s Running `target/release/zeabur`
-
Find the line Running
target/release/zeabur
, extract the final executable name (zeabur). -
Fill in
zeabur
in the Service Name orZBPACK_RUST_ENTRY
.
Copying Other Files
If your project relies on other files in the codebase besides the executable. For example:
*
|`-- public <-- Your program depends on this folder
|`-- src
| `-- main.rs
|`-- Cargo.toml
|`-- Cargo.lock
`--- config.toml <-- Your program depends on this file
You can specify rust.assets
in zbpack.json
, listing the folders or files you want to keep. Folders should end with /
. Example:
{
"rust": {
"assets": [
"public/",
"config.toml"
]
}
}
Automatic Dependency Installation
If your project depends on OpenSSL and explicitly specifies it in Cargo.toml
(or indirectly depends on it via Cargo.lock
), Zeabur will automatically install the openssl
runtime library.
Runtime Environment
Zeabur currently uses rust:1-silm
(opens in a new tab) as the runtime image. Your executable will be placed in the /app
directory, with /
(root directory) as the working directory.
Serverless Deployment
Unlike other PaaS platforms that run your Rust application inside a Docker container directly, Zeabur also supports deploying Rust applications using the Serverless deployment method. This allows your Rust application to start only when it receives a request, instead of running continuously like a container, saving resources.
To deploy a Rust application using Serverless, add ZBPACK_SERVERLESS=1
to the environment variables.