From 39524692e5de47b537f8926015f8e32e8189e783 Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 19 Feb 2026 22:42:09 +0800 Subject: [PATCH] Sync code from main --- EdgeAPI/.gitignore | 3 +- EdgeAPI/build/build-all-plus.sh | 9 + EdgeAPI/build/build-all.sh | 9 + EdgeAPI/build/build.sh | 221 ++++++++++++++++++++++++ EdgeAPI/build/configs/.gitignore | 3 + EdgeAPI/build/configs/api.template.yaml | 12 ++ EdgeAPI/build/configs/db.template.yaml | 5 + EdgeAPI/build/deploy/.gitignore | 1 + EdgeAPI/build/installers/.gitignore | 1 + EdgeAPI/build/sql.sh | 7 + 10 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 EdgeAPI/build/build-all-plus.sh create mode 100644 EdgeAPI/build/build-all.sh create mode 100644 EdgeAPI/build/build.sh create mode 100644 EdgeAPI/build/configs/.gitignore create mode 100644 EdgeAPI/build/configs/api.template.yaml create mode 100644 EdgeAPI/build/configs/db.template.yaml create mode 100644 EdgeAPI/build/deploy/.gitignore create mode 100644 EdgeAPI/build/installers/.gitignore create mode 100644 EdgeAPI/build/sql.sh diff --git a/EdgeAPI/.gitignore b/EdgeAPI/.gitignore index 09d0e54..a9d30f9 100644 --- a/EdgeAPI/.gitignore +++ b/EdgeAPI/.gitignore @@ -7,8 +7,7 @@ edge-api *.dylib # 构建目录 -dist/ -build/ +dist/* # 测试文件 *.test diff --git a/EdgeAPI/build/build-all-plus.sh b/EdgeAPI/build/build-all-plus.sh new file mode 100644 index 0000000..d91ba94 --- /dev/null +++ b/EdgeAPI/build/build-all-plus.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +./build.sh linux amd64 plus +#./build.sh linux 386 plus +#./build.sh linux arm64 plus +#./build.sh linux mips64 plus +#./build.sh linux mips64le plus +#./build.sh darwin amd64 plus +#./build.sh darwin arm64 plus diff --git a/EdgeAPI/build/build-all.sh b/EdgeAPI/build/build-all.sh new file mode 100644 index 0000000..5d257fa --- /dev/null +++ b/EdgeAPI/build/build-all.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +./build.sh linux amd64 +./build.sh linux 386 +#./build.sh linux arm64 +./build.sh linux mips64 +./build.sh linux mips64le +./build.sh darwin amd64 +#./build.sh darwin arm64 diff --git a/EdgeAPI/build/build.sh b/EdgeAPI/build/build.sh new file mode 100644 index 0000000..dade19e --- /dev/null +++ b/EdgeAPI/build/build.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash + +function build() { + ROOT=$(dirname "$0") + NAME="edge-api" + DIST=$ROOT/"../dist/${NAME}" + OS=${1} + ARCH=${2} + TAG=${3} + NODE_ARCHITECTS=("amd64") + #NODE_ARCHITECTS=("amd64" "arm64") + + if [ -z "$OS" ]; then + echo "usage: build.sh OS ARCH" + exit + fi + if [ -z "$ARCH" ]; then + echo "usage: build.sh OS ARCH" + exit + fi + if [ -z "$TAG" ]; then + TAG="community" + fi + + VERSION=$(lookup-version "$ROOT"/../internal/const/const.go) + # 生成 zip 文件名时不包含 plus 标记 + if [ "${TAG}" = "plus" ]; then + ZIP="${NAME}-${OS}-${ARCH}-v${VERSION}.zip" + else + ZIP="${NAME}-${OS}-${ARCH}-${TAG}-v${VERSION}.zip" + fi + + # build edge-node + NodeVersion=$(lookup-version "$ROOT""/../../EdgeNode/internal/const/const.go") + echo "building edge-node v${NodeVersion} ..." + EDGE_NODE_BUILD_SCRIPT=$ROOT"/../../EdgeNode/build/build.sh" + if [ ! -f "$EDGE_NODE_BUILD_SCRIPT" ]; then + echo "unable to find edge-node build script 'EdgeNode/build/build.sh'" + exit + fi + cd "$ROOT""/../../EdgeNode/build" || exit + echo "==============================" + for arch in "${NODE_ARCHITECTS[@]}"; do + # 查找 zip 文件时不包含 plus 标记 + if [ "${TAG}" = "plus" ]; then + NODE_ZIP_FILE="$ROOT""/../../EdgeNode/dist/edge-node-linux-${arch}-v${NodeVersion}.zip" + else + NODE_ZIP_FILE="$ROOT""/../../EdgeNode/dist/edge-node-linux-${arch}-${TAG}-v${NodeVersion}.zip" + fi + if [ ! -f "$NODE_ZIP_FILE" ]; then + ./build.sh linux "$arch" $TAG + else + echo "use built node linux/$arch/v${NodeVersion}" + fi + done + echo "==============================" + cd - || exit + + rm -f "$ROOT"/deploy/*.zip + for arch in "${NODE_ARCHITECTS[@]}"; do + # 复制 zip 文件时不包含 plus 标记 + if [ "${TAG}" = "plus" ]; then + NODE_ZIP_FILE="$ROOT""/../../EdgeNode/dist/edge-node-linux-${arch}-v${NodeVersion}.zip" + else + NODE_ZIP_FILE="$ROOT""/../../EdgeNode/dist/edge-node-linux-${arch}-${TAG}-v${NodeVersion}.zip" + fi + cp "$NODE_ZIP_FILE" "$ROOT"/deploy/edge-node-linux-"${arch}"-v"${NodeVersion}".zip + done + + # build edge-dns + if [ "$TAG" = "plus" ]; then + DNS_ROOT=$ROOT"/../../EdgeDNS" + if [ -d "$DNS_ROOT" ]; then + DNSNodeVersion=$(lookup-version "$ROOT""/../../EdgeDNS/internal/const/const.go") + echo "building edge-dns ${DNSNodeVersion} ..." + EDGE_DNS_NODE_BUILD_SCRIPT=$ROOT"/../../EdgeDNS/build/build.sh" + if [ ! -f "$EDGE_DNS_NODE_BUILD_SCRIPT" ]; then + echo "unable to find edge-dns build script 'EdgeDNS/build/build.sh'" + exit + fi + cd "$ROOT""/../../EdgeDNS/build" || exit + echo "==============================" + architects=("amd64") + #architects=("amd64" "arm64") + for arch in "${architects[@]}"; do + ./build.sh linux "$arch" $TAG + done + echo "==============================" + cd - || exit + + for arch in "${architects[@]}"; do + cp "$ROOT""/../../EdgeDNS/dist/edge-dns-linux-${arch}-v${DNSNodeVersion}.zip" "$ROOT"/deploy/edge-dns-linux-"${arch}"-v"${DNSNodeVersion}".zip + done + fi + fi + + # build sql + if [ $TAG = "plus" ]; then + echo "building sql ..." + "${ROOT}"/sql.sh + fi + + # copy files + echo "copying ..." + if [ ! -d "$DIST" ]; then + mkdir "$DIST" + mkdir "$DIST"/bin + mkdir "$DIST"/configs + mkdir "$DIST"/logs + mkdir "$DIST"/data + fi + cp "$ROOT"/configs/api.template.yaml "$DIST"/configs/ + cp "$ROOT"/configs/db.template.yaml "$DIST"/configs/ + # 复制 EdgeCommon 的配置文件(如果存在) + if [ -f "$ROOT"/../../EdgeCommon/build/configs/ip_library.yaml ]; then + cp "$ROOT"/../../EdgeCommon/build/configs/ip_library.yaml "$DIST"/configs/ + fi + if [ -f "$ROOT"/../../EdgeCommon/build/configs/brand.yaml ]; then + cp "$ROOT"/../../EdgeCommon/build/configs/brand.yaml "$DIST"/configs/ + fi + cp -R "$ROOT"/deploy "$DIST/" + rm -f "$DIST"/deploy/.gitignore + cp -R "$ROOT"/installers "$DIST"/ + + # copy fluent-bit templates and local packages from repo root + FLUENT_ROOT="$ROOT/../../deploy/fluent-bit" + FLUENT_DIST="$DIST/deploy/fluent-bit" + if [ -d "$FLUENT_ROOT" ]; then + rm -rf "$FLUENT_DIST" + mkdir -p "$FLUENT_DIST" + + FLUENT_FILES=( + "fluent-bit.conf" + "fluent-bit-dns.conf" + "fluent-bit-https.conf" + "fluent-bit-dns-https.conf" + "fluent-bit-windows.conf" + "fluent-bit-windows-https.conf" + "parsers.conf" + "clickhouse-upstream.conf" + "clickhouse-upstream-windows.conf" + "logrotate.conf" + "README.md" + ) + for file in "${FLUENT_FILES[@]}"; do + if [ -f "$FLUENT_ROOT/$file" ]; then + cp "$FLUENT_ROOT/$file" "$FLUENT_DIST/" + fi + done + + if [ -d "$FLUENT_ROOT/packages" ]; then + cp -R "$FLUENT_ROOT/packages" "$FLUENT_DIST/" + fi + + # remove local runtime artifacts if present + rm -f "$FLUENT_DIST/.gitignore" + rm -f "$FLUENT_DIST"/logs.db* + rm -rf "$FLUENT_DIST/storage" + fi + + # building edge installer + echo "building node installer ..." + architects=("amd64") + #architects=("amd64" "arm64") + for arch in "${architects[@]}"; do + # TODO support arm, mips ... + env GOOS=linux GOARCH="${arch}" go build -trimpath -tags $TAG --ldflags="-s -w" -o "$ROOT"/installers/edge-installer-helper-linux-"${arch}" "$ROOT"/../cmd/installer-helper/main.go + done + + # building edge dns installer + if [ $TAG = "plus" ]; then + echo "building dns node installer ..." + architects=("amd64") + #architects=("amd64" "arm64") + for arch in "${architects[@]}"; do + # TODO support arm, mips ... + env GOOS=linux GOARCH="${arch}" go build -trimpath -tags $TAG --ldflags="-s -w" -o "$ROOT"/installers/edge-installer-dns-helper-linux-"${arch}" "$ROOT"/../cmd/installer-dns-helper/main.go + done + fi + + # building api node + env GOOS="$OS" GOARCH="$ARCH" go build -trimpath -tags $TAG --ldflags="-s -w" -o "$DIST/bin/$NAME" "$ROOT"/../cmd/edge-api/main.go + if [ ! -f "${DIST}/bin/${NAME}" ]; then + echo "build failed!" + exit + fi + + # delete hidden files + find "$DIST" -name ".DS_Store" -delete + find "$DIST" -name ".gitignore" -delete + + # 删除 MaxMind 数据库文件(使用嵌入的数据库,不需要外部文件) + find "$DIST" -name "*.mmdb" -type f -delete + find "$DIST" -type d -name "iplibrary" -empty -delete + + echo "zip files" + cd "${DIST}/../" || exit + if [ -f "${ZIP}" ]; then + rm -f "${ZIP}" + fi + zip -r -X -q "${ZIP}" ${NAME}/ + rm -rf ${NAME} + cd - || exit + + echo "[done]" +} + +function lookup-version() { + FILE=$1 + VERSION_DATA=$(cat "$FILE") + re="Version[ ]+=[ ]+\"([0-9.]+)\"" + if [[ $VERSION_DATA =~ $re ]]; then + VERSION=${BASH_REMATCH[1]} + echo "$VERSION" + else + echo "could not match version" + exit + fi +} + +build "$1" "$2" "$3" diff --git a/EdgeAPI/build/configs/.gitignore b/EdgeAPI/build/configs/.gitignore new file mode 100644 index 0000000..2493eea --- /dev/null +++ b/EdgeAPI/build/configs/.gitignore @@ -0,0 +1,3 @@ +api.yaml +db.yaml +.db.yaml \ No newline at end of file diff --git a/EdgeAPI/build/configs/api.template.yaml b/EdgeAPI/build/configs/api.template.yaml new file mode 100644 index 0000000..b584452 --- /dev/null +++ b/EdgeAPI/build/configs/api.template.yaml @@ -0,0 +1,12 @@ +nodeId: "${nodeId}" +secret: "${secret}" + +clickhouse: + host: 127.0.0.1 + port: 8123 + user: default + password: "123456" + database: default + scheme: http + tlsSkipVerify: false + tlsServerName: "" diff --git a/EdgeAPI/build/configs/db.template.yaml b/EdgeAPI/build/configs/db.template.yaml new file mode 100644 index 0000000..04c31b7 --- /dev/null +++ b/EdgeAPI/build/configs/db.template.yaml @@ -0,0 +1,5 @@ +user: root +password: 123456 +host: 127.0.0.1:3306 +database: db_edge +boolFields: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "retry40X", "autoSystemTuning", "disableDefaultDB", "autoTrimDisks", "enableGlobalPages", "ignoreLocal", "ignoreSearchEngine" ] \ No newline at end of file diff --git a/EdgeAPI/build/deploy/.gitignore b/EdgeAPI/build/deploy/.gitignore new file mode 100644 index 0000000..6f66c74 --- /dev/null +++ b/EdgeAPI/build/deploy/.gitignore @@ -0,0 +1 @@ +*.zip \ No newline at end of file diff --git a/EdgeAPI/build/installers/.gitignore b/EdgeAPI/build/installers/.gitignore new file mode 100644 index 0000000..9949c9a --- /dev/null +++ b/EdgeAPI/build/installers/.gitignore @@ -0,0 +1 @@ +edge-* \ No newline at end of file diff --git a/EdgeAPI/build/sql.sh b/EdgeAPI/build/sql.sh new file mode 100644 index 0000000..347659a --- /dev/null +++ b/EdgeAPI/build/sql.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# generate 'internal/setup/sql.json' file + +CWD="$(dirname "$0")" + +go run "${CWD}"/../cmd/sql-dump/main.go -dir="${CWD}" \ No newline at end of file