Skip to content

[Feature] Rust running environment #8875

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

Open
ExquisiteCore opened this issue May 29, 2025 · 5 comments
Open

[Feature] Rust running environment #8875

ExquisiteCore opened this issue May 29, 2025 · 5 comments
Assignees

Comments

@ExquisiteCore
Copy link
Contributor

1Panel Version

v1.10.29-lts

Please describe your needs or suggestions for improvements

希望运行环境加入rust

Please describe the solution you suggest

No response

Additional Information

No response

@wanghe-fit2cloud wanghe-fit2cloud changed the title [Feature] Rust运行环境 [Feature] Rust running environment May 29, 2025
@wanghe-fit2cloud
Copy link
Member

我们先调研一下具体的可行方案,后续版本考虑是否支持该功能。

如果你之前有容器化部署 Rust 项目的经验,也欢迎分享你的环境配置和使用教程。

@ExquisiteCore
Copy link
Contributor Author

非常感谢,我的后端基本上都使用axum进行了重构,我很需要这个功能

@ExquisiteCore
Copy link
Contributor Author

以下是一个docker运行rust项目的简单例子

1. 准备 Rust 项目

cargo new my_rust_app
cd my_rust_app
echo 'fn main() { println!("Hello from Docker!"); }' > src/main.rs

2. 创建 Dockerfile

# 使用官方 Rust 镜像作为构建环境
FROM rust:1.73-slim AS builder

# 设置工作目录
WORKDIR /app

# 复制项目文件
COPY . .

# 构建 Release 版本
RUN cargo build --release

# 使用轻量级运行时镜像
FROM debian:bookworm-slim

# 从构建阶段复制二进制文件
COPY --from=builder /app/target/release/my_rust_app /usr/local/bin

# 设置容器启动命令
CMD ["my_rust_app"]

3. 构建 Docker 镜像

docker build -t rust-app .

4. 运行容器

docker run --rm rust-app
# 输出: Hello from Docker!

这是我个人rust项目的Dockerfile(供参考)

# Multi-stage build for Rust backend 
 FROM rust:1.86.0-slim AS chef 
 RUN cargo install cargo-chef 
 WORKDIR /app 
  
 FROM chef AS planner 
 COPY . . 
 RUN cargo chef prepare --recipe-path recipe.json 
  
 FROM chef AS builder 
 COPY --from=planner /app/recipe.json recipe.json 
  
 # Install system dependencies 
 RUN apt-get update && apt-get install -y \ 
     pkg-config \ 
     libssl-dev \ 
     ca-certificates \ 
     && rm -rf /var/lib/apt/lists/* 
  
 # Build dependencies - this layer is cached 
 RUN cargo chef cook --release --recipe-path recipe.json 
  
 # Copy source code and build application 
 COPY . . 
 RUN cargo build --release 
  
 # Runtime stage 
 FROM debian:bookworm-slim AS runtime 
  
 # Install runtime dependencies 
 RUN apt-get update && apt-get install -y \ 
     ca-certificates \ 
     libssl3 \ 
     curl \ 
     && rm -rf /var/lib/apt/lists/* \ 
     && apt-get clean 
  
 # Create non-root user 
 RUN groupadd -r bloguser && useradd -r -g bloguser bloguser 
  
 WORKDIR /app 
  
 # Copy binary and config 
 COPY --from=builder /app/target/release/backend /app/backend 
 COPY --from=builder /app/config.docker.toml /app/config.toml 
  
 # Set ownership 
 RUN chown -R bloguser:bloguser /app 
 USER bloguser 
  
 EXPOSE 8080 
  
 # Health check 
 HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ 
     CMD curl -f http://localhost:8080/health || exit 1 
  
 CMD ["./backend"] 
  
 # Production optimized stage 
 FROM runtime AS production 
 ENV RUST_LOG=info 
 ENV RUST_BACKTRACE=0

@ExquisiteCore
Copy link
Contributor Author

@wanghe-fit2cloud 王哥请问一下,如果需要实现这个功能应该怎么做,直接修改前端部分吗,我没有找到go这边的相应代码

@wanghe-fit2cloud
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@wanghe-fit2cloud Brother Wang, what should I do if I need to implement this function? Do I directly modify the front-end part? I didn’t find the corresponding code on go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants