refactor: reorganize modules and add Linux build tooling

This commit is contained in:
2026-08-09 12:41:08 +08:00
parent 86024fa81d
commit 5cc5fd92ed
1461 changed files with 4054 additions and 4724 deletions

90
scripts/build-all-linux.sh Executable file
View File

@@ -0,0 +1,90 @@
#!/usr/bin/env bash
set -Eeuo pipefail
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
readonly WORKSPACE_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
readonly MODULE_ROOT="${WORKSPACE_ROOT}/module"
readonly BUILD_ROOT="${WORKSPACE_ROOT}/builds"
readonly ENTRY_ROOT="${BUILD_ROOT}/.entries"
if ! command -v go >/dev/null 2>&1; then
echo "error: Go is not installed or is not available in PATH" >&2
exit 1
fi
if [[ ! -f "${WORKSPACE_ROOT}/go.work" ]]; then
echo "error: go.work was not found in ${WORKSPACE_ROOT}" >&2
exit 1
fi
export GOWORK="${WORKSPACE_ROOT}/go.work"
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
modules=()
while IFS= read -r -d '' go_mod; do
modules+=("$(dirname -- "${go_mod}")")
done < <(find "${MODULE_ROOT}" -type f -name go.mod -print0 | sort -z)
if (( ${#modules[@]} == 0 )); then
echo "error: no service modules were found under ${MODULE_ROOT}" >&2
exit 1
fi
mkdir -p "${BUILD_ROOT}"
mkdir -p "${ENTRY_ROOT}"
cleanup() {
rm -rf -- "${ENTRY_ROOT}"
}
trap cleanup EXIT
echo "Building ${#modules[@]} service modules..."
for module_dir in "${modules[@]}"; do
relative_path="${module_dir#"${MODULE_ROOT}/"}"
artifact_name="${relative_path//\//-}"
output="${BUILD_ROOT}/${artifact_name}"
if [[ -f "${module_dir}/cmd/main/main.go" ]]; then
entry_file="${module_dir}/cmd/main/main.go"
entry_package="./cmd/main"
elif [[ -f "${module_dir}/cmd/main.go" ]]; then
entry_file="${module_dir}/cmd/main.go"
entry_package="./cmd"
else
echo "error: service entry not found under ${module_dir}/cmd" >&2
exit 1
fi
mkdir -p "$(dirname -- "${output}")"
echo "==> ${relative_path} -> ${output#"${WORKSPACE_ROOT}/"}"
(
cd -- "${module_dir}"
package_name="$(awk '$1 == "package" { print $2; exit }' "${entry_file}")"
if [[ "${package_name}" == "main" ]]; then
go build -trimpath -o "${output}" "${entry_package}"
else
module_name="$(awk '$1 == "module" { print $2; exit }' go.mod)"
module_name="${module_name//$'\r'/}"
wrapper_dir="${ENTRY_ROOT}/${relative_path}"
wrapper_file="${wrapper_dir}/main.go"
mkdir -p "${wrapper_dir}"
printf '%s\n' \
'package main' \
'' \
"import service \"${module_name}/${entry_package#./}\"" \
'' \
'func main() {' \
$'\tservice.Run()' \
'}' >"${wrapper_file}"
go build -trimpath -o "${output}" "${wrapper_file}"
fi
)
done
echo "Build completed successfully: ${BUILD_ROOT}"

45
scripts/update-all.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -Eeuo pipefail
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
readonly WORKSPACE_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
if ! command -v go >/dev/null 2>&1; then
echo "error: Go is not installed or is not available in PATH" >&2
exit 1
fi
cd "${WORKSPACE_ROOT}"
if [[ ! -f go.work ]]; then
echo "error: go.work was not found in ${WORKSPACE_ROOT}" >&2
exit 1
fi
mapfile -t modules < <(go list -m -f '{{.Dir}}')
if (( ${#modules[@]} == 0 )); then
echo "error: no workspace modules were found" >&2
exit 1
fi
echo "Updating dependencies for ${#modules[@]} workspace modules..."
for module_dir in "${modules[@]}"; do
module_name="$(cd -- "${module_dir}" && go list -m -f '{{.Path}}')"
echo
echo "==> ${module_name} (${module_dir})"
(
cd -- "${module_dir}"
go get -u ./...
go mod tidy
)
done
echo
echo "==> Synchronizing go.work"
go work sync
echo
echo "Dependency update completed successfully. Review and test the changes before committing."