|
1 | 1 | # Multi-stage build for SolverForge Employee Scheduling (Rust) |
2 | 2 | # |
3 | | -# Build context should be the parent directory containing both: |
4 | | -# - solverforge-rs/ |
5 | | -# - solverforge-quickstarts/ |
6 | | -# |
7 | | -# Example: |
8 | | -# docker build -f solverforge-quickstarts/rust/employee-scheduling/Dockerfile \ |
9 | | -# -t employee-scheduling-rust . |
10 | | - |
11 | | -FROM rust:1.83-bookworm AS builder |
| 3 | +# Build context: rust/employee-scheduling/ |
| 4 | +# Uses published solverforge crate from crates.io |
12 | 5 |
|
13 | | -WORKDIR /build |
| 6 | +FROM rust:1.83-alpine AS builder |
14 | 7 |
|
15 | | -# Copy solverforge-rs workspace (local dependency) |
16 | | -COPY solverforge-rs/ ./solverforge-rs/ |
| 8 | +# Install build dependencies |
| 9 | +RUN apk add --no-cache musl-dev |
17 | 10 |
|
18 | | -# Copy quickstarts |
19 | | -COPY solverforge-quickstarts/rust/employee-scheduling/ ./solverforge-quickstarts/rust/employee-scheduling/ |
| 11 | +WORKDIR /build |
20 | 12 |
|
21 | | -WORKDIR /build/solverforge-quickstarts/rust/employee-scheduling |
| 13 | +# Copy workspace files |
| 14 | +COPY Cargo.toml Cargo.lock ./ |
| 15 | +COPY src/ ./src/ |
| 16 | +COPY static/ ./static/ |
| 17 | +COPY solver.toml ./ |
22 | 18 |
|
23 | | -# Build release binary |
24 | | -RUN cargo build --release |
| 19 | +# Build release binary with musl target for static linking |
| 20 | +RUN cargo build --release --target x86_64-unknown-linux-musl |
25 | 21 |
|
26 | | -# Runtime stage - minimal image |
27 | | -FROM debian:bookworm-slim |
| 22 | +# Runtime stage - minimal Alpine image |
| 23 | +FROM alpine:latest |
28 | 24 |
|
29 | | -RUN apt-get update && \ |
30 | | - apt-get install -y --no-install-recommends ca-certificates && \ |
31 | | - rm -rf /var/lib/apt/lists/* |
| 25 | +RUN apk add --no-cache ca-certificates |
32 | 26 |
|
33 | 27 | WORKDIR /app |
34 | 28 |
|
35 | | -# Copy binary from builder |
36 | | -COPY --from=builder /build/solverforge-quickstarts/rust/employee-scheduling/target/release/employee-scheduling ./employee-scheduling |
| 29 | +# Copy binary from builder (musl static binary) |
| 30 | +COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/employee-scheduling ./employee-scheduling |
37 | 31 |
|
38 | 32 | # Copy static files |
39 | | -COPY --from=builder /build/solverforge-quickstarts/rust/employee-scheduling/static/ ./static/ |
| 33 | +COPY --from=builder /build/static/ ./static/ |
40 | 34 |
|
41 | 35 | # Copy solver config |
42 | | -COPY --from=builder /build/solverforge-quickstarts/rust/employee-scheduling/solver.toml ./solver.toml |
| 36 | +COPY --from=builder /build/solver.toml ./solver.toml |
43 | 37 |
|
44 | 38 | # Expose port 7860 (HF Spaces default) |
45 | 39 | EXPOSE 7860 |
|
0 commit comments