Agent Skillsnixopus/nixopus › rust-deploy

rust-deploy

GitHub

提供 Rust 应用的构建与部署指南,涵盖版本检测、二进制编译、端口识别及多种 Dockerfile 模板(含 Cargo Chef 优化),用于自动化发布流程。

api/skills/rust-deploy/SKILL.md nixopus/nixopus

Trigger Scenarios

用户询问如何部署 Rust 项目 检测到 Cargo.toml 文件

Install

npx skills add nixopus/nixopus --skill rust-deploy -g -y
More Options

Non-standard path

npx skills add https://github.com/nixopus/nixopus/tree/master/api/skills/rust-deploy -g -y

Use without installing

npx skills use nixopus/nixopus@rust-deploy

指定 Agent (Claude Code)

npx skills add nixopus/nixopus --skill rust-deploy -a claude-code -g -y

安装 repo 全部 skill

npx skills add nixopus/nixopus --all -g -y

预览 repo 内 skill

npx skills add nixopus/nixopus --list

SKILL.md

Frontmatter
{
    "name": "rust-deploy",
    "metadata": {
        "version": "1.0"
    },
    "description": "Build and deploy Rust applications — version detection, release binaries, cargo-chef, and Dockerfile patterns. Use when deploying a Rust project, or when Cargo.toml is detected."
}

Rust Deployment

Detection

Project is Rust if Cargo.toml or cargo.toml exists.

Versions

Rust version priority:

  1. rust-toolchain.tomltoolchain.channel
  2. Cargo.tomlpackage.rust-version
  3. .rust-version file
  4. Cargo.tomlpackage.edition (maps to minimum Rust version)
  5. Defaults to latest stable (1.89)

Build

Build Command

  • cargo build --release
  • Binary: target/release/<package-name>
  • Package name from Cargo.toml[package].name

Entry Resolution

  1. Binary crate: src/main.rs
  2. Multi-binary: src/bin/<name>.rs → binary name matches filename
  3. Library + binary: [bin] section in Cargo.toml

Output

  • Build output: target/release/<name>
  • Start command: ./bin/<project-name> or ./target/release/<name>

Runtime Variables

Variable Purpose
ROCKET_ADDRESS Rocket bind address (use 0.0.0.0 for containers)
PORT Port for web servers (default 8080)

Port Detection

  1. PORT in .env / .env.example
  2. Source code patterns: :8080, bind, TcpListener in main.rs
  3. Default: 8080

Framework / Library Detection

Crate Category
axum Web
actix-web Web
rocket Web
warp Web
tokio Async runtime
tower Middleware

Install Stage Optimization

Copy in order:

  • Cargo.toml, Cargo.lock
  • src/ (or full source)

BuildKit Caching

Cache key Path
cargo_registry ~/.cargo/registry
cargo_git ~/.cargo/git
cargo_target target/

Base Images

Stage Image
Build rust:1.89-bookworm or rust:1.89-alpine
Runtime debian:bookworm-slim or gcr.io/distroless/cc

For Alpine build: may need musl-dev for fully static binary.

Dockerfile Patterns

Multi-Stage (Debian)

FROM rust:1.89-bookworm AS build
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
COPY src ./src
RUN touch src/main.rs && cargo build --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/target/release/<binary-name> .
EXPOSE 8080
CMD ["./<binary-name>"]

Cargo Chef (faster layer cache)

FROM rust:1.89-bookworm AS chef
RUN cargo install cargo-chef

FROM chef AS planner
WORKDIR /app
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS build
WORKDIR /app
COPY --from=planner /app/recipe.json .
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/target/release/<binary-name> .
EXPOSE 8080
CMD ["./<binary-name>"]

Simple (no chef)

FROM rust:1.89-bookworm AS build
WORKDIR /app
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/target/release/<binary-name> .
EXPOSE 8080
CMD ["./<binary-name>"]

Gotchas

  • The dummy main.rs trick (echo "fn main() {}" > src/main.rs) caches dependency compilation, but touch src/main.rs is needed afterward to invalidate the binary build cache
  • Cargo.lock must be committed for binary crates — without it, dependency versions are resolved fresh on every build
  • Alpine builds need musl-dev, but crates using OpenSSL also need openssl-dev and pkgconfig
  • Rust builds are memory-intensive — cargo build --release -j 2 limits parallelism to avoid OOM kills in resource-constrained environments
  • Cargo chef prepare requires the full source tree — it scans code to compute the dependency recipe

Version History

  • cf05d97 Current 2026-08-20 14:52

Same Skill Collection

api/skills/api-catalog/SKILL.md
api/skills/caddyfile-generation/SKILL.md
api/skills/compose-setup/SKILL.md
api/skills/container-resource-tuning/SKILL.md
api/skills/cpp-deploy/SKILL.md
api/skills/database-migration/SKILL.md
api/skills/deno-deploy/SKILL.md
api/skills/deploy-delegation/SKILL.md
api/skills/deploy-flow/SKILL.md
api/skills/deployment-analysis/SKILL.md
api/skills/diagnostic-workflow/SKILL.md
api/skills/dockerfile-generation/SKILL.md
api/skills/dockerignore-generation/SKILL.md
api/skills/domain-attachment/SKILL.md
api/skills/domain-tls-routing/SKILL.md
api/skills/dotnet-deploy/SKILL.md
api/skills/elixir-deploy/SKILL.md
api/skills/failure-diagnosis/SKILL.md
api/skills/github-onboarding/SKILL.md
api/skills/github-workflow/SKILL.md
api/skills/gleam-deploy/SKILL.md
api/skills/go-deploy/SKILL.md
api/skills/incident-response/SKILL.md
api/skills/java-deploy/SKILL.md
api/skills/machine-ops/SKILL.md
api/skills/mcp-integrations/SKILL.md
api/skills/monorepo-strategy/SKILL.md
api/skills/nixopus-docs/SKILL.md
api/skills/node-deploy/SKILL.md
api/skills/onboarding/SKILL.md
api/skills/php-deploy/SKILL.md
api/skills/post-deploy-verification/SKILL.md
api/skills/pre-deploy-checklist/SKILL.md
api/skills/python-deploy/SKILL.md
api/skills/rollback-strategy/SKILL.md
api/skills/ruby-deploy/SKILL.md
api/skills/self-heal/SKILL.md
api/skills/shell-deploy/SKILL.md
api/skills/static-deploy/SKILL.md

Metadata

Files
0
Version
cf05d97
Hash
b7adbdde
Indexed
2026-08-20 14:52

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-29 23:16
浙ICP备14020137号-1 $방문자$