Dream-MachineProcurementList/scripts/dev-up.sh

39 lines
1.4 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 "- 在容器内编译前端与后端"
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
# 不再依赖宿主机 node_modules 或 dist全部在容器内完成
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"