管理端全部功能跑通
This commit is contained in:
150
EdgeHttpDNS/build/build.sh
Normal file
150
EdgeHttpDNS/build/build.sh
Normal file
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
function build() {
|
||||
ROOT=$(dirname "$0")
|
||||
NAME="edge-httpdns"
|
||||
VERSION=$(lookup-version "$ROOT"/../internal/const/const.go)
|
||||
DIST=$ROOT/"../dist/${NAME}"
|
||||
OS=${1}
|
||||
ARCH=${2}
|
||||
|
||||
if [ -z "$OS" ]; then
|
||||
echo "usage: build.sh OS ARCH"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "usage: build.sh OS ARCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ZIP_PATH=$(which zip)
|
||||
if [ -z "$ZIP_PATH" ]; then
|
||||
echo "we need 'zip' command to compress files"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "building v${VERSION}/${OS}/${ARCH} ..."
|
||||
ZIP="${NAME}-${OS}-${ARCH}-v${VERSION}.zip"
|
||||
|
||||
rm -rf "$DIST"
|
||||
mkdir -p "$DIST"/bin
|
||||
mkdir -p "$DIST"/configs
|
||||
mkdir -p "$DIST"/logs
|
||||
mkdir -p "$DIST"/data
|
||||
|
||||
cp "$ROOT"/configs/api_httpdns.template.yaml "$DIST"/configs
|
||||
copy_fluent_bit_assets "$ROOT" "$DIST" "$OS" "$ARCH" || exit 1
|
||||
|
||||
env GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 \
|
||||
go build -trimpath -o "$DIST"/bin/${NAME} -ldflags="-s -w" "$ROOT"/../cmd/edge-httpdns/main.go
|
||||
|
||||
if [ ! -f "$DIST"/bin/${NAME} ]; then
|
||||
echo "build failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# delete hidden files
|
||||
find "$DIST" -name ".DS_Store" -delete
|
||||
find "$DIST" -name ".gitignore" -delete
|
||||
|
||||
echo "zip files ..."
|
||||
cd "${DIST}/../" || exit 1
|
||||
if [ -f "${ZIP}" ]; then
|
||||
rm -f "${ZIP}"
|
||||
fi
|
||||
zip -r -X -q "${ZIP}" ${NAME}/
|
||||
rm -rf "${NAME}"
|
||||
cd - || exit 1
|
||||
|
||||
echo "OK"
|
||||
}
|
||||
|
||||
function copy_fluent_bit_assets() {
|
||||
ROOT=$1
|
||||
DIST=$2
|
||||
OS=$3
|
||||
ARCH=$4
|
||||
FLUENT_ROOT="$ROOT/../../deploy/fluent-bit"
|
||||
FLUENT_DIST="$DIST/deploy/fluent-bit"
|
||||
|
||||
if [ ! -d "$FLUENT_ROOT" ]; then
|
||||
echo "[error] fluent-bit source directory not found: $FLUENT_ROOT"
|
||||
return 1
|
||||
fi
|
||||
verify_fluent_bit_package_matrix "$FLUENT_ROOT" "$ARCH" || return 1
|
||||
|
||||
rm -rf "$FLUENT_DIST"
|
||||
mkdir -p "$FLUENT_DIST"
|
||||
|
||||
for file in 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 README.md; do
|
||||
if [ -f "$FLUENT_ROOT/$file" ]; then
|
||||
cp "$FLUENT_ROOT/$file" "$FLUENT_DIST/"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$OS" = "linux" ]; then
|
||||
PACKAGE_SRC="$FLUENT_ROOT/packages/linux-$ARCH"
|
||||
PACKAGE_DST="$FLUENT_DIST/packages/linux-$ARCH"
|
||||
if [ -d "$PACKAGE_SRC" ]; then
|
||||
mkdir -p "$PACKAGE_DST"
|
||||
cp -R "$PACKAGE_SRC/." "$PACKAGE_DST/"
|
||||
else
|
||||
echo "[error] fluent-bit package directory not found: $PACKAGE_SRC"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f "$FLUENT_DIST/.gitignore"
|
||||
rm -f "$FLUENT_DIST"/logs.db*
|
||||
rm -rf "$FLUENT_DIST/storage"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function verify_fluent_bit_package_matrix() {
|
||||
FLUENT_ROOT=$1
|
||||
ARCH=$2
|
||||
REQUIRED_FILES=()
|
||||
if [ "$ARCH" = "amd64" ]; then
|
||||
REQUIRED_FILES=(
|
||||
"packages/linux-amd64/fluent-bit_4.2.2_amd64.deb"
|
||||
"packages/linux-amd64/fluent-bit-4.2.2-1.x86_64.rpm"
|
||||
)
|
||||
elif [ "$ARCH" = "arm64" ]; then
|
||||
REQUIRED_FILES=(
|
||||
"packages/linux-arm64/fluent-bit_4.2.2_arm64.deb"
|
||||
"packages/linux-arm64/fluent-bit-4.2.2-1.aarch64.rpm"
|
||||
)
|
||||
else
|
||||
echo "[error] unsupported arch for fluent-bit package validation: $ARCH"
|
||||
return 1
|
||||
fi
|
||||
|
||||
MISSING=0
|
||||
for FILE in "${REQUIRED_FILES[@]}"; do
|
||||
if [ ! -f "$FLUENT_ROOT/$FILE" ]; then
|
||||
echo "[error] fluent-bit matrix package missing: $FLUENT_ROOT/$FILE"
|
||||
MISSING=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$MISSING" -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function lookup-version() {
|
||||
FILE=$1
|
||||
VERSION_DATA=$(cat "$FILE")
|
||||
re="Version[ ]+=[ ]+\"([0-9.]+)\""
|
||||
if [[ $VERSION_DATA =~ $re ]]; then
|
||||
echo "${BASH_REMATCH[1]}"
|
||||
else
|
||||
echo "could not match version"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
build "$1" "$2"
|
||||
Reference in New Issue
Block a user