-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (42 loc) · 1.16 KB
/
Dockerfile
File metadata and controls
58 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Multi-stage build for minimal final image
FROM rust:1.89-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create a new empty project
WORKDIR /app
# Copy manifests
COPY Cargo.toml Cargo.lock ./
# Copy source code
COPY src ./src
COPY examples ./examples
COPY tests ./tests
# Build the application in release mode
RUN cargo build --release
# Runtime stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN useradd -m -u 1000 appuser
WORKDIR /app
# Copy the binary from builder
COPY --from=builder /app/target/release/template-rust /usr/local/bin/template-rust
# Change ownership
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Set default database path
ENV DATABASE_URL=/app/data/todo.db
# Create data directory
RUN mkdir -p /app/data
# Expose any necessary ports (if needed for future web features)
# EXPOSE 8080
# Set the default command
ENTRYPOINT ["template-rust"]
CMD ["--help"]