138 lines
4.8 KiB
Bash
138 lines
4.8 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
STAGE_DIR="tools/build/output/hy2xs-install"
|
|
ADMIN_BUILD_DIR="tools/build/output/hy2xs-admin-build"
|
|
HYSTERIA_LOCK_FILE="tools/build/hysteria-lock.env"
|
|
|
|
prepare_stage() {
|
|
local version="$1"
|
|
local build_id="$2"
|
|
|
|
rm -rf "$STAGE_DIR"
|
|
mkdir -p "$STAGE_DIR" "dist"
|
|
copy_dir_contents "package" "$STAGE_DIR"
|
|
chmod 0755 "$STAGE_DIR/install.sh"
|
|
find "$STAGE_DIR" -type d -exec chmod 0755 {} +
|
|
find "$STAGE_DIR" -type f -name "*.service" -exec chmod 0644 {} +
|
|
find "$STAGE_DIR" -type f -name "*.tpl" -exec chmod 0644 {} +
|
|
find "$STAGE_DIR/config" -type f -exec chmod 0644 {} +
|
|
|
|
rm -rf "$STAGE_DIR/orchestrator" "$STAGE_DIR/ui" "$STAGE_DIR/metadata"
|
|
mkdir -p "$STAGE_DIR/orchestrator" "$STAGE_DIR/ui/hy2xs-admin" "$STAGE_DIR/metadata"
|
|
|
|
printf '%s\n' "$version" >"$STAGE_DIR/metadata/package.version"
|
|
printf '%s\n' "$build_id" >"$STAGE_DIR/metadata/package.build_id"
|
|
}
|
|
|
|
build_orchestrator() {
|
|
local bun_compile_target="${BUN_COMPILE_TARGET:-bun-linux-x64}"
|
|
|
|
log_info "Building orchestrator with Bun compile target: $bun_compile_target"
|
|
|
|
(
|
|
cd orchestrator
|
|
"$BUN_BIN" install --frozen-lockfile
|
|
"$BUN_BIN" build src/cli.ts --compile --target="$bun_compile_target" --outfile ../"$STAGE_DIR"/orchestrator/hy2xs-orchestrator
|
|
)
|
|
|
|
chmod 0755 "$STAGE_DIR/orchestrator/hy2xs-orchestrator"
|
|
}
|
|
|
|
bundle_ui() {
|
|
local ui_src="${UI_SRC:-apps}"
|
|
|
|
rm -rf "$ADMIN_BUILD_DIR"
|
|
mkdir -p "$ADMIN_BUILD_DIR"
|
|
|
|
(
|
|
cd "$ui_src/frontend"
|
|
|
|
local frontend_node_old_space_size="${FRONTEND_NODE_OLD_SPACE_SIZE:-2048}"
|
|
local frontend_node_options="${NODE_OPTIONS:-}"
|
|
|
|
if [[ "$frontend_node_options" != *"--max-old-space-size="* ]]; then
|
|
frontend_node_options="${frontend_node_options:+$frontend_node_options }--max-old-space-size=${frontend_node_old_space_size}"
|
|
fi
|
|
|
|
export NODE_OPTIONS="$frontend_node_options"
|
|
log_info "Frontend Node.js options: $NODE_OPTIONS"
|
|
|
|
"$PNPM_BIN" install --frozen-lockfile
|
|
"$PNPM_BIN" run build:prod
|
|
)
|
|
|
|
(
|
|
cd "$ui_src"
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GOTOOLCHAIN=local "$GO_BIN" mod download
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GOTOOLCHAIN=local "$GO_BIN" build -trimpath -ldflags "-s -w" -o "../$ADMIN_BUILD_DIR/hy2xs-admin" .
|
|
)
|
|
|
|
install -m 0755 "$ADMIN_BUILD_DIR/hy2xs-admin" "$STAGE_DIR/ui/hy2xs-admin/hy2xs-admin"
|
|
if [ -f "$ui_src/docs/sql/h_ui_db.sql" ]; then
|
|
mkdir -p "$STAGE_DIR/ui/hy2xs-admin/docs/sql"
|
|
install -m 0644 "$ui_src/docs/sql/h_ui_db.sql" "$STAGE_DIR/ui/hy2xs-admin/docs/sql/h_ui_db.sql"
|
|
fi
|
|
}
|
|
|
|
write_metadata() {
|
|
local version="$1"
|
|
local build_id="$2"
|
|
|
|
[ -f "$HYSTERIA_LOCK_FILE" ] || fail "missing Hysteria lock file: $HYSTERIA_LOCK_FILE"
|
|
# shellcheck disable=SC1090
|
|
. "$HYSTERIA_LOCK_FILE"
|
|
[ -n "${HYSTERIA_VERSION:-}" ] || fail "HYSTERIA_VERSION is required in $HYSTERIA_LOCK_FILE"
|
|
[ -n "${HYSTERIA_ARTIFACT_URL:-}" ] || fail "HYSTERIA_ARTIFACT_URL is required in $HYSTERIA_LOCK_FILE"
|
|
[ -n "${HYSTERIA_ARTIFACT_SHA256:-}" ] || fail "HYSTERIA_ARTIFACT_SHA256 is required in $HYSTERIA_LOCK_FILE"
|
|
case "$HYSTERIA_ARTIFACT_SHA256" in
|
|
replace-with-*|"")
|
|
fail "HYSTERIA_ARTIFACT_SHA256 must be a real release sha256"
|
|
;;
|
|
esac
|
|
printf '%s' "$HYSTERIA_ARTIFACT_SHA256" | grep -Eq '^[a-fA-F0-9]{64}$' \
|
|
|| fail "HYSTERIA_ARTIFACT_SHA256 must be a 64-char hex SHA256"
|
|
|
|
{
|
|
printf 'name=HY2XS\n'
|
|
printf 'version=%s\n' "$version"
|
|
printf 'build_id=%s\n' "$build_id"
|
|
printf 'build_host_os=debian13\n'
|
|
printf 'build_host_arch=amd64\n'
|
|
printf 'target_os=linux\n'
|
|
printf 'target_arch=amd64\n'
|
|
printf 'target_distro=debian\n'
|
|
printf 'target_version=13\n'
|
|
printf 'orchestrator_stack=Bun+TypeScript\n'
|
|
printf 'go_version=%s\n' "$($GO_BIN version)"
|
|
printf 'bun_version=%s\n' "$($BUN_BIN --version)"
|
|
printf 'bun_compile_target=%s\n' "${BUN_COMPILE_TARGET:-unknown}"
|
|
printf 'node_version=%s\n' "$($NODE_BIN --version)"
|
|
printf 'pnpm_version=%s\n' "$($PNPM_BIN --version)"
|
|
printf 'hysteria_source=official-upstream\n'
|
|
printf 'hysteria_target=linux-amd64\n'
|
|
printf 'hysteria_version=%s\n' "$HYSTERIA_VERSION"
|
|
printf 'hysteria_artifact_url=%s\n' "$HYSTERIA_ARTIFACT_URL"
|
|
printf 'hysteria_artifact_sha256=%s\n' "$HYSTERIA_ARTIFACT_SHA256"
|
|
} >"$STAGE_DIR/metadata/package.env"
|
|
|
|
printf '%s\n' "$HYSTERIA_VERSION" >"$STAGE_DIR/metadata/hysteria.version"
|
|
printf '%s\n' "$HYSTERIA_ARTIFACT_URL" >"$STAGE_DIR/metadata/hysteria.url"
|
|
printf '%s\n' "$HYSTERIA_ARTIFACT_SHA256" >"$STAGE_DIR/metadata/hysteria.sha256"
|
|
|
|
(
|
|
cd "$STAGE_DIR"
|
|
find . -type f ! -path './metadata/checksums.txt' -print0 \
|
|
| sort -z \
|
|
| xargs -0 sha256sum >metadata/checksums.txt
|
|
)
|
|
}
|
|
|
|
create_archive() {
|
|
local version="$1"
|
|
local archive="dist/hy2xs-install-${version}.tar.gz"
|
|
|
|
rm -f "$archive"
|
|
tar --owner=0 --group=0 --numeric-owner -C "tools/build/output" -czf "$archive" "hy2xs-install"
|
|
}
|