feat: switch to Docker Compose + auto-migration
- docker-compose.yml: 移除 MySQL 容器,后端连宿主机 MySQL - main.ts: 启动时自动 runMigrations - 前端 Nginx 反代 /api/ → backend:3000 不变
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { AppModule } from './app.module';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.setGlobalPrefix('api');
|
||||
app.enableCors();
|
||||
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
|
||||
const dataSource = app.get(DataSource);
|
||||
await dataSource.runMigrations();
|
||||
console.log('Migrations OK');
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
console.log(`Server running on http://localhost:${process.env.PORT ?? 3000}`);
|
||||
}
|
||||
|
||||
@@ -1,46 +1,25 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: gongxue_mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-gongxue_2024}
|
||||
MYSQL_DATABASE: dorm_billing_v2
|
||||
MYSQL_CHARSET: utf8mb4
|
||||
MYSQL_COLLATION: utf8mb4_unicode_ci
|
||||
ports:
|
||||
- "127.0.0.1:3306:3306"
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
- ./docker/mysql/init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
|
||||
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
interval: 5s
|
||||
retries: 10
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: apps/server/Dockerfile
|
||||
container_name: gongxue_backend
|
||||
restart: always
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
environment:
|
||||
DB_TYPE: mysql
|
||||
DB_HOST: mysql
|
||||
DB_HOST: host.docker.internal
|
||||
DB_PORT: 3306
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: ${MYSQL_ROOT_PASSWORD:-gongxue_2024}
|
||||
DB_DATABASE: dorm_billing_v2
|
||||
DB_USERNAME: ${MYSQL_ROOT_USERNAME:-root}
|
||||
DB_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
||||
DB_DATABASE: ${DB_DATABASE:-dorm_billing_v2}
|
||||
DB_SYNCHRONIZE: "false"
|
||||
JWT_SECRET: ${JWT_SECRET:-gongxue-jwt-prod-2026-k3y}
|
||||
JWT_EXPIRES_IN: 24h
|
||||
PORT: 3000
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
|
||||
frontend:
|
||||
build:
|
||||
@@ -49,9 +28,6 @@ services:
|
||||
container_name: gongxue_frontend
|
||||
restart: always
|
||||
ports:
|
||||
- "9527:80"
|
||||
- "127.0.0.1:9527:80"
|
||||
depends_on:
|
||||
- backend
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
|
||||
Reference in New Issue
Block a user