-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wechat-push): 添加 Docker 支持,包括 Dockerfile、docker-compose 和 PM2 配置
- 引入了用于构建 wechat-push 应用程序的 Dockerfile,使用 Node.js 16。 - 添加了 docker-compose.yml 以定义服务配置和环境变量。 - 创建了 pm2.json 用于使用 PM2 管理应用程序进程,支持集群和生产环境设置。 - 更新了 server-config.js 以允许通过环境变量动态配置 cron 时间。
- Loading branch information
1 parent
081c85d
commit 2f487bb
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |