add Dockerfile

This commit is contained in:
fa-sharp
2026-02-22 02:24:28 -05:00
parent 13918f65ad
commit 594e15a768
2 changed files with 46 additions and 0 deletions

45
Dockerfile Normal file
View File

@@ -0,0 +1,45 @@
# Image versions (can be overridden by args when building)
ARG RUST_VERSION=1.90
ARG DEBIAN_VERSION=bookworm
### Build server ###
FROM rust:${RUST_VERSION}-slim-${DEBIAN_VERSION} AS build
WORKDIR /app
# Copy all necessary files to build the server
COPY Cargo.lock Cargo.toml ./
COPY ./src ./src
# COPY ./migrations ./migrations
# etc...
ARG pkg={{project-name}}
RUN --mount=type=cache,id=rust_target,target=/app/target \
--mount=type=cache,id=cargo_registry,target=/usr/local/cargo/registry \
--mount=type=cache,id=cargo_git,target=/usr/local/cargo/git \
set -eux; \
cargo build --package $pkg --release --locked; \
objcopy --compress-debug-sections target/release/$pkg ./run-server
### Run server ###
FROM debian:${DEBIAN_VERSION}-slim AS run
# Create non-root user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/appuser" \
--shell "/sbin/nologin" \
--uid "${UID}" \
appuser
USER appuser
# Copy server binary
COPY --from=build --chown=appuser /app/run-server /usr/local/bin/
# Run server
WORKDIR /app
ENV {{env_prefix}}_HOST=0.0.0.0
CMD ["run-server"]

View File

@@ -10,6 +10,7 @@ A production-ready template for building web services with Rust and Axum.
- **Graceful Shutdown** - Handles SIGTERM and SIGINT signals
- **Plugin Architecture** - Modular app initialization with `axum-app-wrapper`
- **Optional OpenAPI** - API documentation with `aide` (optional)
- **Docker / OCI** - Dockerfile with sensible defaults for quick deployment
## Usage