Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
49 lines (39 loc) · 1.74 KB
/
Copy pathDockerfile
File metadata and controls
49 lines (39 loc) · 1.74 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
# -------------------------------------------------------------------
# Stage 1: Build binary with cargo
# -------------------------------------------------------------------
FROM rust:1.98.1-bookworm AS builder
WORKDIR /usr/src/app
# Copy dependency specifications first to leverage Docker layer caching
COPY Cargo.toml Cargo.lock ./
RUN mkdir src \
&& echo "fn main() {}" > src/main.rs \
&& echo "" > src/lib.rs \
&& cargo build --release --locked \
&& rm -rf src
# Copy source code and build actual binary
COPY src ./src
RUN touch src/main.rs src/lib.rs && cargo build --release --locked
# -------------------------------------------------------------------
# Stage 2: Minimal runtime image
# -------------------------------------------------------------------
FROM debian:bookworm-slim AS runtime
WORKDIR /app
# Install CA certificates and tzdata for secure HTTPS/WSS connections to Binance
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
&& rm -rf /var/lib/apt/lists/*
# Copy compiled binary from builder
COPY --from=builder /usr/src/app/target/release/binance-grid-bot /app/binance-grid-bot
# Ensure data directory for SQLite persistence
RUN groupadd --system --gid 10001 bot \
&& useradd --system --uid 10001 --gid 10001 --no-create-home --home-dir /app --shell /usr/sbin/nologin bot \
&& install -d -m 0700 -o 10001 -g 10001 /app/data
VOLUME ["/app/data"]
USER 10001:10001
# Expose web dashboard port
EXPOSE 8080
ENV RUST_LOG="binance_grid_bot=info"
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 CMD ["/app/binance-grid-bot", "--db", "/app/data/bot.db", "healthcheck"]
ENTRYPOINT ["/app/binance-grid-bot"]
CMD ["--db", "/app/data/bot.db", "--host", "0.0.0.0"]