forked from spacedriveapp/spacebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
105 lines (90 loc) · 3.22 KB
/
Dockerfile
File metadata and controls
105 lines (90 loc) · 3.22 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# syntax=docker/dockerfile:1.6
# ---- Builder stage ----
# Compiles the React frontend and the Rust binary with the frontend embedded.
FROM rust:bookworm AS builder
# Install build dependencies:
# protobuf-compiler — LanceDB protobuf codegen
# cmake — onig_sys (regex), lz4-sys
# libssl-dev — openssl-sys (reqwest TLS)
RUN apt-get update && apt-get install -y --no-install-recommends \
protobuf-compiler \
libprotobuf-dev \
cmake \
libssl-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"
WORKDIR /build
# 1. Fetch and cache Rust dependencies.
# cargo fetch needs a valid target, so we create stubs that get replaced later.
COPY Cargo.toml Cargo.lock ./
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/build/target \
mkdir src && echo "fn main() {}" > src/main.rs && touch src/lib.rs \
&& cargo build --release \
&& rm -rf src
# 2. Build the frontend.
COPY interface/package.json interface/
RUN --mount=type=cache,target=/root/.bun/install/cache \
cd interface && bun install
COPY interface/ interface/
RUN --mount=type=cache,target=/root/.bun/install/cache \
cd interface && bun run build
# 3. Copy source and compile the real binary.
# build.rs runs the frontend build (already done above, node_modules present).
# prompts/ is needed for include_str! in src/prompts/text.rs.
# migrations/ is needed for sqlx::migrate! in src/db.rs.
COPY build.rs ./
COPY prompts/ prompts/
COPY migrations/ migrations/
COPY src/ src/
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/build/target \
SPACEBOT_SKIP_FRONTEND_BUILD=1 cargo build --release \
&& mv /build/target/release/spacebot /usr/local/bin/spacebot \
&& cargo clean -p spacebot --release --target-dir /build/target
# ---- Slim stage ----
# Minimal runtime with just the binary. No browser.
FROM debian:bookworm-slim AS slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libsqlite3-0 \
curl \
gh \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/bin/spacebot /usr/local/bin/spacebot
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENV SPACEBOT_DIR=/data
ENV SPACEBOT_DEPLOYMENT=docker
EXPOSE 19898 18789
VOLUME /data
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD curl -f http://localhost:19898/api/health || exit 1
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["spacebot", "start", "--foreground"]
# ---- Full stage ----
# Slim + Chromium for browser workers.
FROM slim AS full
RUN apt-get update && apt-get install -y --no-install-recommends \
chromium \
fonts-liberation \
libnss3 \
libatk-bridge2.0-0 \
libdrm2 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libcairo2 \
libcups2 \
libxss1 \
libxtst6 \
&& rm -rf /var/lib/apt/lists/*
ENV CHROME_PATH=/usr/bin/chromium
ENV CHROME_FLAGS="--no-sandbox --disable-dev-shm-usage --disable-gpu"