-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·78 lines (63 loc) · 2.84 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·78 lines (63 loc) · 2.84 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
#!/usr/bin/env bash
#
# 构建 pgvector-zh 镜像:
# 1. 自动下载 SCWS / zhparser 源码到 downloads/(做 SHA256 校验;文件已存在且校验通过则跳过下载)
# 2. 执行 docker build
#
# 可用环境变量覆盖默认值(覆盖下载地址时,请同步更新对应 SHA256,或将 SHA256 置空跳过校验):
# IMAGE_NAME 镜像名,默认 pgvector-zh
# IMAGE_TAG 镜像标签,默认 0.8.2-pg18
# SCWS_URL SCWS 源码包下载地址
# SCWS_SHA256 SCWS 源码包校验值
# ZHPARSER_URL zhparser 源码包下载地址
# ZHPARSER_SHA256 zhparser 源码包校验值
set -euo pipefail
cd "$(dirname "$0")"
readonly SCWS_VERSION="1.2.3"
readonly SCWS_SHA256="${SCWS_SHA256:-60d50ac3dc42cff3c0b16cb1cfee47d8cb8c8baa142a58bc62854477b81f1af5}"
readonly SCWS_URL="${SCWS_URL:-https://www.xunsearch.com/scws/down/scws-${SCWS_VERSION}.tar.bz2}"
# zhparser 固定在 amutu/zhparser master 分支 2025-10-21 的快照
readonly ZHPARSER_COMMIT="02c08378643739a07bdb0a3f64e249d4da7a9d99"
readonly ZHPARSER_SHA256="${ZHPARSER_SHA256:-195845c477ae209fa706efcb807696730344edd88ad3233c28511cc289aa23c5}"
readonly ZHPARSER_URL="${ZHPARSER_URL:-https://github.com/amutu/zhparser/archive/${ZHPARSER_COMMIT}.zip}"
readonly IMAGE_NAME="${IMAGE_NAME:-pgvector-zh}"
readonly IMAGE_TAG="${IMAGE_TAG:-0.8.2-pg18}"
readonly DOWNLOAD_DIR="downloads"
# verify_sha256 <file> <expected>:兼容 macOS(shasum)与 Linux(sha256sum)
verify_sha256() {
local file="$1" expected="$2" actual=""
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "$file" | awk '{print $1}')"
else
actual="$(shasum -a 256 "$file" | awk '{print $1}')"
fi
[[ "$actual" == "$expected" ]]
}
# fetch <url> <output> <sha256>(sha256 为空时跳过校验)
fetch() {
local url="$1" out="$2" sha256="$3"
if [[ -f "$out" ]]; then
if [[ -z "$sha256" ]] || verify_sha256 "$out" "$sha256"; then
echo "== 已存在且校验通过,跳过下载: $out"
return
fi
echo "== 已存在但校验不通过,重新下载: $out"
rm -f "$out"
fi
echo "== 下载: $url"
if ! curl --fail --location --retry 3 --connect-timeout 15 -o "$out" "$url"; then
echo "下载失败: $url" >&2
echo "提示: 网络受限环境可设置 https_proxy 等标准代理环境变量后重试" >&2
exit 1
fi
if [[ -n "$sha256" ]] && ! verify_sha256 "$out" "$sha256"; then
echo "SHA256 校验失败: $out" >&2
exit 1
fi
}
mkdir -p "$DOWNLOAD_DIR"
fetch "$SCWS_URL" "$DOWNLOAD_DIR/scws-${SCWS_VERSION}.tar.bz2" "$SCWS_SHA256"
fetch "$ZHPARSER_URL" "$DOWNLOAD_DIR/zhparser.zip" "$ZHPARSER_SHA256"
echo "== 构建镜像: ${IMAGE_NAME}:${IMAGE_TAG}"
docker build --tag "${IMAGE_NAME}:${IMAGE_TAG}" .
echo "== 完成: ${IMAGE_NAME}:${IMAGE_TAG}"