Files
runny 168057db78
deploy-hxtesting / build-and-deploy (push) Failing after 1s
feat(tenant): 成员管理新增 CASDOOR 同步与批量导入部门匹配(000156)
同步CASDOOR成员:
- 经 Casdoor 管理 API 拉全量用户目录:部门落组织架构(org_depts),账号
  工号优先匹配/邮箱兜底,未注册自动开户并加入空间;单向增量幂等,
  无部门数据自动降级为纯成员同步
- 新增 OIDC_AUTH_ADMIN_* 配置段(client_credentials/服务账号密码两种模式、
  部门字段映射),集成层见 internal/integrations/casdoor
用户部门字段(迁移 000156):
- users.dept_code/dept_name 同步态字段:成员列表「所属部门」列展示,
  组织中心从平台用户添加时按部门自动预选
批量导入部门列:
- 模板调整为 工号/姓名/部门/邮箱/角色 五列,六语言弹窗文案同步更新
- 部门列按部门管理自动匹配:名称/编号精确命中 → 唯一子串兜底,多候选
  歧义不匹配;命中回写所属部门,未命中留空不阻断该行导入;部门管理
  不可用时整列降级忽略(与 Casdoor 同步降级同思路)
构建:
- Dockerfile: browserskill 预构建产物快速通道,rustup 按需安装 + BuildKit 缓存挂载
2026-11-21 01:39:06 +08:00

