-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (60 loc) · 2.52 KB
/
Copy pathDockerfile
File metadata and controls
81 lines (60 loc) · 2.52 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
73
74
75
76
77
78
79
80
81
# Multi-stage Dockerfile for Charcoal on Railway.
#
# Stage 1: Build (Rust + Node.js on Ubuntu 24.04 for glibc 2.39)
# Stage 2: Runtime (slim image with just the binary)
#
# Ubuntu 24.04 provides glibc 2.39 which satisfies ort-sys's requirement
# for __isoc23_strtoll (glibc 2.38+).
# ── Build stage ──────────────────────────────────────────────────────
FROM ubuntu:24.04 AS builder
ENV DEBIAN_FRONTEND=noninteractive
# Install build dependencies + Node 22 via nodesource
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
build-essential \
pkg-config \
libssl-dev \
ca-certificates \
git \
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.94.0
ENV PATH="/root/.cargo/bin:${PATH}"
WORKDIR /app
# Copy dependency manifests first for layer caching
COPY Cargo.toml Cargo.lock ./
COPY web/package.json web/package-lock.json ./web/
# Create a dummy src so cargo can resolve dependencies
RUN mkdir src && echo 'fn main() {}' > src/main.rs && \
mkdir -p src/web && touch src/lib.rs
# Pre-fetch Cargo dependencies (cached unless Cargo.toml/lock changes)
RUN cargo fetch --locked
# Install Node dependencies (cached unless package.json/lock changes)
RUN cd web && npm ci
# Copy the full source
COPY . .
# Build SvelteKit SPA first (include_dir! embeds it at compile time)
RUN cd web && npm run build
# Build the release binary
RUN cargo build --release --features web,postgres
# ── Runtime stage ────────────────────────────────────────────────────
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# Runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libssl3t64 \
libstdc++6 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy the built binary
COPY --from=builder /app/target/release/charcoal /app/charcoal
# Create the model directory (Railway volume mounts here at runtime)
RUN mkdir -p /data/models
# Railway sets PORT at runtime
ENV RUST_LOG=charcoal=info
EXPOSE 3000
# Shell form so $PORT expands at runtime (Railway injects PORT)
CMD ./charcoal serve --port ${PORT:-3000} --bind 0.0.0.0