deploy.sh
This commit is contained in:
1 parent
888e8f3054
commit
137d9508ae
1 file changed
+14
-3
@@ -31,12 +31,23 @@ echo "🏗️ 构建前端资源..."
|
||||
# 如果我们想在服务器构建,最好修改 Dockerfile 为多阶段构建,或者使用临时容器
|
||||
# 这里我们采用临时 node 容器构建 dist,然后让 docker-compose build 复制进去
|
||||
|
||||
# 清理旧 dist
|
||||
rm -rf frontend/dist
|
||||
# frontend 目录与当前用户信息
|
||||
FRONTEND_DIR="$(pwd)/frontend"
|
||||
HOST_UID="$(id -u)"
|
||||
HOST_GID="$(id -g)"
|
||||
|
||||
# 清理旧构建产物(通过容器执行,兼容历史 root 权限文件)
|
||||
echo " Cleaning old dist/node_modules..."
|
||||
docker run --rm -v "${FRONTEND_DIR}:/app" -w /app node:22-alpine sh -c "rm -rf dist node_modules"
|
||||
|
||||
# 使用临时容器构建
|
||||
echo " Running npm install & build in docker..."
|
||||
docker run --rm -v $(pwd)/frontend:/app -w /app node:22-alpine sh -c "npm install && npm run build"
|
||||
docker run --rm \
|
||||
-u "${HOST_UID}:${HOST_GID}" \
|
||||
-e npm_config_cache=/tmp/.npm \
|
||||
-v "${FRONTEND_DIR}:/app" \
|
||||
-w /app \
|
||||
node:22-alpine sh -c "npm install && npm run build"
|
||||
|
||||
if [ ! -d "frontend/dist" ]; then
|
||||
echo "❌ 前端构建失败: frontend/dist 目录未生成"
|
||||
|
||||
Reference in new issue
Block a user