add docker file
This commit is contained in:
39
Dockerfile
Normal file
39
Dockerfile
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
|
# Install all dependencies (including dev dependencies for building)
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY src/ ./src/
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:20-alpine AS production
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install production dependencies only
|
||||||
|
RUN npm ci --only=production
|
||||||
|
|
||||||
|
# Copy built application from builder stage
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Start the application
|
||||||
|
CMD ["npm", "start"]
|
||||||
26
README.md
26
README.md
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
## 运行步骤
|
## 运行步骤
|
||||||
|
|
||||||
|
### 本地开发
|
||||||
1. **安装依赖:**
|
1. **安装依赖:**
|
||||||
```
|
```
|
||||||
npm install
|
npm install
|
||||||
@@ -32,6 +33,31 @@
|
|||||||
npm start # 生产模式(需预先构建)
|
npm start # 生产模式(需预先构建)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Docker Compose 部署(推荐)
|
||||||
|
1. **启动所有服务:**
|
||||||
|
```
|
||||||
|
docker-compose up --build -d
|
||||||
|
```
|
||||||
|
|
||||||
|
这将启动:
|
||||||
|
- PostgreSQL 数据库(在 `db` 服务中)
|
||||||
|
- 许可证服务器应用(在 `app` 服务中,端口 3000)
|
||||||
|
|
||||||
|
2. **检查服务状态:**
|
||||||
|
```
|
||||||
|
docker-compose ps
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **查看日志:**
|
||||||
|
```
|
||||||
|
docker-compose logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **停止服务:**
|
||||||
|
```
|
||||||
|
docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
5. **测试 API:**
|
5. **测试 API:**
|
||||||
- 健康检查:`GET http://localhost:3000/health`
|
- 健康检查:`GET http://localhost:3000/health`
|
||||||
- 许可证检查:`POST http://localhost:3000/api/license/check`
|
- 许可证检查:`POST http://localhost:3000/api/license/check`
|
||||||
|
|||||||
35
docker-compose.yml
Normal file
35
docker-compose.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- DB_HOST=db
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:15
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: kintone_license_server
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: psadmin
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
- ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
@@ -2,7 +2,7 @@ import { Pool } from 'pg';
|
|||||||
|
|
||||||
export const pool = new Pool({
|
export const pool = new Pool({
|
||||||
user: 'postgres',
|
user: 'postgres',
|
||||||
host: 'localhost',
|
host: process.env.DB_HOST || 'localhost',
|
||||||
database: 'kintone_license_server',
|
database: 'kintone_license_server',
|
||||||
password: 'psadmin',
|
password: 'psadmin',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
|
|||||||
Reference in New Issue
Block a user