Dream-MachineProcurementList/scripts/dev-up.sh

47 lines
1.6 KiB
Bash
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
set -euo pipefail
echo "[Dream-Machine] 开发环境启动"
# 自动探测宿主机平台,允许环境变量覆盖
HOST_OS=$(uname -s 2>/dev/null || echo unknown)
HOST_ARCH=$(uname -m 2>/dev/null || echo unknown)
# 如果用户误传了 darwin/arm64统一转换为 linux/arm64Docker 只支持 Linux 基础镜像)
if [ "${DOCKER_PLATFORM:-}" = "darwin/arm64" ] || [ "${DOCKER_PLATFORM:-}" = "Darwin/arm64" ]; then
DOCKER_PLATFORM=linux/arm64
fi
if [ -z "${DOCKER_PLATFORM:-}" ]; then
case "${HOST_OS}-${HOST_ARCH}" in
Darwin-arm64) DOCKER_PLATFORM=linux/arm64 ;;
Darwin-x86_64) DOCKER_PLATFORM=linux/amd64 ;;
Linux-x86_64) DOCKER_PLATFORM=linux/amd64 ;;
Linux-aarch64) DOCKER_PLATFORM=linux/arm64 ;;
*) DOCKER_PLATFORM=linux/amd64 ;;
esac
fi
echo "- 宿主机: ${HOST_OS}/${HOST_ARCH}"
echo "- 容器镜像平台: ${DOCKER_PLATFORM} (Docker 仅支持 linux/*;可通过 DOCKER_PLATFORM 覆盖)"
echo "- 将使用外部构建的前端 (dist/)"
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
if [ ! -d "$ROOT_DIR/node_modules" ]; then
echo "[提示] 未检测到 node_modules将安装依赖 (pnpm install)"
(cd "$ROOT_DIR" && pnpm install)
fi
if [ ! -d "$ROOT_DIR/dist" ]; then
echo "[提示] 未检测到 dist/,将进行前端构建 (pnpm build)"
(cd "$ROOT_DIR" && pnpm run build)
fi
echo "[步骤] 启动 Docker Compose (开发)"
(cd "$ROOT_DIR/docker" && DOCKER_PLATFORM=${DOCKER_PLATFORM} docker compose -f docker-compose.dev.yml up -d --build)
echo "[完成] API: http://localhost:3004"