Skip to content

Commit

Permalink
feat(wechat-push): 添加 Docker 支持,包括 Dockerfile、docker-compose 和 PM2 配置
Browse files Browse the repository at this point in the history
- 引入了用于构建 wechat-push 应用程序的 Dockerfile,使用 Node.js 16。
- 添加了 docker-compose.yml 以定义服务配置和环境变量。
- 创建了 pm2.json 用于使用 PM2 管理应用程序进程,支持集群和生产环境设置。
- 更新了 server-config.js 以允许通过环境变量动态配置 cron 时间。
  • Loading branch information
wangxinleo committed Dec 26, 2024
1 parent 081c85d commit 2f487bb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 使用官方 Node.js 16 镜像作为基础镜像
FROM node:16

# 设置工作目录
WORKDIR /app

# 复制 package.json 和 package-lock.json
COPY package*.json ./

# 安装项目依赖
RUN npm install -g cnpm --registry=https://registry.npm.taobao.org && cnpm install && cnpm install pm2 -g

# 复制项目文件到工作目录
COPY . .

# 暴露应用运行的端口(假设应用在3000端口运行)
EXPOSE 3000

# 使用 PM2 启动应用
CMD ["pm2-runtime", "start", "pm2.json"]
2 changes: 1 addition & 1 deletion config/server-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 此时间为每天的早上8点,*为匹配任意一个
// 这里的时间是中国时间 秒 分 时 日 月 年
const cornTime = '0 0 8 * * *'
const cornTime = process.env.CRON_TIME || '0 0 8 * * *'
export default cornTime
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.8'

services:
wechat-push:
build: .
image: wechat-push:0.0.1
volumes:
- .:/app
environment:
- NODE_ENV=production
- CRON_TIME=0 0 9 * * *
restart: always
15 changes: 15 additions & 0 deletions pm2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"apps": [
{
"name": "wechat-push",
"script": "start_pm2.js",
"instances": "max",
"exec_mode": "cluster",
"watch": false,
"env": {
"NODE_ENV": "production",
"APP_MODE": "server"
}
}
]
}

0 comments on commit 2f487bb

Please sign in to comment.