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

View file

@ -17,6 +17,8 @@ NODE_MODULES = node_modules
# 包管理器自动检测(优先 pnpm否者回退 npm
PKG = $(shell command -v pnpm >/dev/null 2>&1 && echo pnpm || echo npm)
# Docker平台由 scripts/dev-up.sh 自动探测,可通过环境变量 DOCKER_PLATFORM 覆盖)
# 默认目标
.PHONY: help
help: ## 显示帮助信息
@ -146,5 +148,31 @@ quick-build: lint build ## 快速构建(检查代码并构建)
test-flow: clean-install lint build preview ## 完整测试流程
@echo "$(GREEN)完整测试流程完成!$(RESET)"
# ----- Docker 开发/生产 -----
.PHONY: dev-up
dev-up: ## 启动开发环境 (自动探测平台;可通过 DOCKER_PLATFORM=linux/arm64 覆盖)
@echo "$(GREEN)启动开发环境 (Docker)$(RESET)"
bash scripts/dev-up.sh
.PHONY: prod-build
prod-build: build ## 构建生产镜像 (前端在宿主机构建)
@echo "$(GREEN)构建生产镜像 (linux/amd64)$(RESET)"
bash scripts/prod-build.sh
.PHONY: prod-up
prod-up: ## 启动生产环境 (使用生产镜像)
@echo "$(GREEN)启动生产环境 (linux/amd64)$(RESET)"
bash scripts/prod-up.sh
.PHONY: dev-down
dev-down: ## 停止开发环境 (保留数据卷)
@echo "$(YELLOW)停止开发环境 (Docker)$(RESET)"
bash scripts/dev-down.sh
.PHONY: prod-down
prod-down: ## 停止生产环境 (保留数据卷)
@echo "$(YELLOW)停止生产环境 (Docker)$(RESET)"
bash scripts/prod-down.sh
# 设置默认目标
.DEFAULT_GOAL := help