add Dockerfile
This commit is contained in:
45
Dockerfile
Normal file
45
Dockerfile
Normal 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"]
|
||||||
@@ -10,6 +10,7 @@ A production-ready template for building web services with Rust and Axum.
|
|||||||
- **Graceful Shutdown** - Handles SIGTERM and SIGINT signals
|
- **Graceful Shutdown** - Handles SIGTERM and SIGINT signals
|
||||||
- ️**Plugin Architecture** - Modular app initialization with `axum-app-wrapper`
|
- ️**Plugin Architecture** - Modular app initialization with `axum-app-wrapper`
|
||||||
- **Optional OpenAPI** - API documentation with `aide` (optional)
|
- **Optional OpenAPI** - API documentation with `aide` (optional)
|
||||||
|
- **Docker / OCI** - Dockerfile with sensible defaults for quick deployment
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user