How to Deploy Applications

A Salvo project, after compilation, becomes an executable file. For deployment, you only need to upload this executable along with its dependent static resources to the server.

For Rust-based projects, there is also a very simple deployment platform: shuttle.rs. Shuttle provides support for Salvo-like projects. For details, please refer to the official documentation.

Docker Deployment

You can also use Docker to deploy Salvo applications. Below is a basic Dockerfile example, which you can adjust according to your project's requirements:

# Build stage
FROM rust:slim AS build
WORKDIR /app

# Copy dependency files first to build dependencies (leveraging cache layers)
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && \
    echo 'fn main() { println!("Placeholder"); }' > src/main.rs && \
    cargo build --release

# Copy actual source code and build the application
COPY src ./src/
RUN touch src/main.rs && \
    cargo build --release

# Use a lightweight base image for the runtime stage
FROM debian:bookworm-slim
RUN apt-get update && \
    apt-get install -y --no-install-recommends ca-certificates && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Create a non-root user to run the application
RUN useradd -ms /bin/bash appuser
USER appuser
WORKDIR /app

# Copy the binary file from the build stage
COPY --from=build /app/target/release/your_app_name ./app

# Set the container startup command
CMD ["./app"]

Usage Instructions

  1. Save the above Dockerfile in your project's root directory.
  2. Adjust your_app_name to the actual binary file name according to your project.
  3. If your application requires static files (such as templates, CSS, JS, etc.), you can add corresponding COPY commands.
  4. If your application requires environment variable configuration, you can use the ENV instruction.
  5. Build the Docker image:
    docker build -t your-app-name .
  6. Run the container:
    docker run -p 8698:8698 your-app-name

Please adjust the port number and other configurations according to your application's actual needs.