This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.tgz
|
||||
80
build.sh
Executable file
80
build.sh
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ADMIN_DIR="$ROOT_DIR/frontend/admin"
|
||||
WECHAT_DIR="$ROOT_DIR/frontend/wechat"
|
||||
BACKEND_DIR="$ROOT_DIR/backend"
|
||||
DOCKER_IMAGE="${DOCKER_IMAGE:-rogeecn/quyun}"
|
||||
NPM_REGISTRY="${NPM_REGISTRY:-https://npm.hub.ipao.vip}"
|
||||
GO_PROXY="${GO_PROXY:-https://go.hub.ipao.vip}" # fallback adds ,direct when exported
|
||||
GO_NO_PROXY="${GO_NO_PROXY:-git.ipao.vip}"
|
||||
IMAGE_ARCHIVE="${IMAGE_ARCHIVE:-$ROOT_DIR/quyun.tgz}"
|
||||
|
||||
log() {
|
||||
printf '\n==> %s\n' "$1"
|
||||
}
|
||||
|
||||
die() {
|
||||
printf 'Error: %s\n' "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
ensure_bun() {
|
||||
if command -v bun >/dev/null 2>&1; then
|
||||
return
|
||||
fi
|
||||
log "Installing bun via npm"
|
||||
npm install -g bun || die "Failed to install bun"
|
||||
}
|
||||
|
||||
run_frontend_build() {
|
||||
local dir="$1"
|
||||
local label="$2"
|
||||
|
||||
[[ -d "$dir" ]] || die "Missing frontend directory $dir"
|
||||
log "Building ${label}"
|
||||
pushd "$dir" >/dev/null
|
||||
bun install
|
||||
bun run build
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
build_backend() {
|
||||
[[ -d "$BACKEND_DIR" ]] || die "Missing backend directory"
|
||||
log "Tidying Go modules"
|
||||
pushd "$BACKEND_DIR" >/dev/null
|
||||
export GOPROXY="${GO_PROXY},direct"
|
||||
export GONOPROXY="$GO_NO_PROXY"
|
||||
export GONOSUMDB="$GO_NO_PROXY"
|
||||
go mod tidy
|
||||
log "Building Go binary"
|
||||
mkdir -p build
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/app .
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
build_image() {
|
||||
log "Building Docker image ${DOCKER_IMAGE}:latest"
|
||||
sudo docker build -f Dockerfile -t "${DOCKER_IMAGE}:latest" "$ROOT_DIR"
|
||||
}
|
||||
|
||||
export_image() {
|
||||
log "Exporting image to ${IMAGE_ARCHIVE}"
|
||||
sudo docker save "${DOCKER_IMAGE}:latest" | gzip -c > "$IMAGE_ARCHIVE"
|
||||
}
|
||||
|
||||
main() {
|
||||
export NPM_CONFIG_REGISTRY="$NPM_REGISTRY"
|
||||
export npm_config_registry="$NPM_REGISTRY"
|
||||
|
||||
ensure_bun
|
||||
run_frontend_build "$ADMIN_DIR" "frontend/Admin"
|
||||
run_frontend_build "$WECHAT_DIR" "frontend/Wechat"
|
||||
build_backend
|
||||
build_image
|
||||
export_image
|
||||
log "Build finished"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user