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:
parent
3b638a9509
commit
4557728932
20 changed files with 1955 additions and 20 deletions
24
scripts/prod-build.sh
Normal file
24
scripts/prod-build.sh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[Dream-Machine] 生产镜像构建"
|
||||
echo "- 环境要求: 前端包 dist/ 已在宿主机构建完成"
|
||||
echo "- 目标平台: linux/amd64"
|
||||
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
ROOT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
|
||||
|
||||
if [ ! -d "$ROOT_DIR/dist" ]; then
|
||||
echo "[错误] 未检测到 dist/。请先在宿主机运行: pnpm run build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[步骤] 安装并构建后端 (宿主机)"
|
||||
(cd "$ROOT_DIR/server" && pnpm install && pnpm run build)
|
||||
|
||||
echo "[步骤] 构建生产镜像 (仅打包、禁止在容器内构建)"
|
||||
(cd "$ROOT_DIR/docker" && docker buildx build --platform linux/amd64 -f Dockerfile.prod -t dm-purchase-api:prod ..)
|
||||
|
||||
echo "[完成] 镜像: dm-purchase-api:prod"
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue