Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (66 loc) · 4.1 KB
/
Copy pathDockerfile
File metadata and controls
69 lines (66 loc) · 4.1 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
# EXMACHINA 多阶段构建:
# 1) node 阶段构建 WebUI(npm run build:webui 产物由网关静态托管)
# 2) rust 阶段编译 CLI + 网关(GNU 工具链)
# 3) 运行时镜像:仅二进制 + 静态资源 + 数据卷
# 部署语言:EXM_LANG=zh(默认)| en —— en 时指挥体提示词装载 exmachina-orchestrator.en.md
# ---------- 1) WebUI ----------
FROM node:22-bookworm-slim AS webui-builder
WORKDIR /build
COPY webui/package.json webui/package-lock.json* ./
RUN npm install --no-audit --no-fund
COPY webui/ ./
RUN npm run build
# ---------- 2) Rust 核心 ----------
FROM rust:1.92-bookworm AS rust-builder
WORKDIR /build
# 国内网络环境:rustup/cargo 走 rsproxy 镜像(static.rust-lang.org 在部分路由器 DNS 下超时)
ENV RUSTUP_DIST_SERVER=https://rsproxy.cn
ENV RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
# apt 源同样换国内(deb.debian.org 为 Fastly CDN,该网络下不可达)
RUN sed -i 's|deb.debian.org|mirrors.ustc.edu.cn|g' /etc/apt/sources.list.d/debian.sources
# libxdo-dev:enigo 键鼠控制链接 libxdo(dbus 已 vendored,无需系统包)
RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libxdo-dev && rm -rf /var/lib/apt/lists/*
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
COPY crates ./crates
# vendor 的时区依赖(chrono-tz 等,路径依赖,必须随源码进构建上下文)
COPY third_party ./third_party
# cargo 源也切到 rsproxy(crates.io 代理)
RUN mkdir -p /usr/local/cargo/ && printf '[source.crates-io]\nreplace-with = "rsproxy-sparse"\n\n[source.rsproxy-sparse]\nregistry = "sparse+https://rsproxy.cn/index/"\n' > /usr/local/cargo/config.toml
# 依赖缓存层(无 lockfile 变更时命中)
RUN cargo build --release -p exm-cli -p exm-gateway
# ---------- 3) 编成数据(生成器需要 node;此处直接 COPY 源仓数据) ----------
FROM debian:bookworm-slim AS runtime
WORKDIR /app
# 运行时动态库:enigo/xcap 的 X11 栈(libxdo / X11 / xkbcommon;容器内无显示面,Computer Use 默认关闭,
# 但二进制加载即需这些 .so)+ CA 证书与 curl(健康检查)
# 命令面口径:终端白名单 AllowRule 允许的非开发工具链命令,镜像必须提供——否则审批流走完才失败,
# 浪费轮次与信任(审计实证:7 张审批单 failed 全为工具缺失)。开发工具链(node/cargo/go/gcc…)
# 属宿主机编码场景,不进镜像。
# apt 源换国内(deb.debian.org 为 Fastly CDN,该网络下不可达)
RUN sed -i 's|deb.debian.org|mirrors.ustc.edu.cn|g' /etc/apt/sources.list.d/debian.sources \
&& apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl git libxdo3 libx11-6 libxcb1 libxext6 libxinerama1 libxtst6 libxkbcommon0 \
python3 jq sqlite3 xxd \
ffmpeg imagemagick iproute2 iputils-ping dnsutils tree file procps util-linux-extra \
bsdextrautils bc unzip zip xz-utils openssh-client rsync util-linux \
&& rm -rf /var/lib/apt/lists/*
# 一键更新工具链:docker cli + compose 插件由 compose 从宿主机只读挂载(零构建期下载,版本与宿主引擎一致)
COPY --from=rust-builder /build/target/release/exm /usr/local/bin/exm
COPY --from=rust-builder /build/target/release/exmachina /usr/local/bin/exmachina
COPY --from=rust-builder /build/target/release/exm-gateway /usr/local/bin/exm-gateway
COPY --from=webui-builder /build/dist ./webui/dist
COPY entities ./entities
# 一键更新脚本:精简部署目录无 scripts/,网关回落 /app/scripts/apply-update.sh
COPY scripts/apply-update.sh ./scripts/apply-update.sh
RUN chmod +x ./scripts/apply-update.sh
# 执行身份约束专用用户(agent-exec-confinement):固定 uid 911、建主目录;
# 默认不启用(网关仍 root 跑,子进程降权由 security.execUser 显式开启)
RUN useradd -r -m -d /home/exm -u 911 exm 2>/dev/null || true
ENV EXM_LANG=zh
ENV RUST_LOG=info
# git 短哈希:runtime 阶段才注入(进程运行时读取)——若放 builder 阶段,每个 commit 都会作废整条 Rust 编译缓存
ARG GIT_HASH=dev
ENV EXM_GIT_HASH=${GIT_HASH}
EXPOSE 4173
VOLUME ["/app/.exmachina"]
CMD ["exm-gateway"]