material_manage_system/scripts/deploy-build.sh
copper-xw 9c78dcb6db feat: 支持前端 go:embed 单容器部署
新增部署专用 Dockerfile.deploy / docker-compose.deploy.yml 与本机构建脚本:
前端 dist 经 go:embed 编入 Go 二进制,alpine 运行时只打包不编译,
旧 Dockerfile 与双容器编排保持不变。
2026-10-10 16:14:49 +08:00

28 lines
844 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 在本机编译前后端,产出供 Dockerfile.deploy 打包的文件。
# 产物:deploy/server(已 embed 前端 dist)、deploy/entrypoint.sh
set -euo pipefail
# 解析到服务根目录(脚本位于 scripts/)
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${ROOT}"
echo "==> 1/3 构建前端 (npm run build)"
cd frontend
[ -d node_modules ] || npm install
npm run build
cd "${ROOT}"
echo "==> 2/3 将 dist 放入 embed 目录 internal/web/dist"
rm -rf internal/web/dist
mkdir -p internal/web/dist
cp -r frontend/dist/. internal/web/dist/
echo "==> 3/3 本机编译 Go(前端嵌入二进制)"
mkdir -p deploy
CGO_ENABLED=0 GOOS=linux go build -o deploy/server ./cmd/server
cp entrypoint-deploy.sh deploy/entrypoint.sh
chmod +x deploy/entrypoint.sh
echo "done -> deploy/server (含前端)"