253 lines
12 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Build extension and daemon from the same pinned source on the runtime architecture.
FROM --platform=$TARGETPLATFORM node:24-bookworm-slim@sha256:ba849c60be29959425b8734d57b8b4b7d56f98edd9504c9af091d5281095a71e AS browserskill
WORKDIR /build
# Use the same optional Debian mirror as the Go builder and runtime stages.
ARG APK_MIRROR_ARG
# This base image has no CA certificates. Install them from the original HTTP
# Debian source before swapping in a mirror: mirrors.tencent.com redirects
# apt to HTTPS, and that handshake fails without a trust store.
RUN if [ -n "$APK_MIRROR_ARG" ]; then \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/* && \
sed -i "s@deb.debian.org@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
fi && \
apt-get update && \
apt-get install -y --no-install-recommends git python3 ca-certificates curl build-essential cmake pkg-config && \
rm -rf /var/lib/apt/lists/*
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:$PATH
COPY scripts/build_browserskill.sh scripts/browserskill-release.json ./scripts/
# 离线快速通道:优先使用仓库内预构建产物(air-gapped/网络受限环境无需 clone GitHub)
COPY artifacts/browserskill ./artifacts/browserskill/
ARG TARGETOS
ARG TARGETARCH
# 预构建产物存在时 Rust 工具链不需要(构建脚本走秒级快速通道)——此前无条件装
# rustup 曾因 sh.rustup.rs 直连抖动反复失败拖慢全量构建。需要完整构建时才装,
# 且走国内镜像链(与 anydoc 阶段一致),cargo/rustup 用 BuildKit 缓存挂载复用。
# 注意:构建脚本本身必须始终执行——无产物时全量构建,有产物时也是它把产物
# 复制进 /opt/academy/browserskill(最终 stage 的 COPY 依赖该路径)。
RUN --mount=type=cache,target=/usr/local/cargo/registry,id=bs-cargo-registry \
--mount=type=cache,target=/usr/local/cargo/git,id=bs-cargo-git \
--mount=type=cache,target=/usr/local/rustup,id=bs-rustup \
if [ ! -f artifacts/browserskill/bsk ]; then \
curl --http1.1 --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh \
-o /tmp/rustup-init.sh \
|| curl --http1.1 --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
-o /tmp/rustup-init.sh; \
ok=0; \
for srv in https://rsproxy.cn https://mirrors.ustc.edu.cn/rust-static https://static.rust-lang.org; do \
case "$srv" in \
https://rsproxy.cn) upd=https://rsproxy.cn/rustup ;; \
https://mirrors.ustc.edu.cn/rust-static) upd=https://mirrors.ustc.edu.cn/rust-static/rustup ;; \
*) upd=https://static.rust-lang.org/rustup ;; \
esac; \
echo "==> Trying rust toolchain mirror: $srv"; \
if RUSTUP_DIST_SERVER="$srv" RUSTUP_UPDATE_ROOT="$upd" \
sh /tmp/rustup-init.sh -y --profile minimal --default-toolchain stable; then \
ok=1; break; \
fi; \
done; \
[ "$ok" = "1" ]; \
fi && \
bash scripts/build_browserskill.sh /opt/academy/browserskill "${TARGETOS}/${TARGETARCH}"
# Build stage
FROM golang:1.26-bookworm AS builder
WORKDIR /app
# 通过构建参数接收敏感信息
ARG GOPRIVATE_ARG
ARG GOPROXY_ARG
ARG GOSUMDB_ARG=off
ARG APK_MIRROR_ARG
# 设置Go环境变量
ENV GOPRIVATE=${GOPRIVATE_ARG}
ENV GOPROXY=${GOPROXY_ARG}
ENV GOSUMDB=${GOSUMDB_ARG}
# Install dependencies
RUN if [ -n "$APK_MIRROR_ARG" ]; then \
sed -i "s@deb.debian.org@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
fi && \
apt-get update && \
apt-get install -y git build-essential libsqlite3-dev curl
# Install migrate tool(Go 模块缓存挂载:守护进程重启/层失效时不重新下载全量模块)
RUN --mount=type=cache,target=/go/pkg/mod,id=go-mod \
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
# Copy go mod files. go.mod replace-points anydoc at ./third_party/anydoc-go,
# so that module's go.mod must exist before `go mod download`.
COPY go.mod go.sum ./
COPY third_party/anydoc-go/go.mod third_party/anydoc-go/go.mod
# 模块缓存挂载复用(下载产物不进镜像层;yanyiwu 目录是 gojieba 运行时依赖,
# 复制到层内固定路径供后续 COPY,避免依赖已被卸载的缓存挂载)
RUN --mount=type=cache,target=/go/pkg/mod,id=go-mod \
go mod download && cp -r /go/pkg/mod/github.com/yanyiwu/ /app/yanyiwu-mod/
COPY cmd/download cmd/download
# DuckDB extensions (spatial/excel): prefer a local seed tarball exported from
# a previously built image (artifacts/duckdb_extensions/seed.tar) —
# extensions.duckdb.org is often unreachable from some networks. Fall back to
# the online INSTALL path when the seed is absent.
COPY artifacts/duckdb_extensions/seed.tar /tmp/duckdb-seed.tar
RUN if [ -s /tmp/duckdb-seed.tar ]; then \
mkdir -p /root/.duckdb && tar -xf /tmp/duckdb-seed.tar -C /root/.duckdb; \
ls -la /root/.duckdb/extensions/*/linux_amd64; \
else \
go run cmd/download/duckdb/duckdb.go; \
fi
COPY . .
RUN bash ./scripts/copy-licenses.sh /license-bundle
# Get version and commit info for build injection
ARG VERSION_ARG
ARG COMMIT_ID_ARG
ARG BUILD_TIME_ARG
ARG GO_VERSION_ARG
# Set build-time variables
ENV VERSION=${VERSION_ARG}
ENV COMMIT_ID=${COMMIT_ID_ARG}
ENV BUILD_TIME=${BUILD_TIME_ARG}
ENV GO_VERSION=${GO_VERSION_ARG}
# Link the anydoc parser engine (office docs converted in-process, no
# Python docreader). Default on so Hub / compose images ship a working
# engine; pass WITH_ANYDOC=0 to skip the Rust toolchain (~few minutes and
# ~1 GB of build-stage layers).
ARG WITH_ANYDOC=1
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:$PATH
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
if [ "$WITH_ANYDOC" = "1" ]; then \
curl --http1.1 --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh \
-o /tmp/rustup-init.sh \
|| curl --http1.1 --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
-o /tmp/rustup-init.sh; \
ok=0; \
for srv in https://mirrors.ustc.edu.cn/rust-static https://rsproxy.cn https://static.rust-lang.org; do \
case "$srv" in \
https://mirrors.ustc.edu.cn/rust-static) upd=https://mirrors.ustc.edu.cn/rust-static/rustup ;; \
https://rsproxy.cn) upd=https://rsproxy.cn/rustup ;; \
*) upd=https://static.rust-lang.org/rustup ;; \
esac; \
echo "==> Trying rust toolchain mirror: $srv"; \
if RUSTUP_DIST_SERVER="$srv" RUSTUP_UPDATE_ROOT="$upd" \
sh /tmp/rustup-init.sh -y --profile minimal --default-toolchain stable; then \
ok=1; break; \
fi; \
done; \
[ "$ok" = "1" ] && ./scripts/build-anydoc-lib.sh; \
fi
# Build the application with version info. Mount the Go build cache as well as
# the module cache: `COPY . .` invalidates this layer on every source change,
# and without the mount each rebuild regenerates the whole compile cache inside
# the layer (~2.7 GB), which occupies disk locally and is uploaded to the CI
# layer cache. Mounted, the cache lives outside the layer and repeated builds
# reuse compiled objects instead of recompiling from scratch.
#
# 链接前剥离 anydoc 静态库的 LLVM LTO 段(.llvmbc/.llvmcmd/.llvm_ar 等):
# golang:1.26-bookworm 浮动 tag 更新后的 Go 链接器拒绝所有 .llvm* 位码段;
# fat 对象中的常规 ELF 代码段不受影响。必须在 anydoc 构建(生成 .a)之后、
# make build-prod 之前,并按实际出现的段名逐个剥离。
RUN --mount=type=cache,target=/go/pkg/mod,id=go-mod \
--mount=type=cache,target=/root/.cache/go-build,id=go-build \
for a in $(find third_party/anydoc-go/lib -name '*.a' -type f); do \
secs=$(readelf -S "$a" 2>/dev/null | grep -oE '\.llvm[A-Za-z0-9_.-]*' | sort -u); \
for s in $secs; do \
objcopy --remove-section "$s" "$a" || true; \
done; \
done; \
if [ "$WITH_ANYDOC" = "1" ]; then \
make build-prod GO_BUILD_TAGS=anydoc; \
else \
make build-prod; \
fi
RUN cp -r /app/yanyiwu-mod/ /app/yanyiwu/
# Final stage
FROM debian:12.12-slim
WORKDIR /app
ARG APK_MIRROR_ARG
# PyPI 镜像(国内网络直连 pypi.org 常超时;由 compose 传入国内源,留空回退官方源)
ARG PIP_INDEX_ARG
# apt bootstrap 镜像(须为不跳转 HTTPS 的纯 HTTP 源,如 mirrors.aliyun.com)
ARG BOOTSTRAP_MIRROR_ARG
# Pairing derives the gateway URL from the user's page origin by default.
ENV BROWSERSKILL_BINARY=/opt/academy/browserskill/bsk \
BROWSERSKILL_EXTENSION_PATH=/opt/academy/browserskill/browser-skill-academy-0.3.1.zip
COPY --from=browserskill /opt/academy/browserskill /opt/academy/browserskill
# Create a non-root user first
RUN useradd -m -s /bin/bash appuser
# First, install ca-certificates via an HTTP-only bootstrap mirror (国内直连官方源
# 速率极慢;主镜像会 302 跳 HTTPS 而此刻尚无信任库,故 bootstrap 需用不跳转的 HTTP 源),
# 装好信任库后立即把源切到 APK_MIRROR_ARG 供后续步骤使用
RUN if [ -n "$BOOTSTRAP_MIRROR_ARG" ]; then \
sed -i "s@deb.debian.org@${BOOTSTRAP_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
fi && \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
if [ -n "$APK_MIRROR_ARG" ]; then \
sed -i "s@${BOOTSTRAP_MIRROR_ARG:-deb.debian.org}@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
fi && \
rm -rf /var/lib/apt/lists/*
# Then switch to mirror if specified and install other packages
RUN if [ -n "$APK_MIRROR_ARG" ]; then \
sed -i "s@deb.debian.org@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
fi && \
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential postgresql-client default-mysql-client tzdata sed curl bash vim wget \
libsqlite3-0 \
python3 python3-pip python3-dev libffi-dev libssl-dev \
nodejs npm \
gosu \
ffmpeg && \
python3 -m pip install --break-system-packages -i ${PIP_INDEX_ARG:-https://pypi.org/simple} --upgrade pip setuptools wheel && \
# uv 通过 PyPI 镜像安装(uvx 由 pip 装入 /usr/local/bin;官方 astral.sh 安装脚本在受限网络不可达)
python3 -m pip install --break-system-packages -i ${PIP_INDEX_ARG:-https://pypi.org/simple} uv && \
chown -R appuser:appuser /home/appuser && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create data directories and set permissions
RUN mkdir -p /data/files && \
chown -R appuser:appuser /app /data/files
# Copy migrate tool from builder stage
COPY --from=builder /go/bin/migrate /usr/local/bin/
COPY --from=builder /app/yanyiwu/ /go/pkg/mod/github.com/yanyiwu/
# Copy the binary from the builder stage
COPY --from=builder /app/config ./config
COPY --from=builder /app/scripts ./scripts
COPY --from=builder /app/migrations ./migrations
COPY --from=builder /app/dataset/samples ./dataset/samples
COPY --from=builder /root/.duckdb /home/appuser/.duckdb
COPY --from=builder /app/Academy .
COPY --from=builder /license-bundle/ ./
# Copy and make entrypoint script executable
COPY --from=builder /app/scripts/docker-entrypoint.sh ./scripts/docker-entrypoint.sh
# Make scripts executable
RUN chmod +x ./scripts/*.sh
# Expose ports
EXPOSE 8080
ENTRYPOINT ["./scripts/docker-entrypoint.sh"]
CMD ["./Academy"]