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.
This commit is contained in:
Chenwei Jiang 2025-08-21 14:46:11 +08:00
parent 3b638a9509
commit 4557728932
Signed by: cheverjohn
GPG key ID: ADC4815BFE960182
20 changed files with 1955 additions and 20 deletions

42
scripts/dev-up.sh Normal file
View file

@ -0,0 +1,42 @@
#!/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"