feat: 添加Docker配置,集成my_oss图片服务
This commit is contained in:
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["npm", "start"]
|
||||||
@@ -2,8 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
|||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
|
|
||||||
const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
||||||
const OSS_URL = 'http://localhost:9000';
|
const OSS_URL = process.env.OSS_URL || 'http://localhost:9000';
|
||||||
const API_KEY = '7cf93760ea49b750c96e6078b364e5f0';
|
const API_KEY = process.env.OSS_API_KEY || '7cf93760ea49b750c96e6078b364e5f0';
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
let imageBuffer: Buffer;
|
let imageBuffer: Buffer;
|
||||||
|
|||||||
46
docker-compose.yml
Normal file
46
docker-compose.yml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:10
|
||||||
|
container_name: smalltown_mysql
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: rootpass
|
||||||
|
MYSQL_DATABASE: smalltown
|
||||||
|
MYSQL_USER: smalltown
|
||||||
|
MYSQL_PASSWORD: MyPassword1+
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
volumes:
|
||||||
|
- mysql_data:/var/lib/mysql
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
smalltown:
|
||||||
|
build: .
|
||||||
|
container_name: smalltown_app
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- DB_HOST=mysql
|
||||||
|
- DB_PORT=3306
|
||||||
|
- DB_USER=smalltown
|
||||||
|
- DB_PASSWORD=MyPassword1+
|
||||||
|
- DB_NAME=smalltown
|
||||||
|
- OSS_URL=http://myoss:9000
|
||||||
|
- OSS_API_KEY=7cf93760ea49b750c96e6078b364e5f0
|
||||||
|
volumes:
|
||||||
|
- uploads:/app/public/uploads
|
||||||
|
depends_on:
|
||||||
|
mysql:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mysql_data:
|
||||||
|
uploads:
|
||||||
10
lib/db.ts
10
lib/db.ts
@@ -1,11 +1,11 @@
|
|||||||
import mysql from 'mysql2/promise';
|
import mysql from 'mysql2/promise';
|
||||||
|
|
||||||
const pool = mysql.createPool({
|
const pool = mysql.createPool({
|
||||||
host: '192.168.0.196',
|
host: process.env.DB_HOST || '192.168.0.196',
|
||||||
port: 3306,
|
port: parseInt(process.env.DB_PORT || '3306'),
|
||||||
user: 'smalltown',
|
user: process.env.DB_USER || 'smalltown',
|
||||||
password: 'MyPassword1+',
|
password: process.env.DB_PASSWORD || 'MyPassword1+',
|
||||||
database: 'smalltown',
|
database: process.env.DB_NAME || 'smalltown',
|
||||||
waitForConnections: true,
|
waitForConnections: true,
|
||||||
connectionLimit: 10,
|
connectionLimit: 10,
|
||||||
queueLimit: 0
|
queueLimit: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user