-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (54 loc) · 2 KB
/
Dockerfile
File metadata and controls
72 lines (54 loc) · 2 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# =============================================================================
# Stage 1: Build
# =============================================================================
FROM rust:1.92-trixie AS builder
WORKDIR /usr/src/monocle
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Copy manifests first for better layer caching
COPY Cargo.toml Cargo.lock ./
# Create a dummy main and lib to build dependencies
RUN mkdir -p src/bin && \
echo 'fn main() { println!("dummy"); }' > src/bin/monocle.rs && \
echo '#![allow(dead_code)]' > src/lib.rs
# Build dependencies only (this layer will be cached)
# Must use same features as final build
RUN cargo build --release --features cli || true
RUN rm -rf src
# Copy the actual source code
COPY src ./src
COPY examples ./examples
COPY README.md ./
# Touch the source files to ensure they're rebuilt
RUN touch src/lib.rs src/bin/monocle.rs
# Build the actual binary
RUN cargo build --release --features cli
# =============================================================================
# Stage 2: Runtime
# =============================================================================
FROM debian:trixie-slim AS runtime
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user for security
RUN useradd --create-home --shell /bin/bash monocle
# Create data directory
RUN mkdir -p /data && \
chown -R monocle:monocle /data
# Copy the binary from builder
COPY --from=builder /usr/src/monocle/target/release/monocle /usr/local/bin/monocle
# Switch to non-root user
USER monocle
WORKDIR /home/monocle
# Set environment variables
ENV MONOCLE_DATA_DIR=/data
# Define volume for persistent data
VOLUME ["/data"]
# Expose the default server port
EXPOSE 8080
# Default command shows help; override with your desired command
ENTRYPOINT ["monocle"]
CMD ["--help"]