Dream-MachineProcurementList/scripts/dev-up.sh
Chever John 4557728932
Adds Docker setup and basic API endpoints
WHAT: Introduces Dockerfiles for development and production, Docker Compose configurations, a Makefile for common tasks, shell scripts for environment setup/teardown, a basic Express API with SQLite integration.
WHY: Enables easy setup and deployment of the application using Docker. Provides basic API endpoints for managing purchase items.
HOW:
- Creates `docker-compose.dev.yml` and `docker-compose.prod.yml` to define services and volumes.
- Introduces `Dockerfile.dev` and `Dockerfile.prod` to build container images with necessary dependencies.
- Adds `Makefile` with commands for building, running, and managing the application.
- Implements shell scripts for simplified Docker environment management.
- Sets up Express API with endpoints for CRUD operations on purchase items, using SQLite as the database.
- Uses `better-sqlite3` to connect and interact with the SQLite database.
2025-08-21 14:46:11 +08:00

42 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 "- 将使用外部构建的前端 (dist/)"
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
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:8080"