添加yaml 部署文件
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 4m29s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 4m29s
This commit is contained in:
parent
65f17b4a66
commit
345533ed6e
44
.gitea/workflows/deploy.yaml
Normal file
44
.gitea/workflows/deploy.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
name: Gitea Actions Demo
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'dev'
|
||||
|
||||
env:
|
||||
BUILD: staging
|
||||
|
||||
|
||||
jobs:
|
||||
Explore-Gitea-Actions:
|
||||
runs-on: stream9
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: https://gitea.yantootech.com/neil/checkout@v4
|
||||
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
|
||||
- name: List files in the repository
|
||||
run: |
|
||||
whoami
|
||||
uname -a
|
||||
pwd
|
||||
ls ${{ gitea.workspace }}
|
||||
- name: Build and push
|
||||
uses: https://gitea.yantootech.com/neil/build-push-action@v6
|
||||
with:
|
||||
push: false
|
||||
tags: emotion-digital-video:${{ gitea.run_id }}
|
||||
- name: Run docker
|
||||
run: |
|
||||
pwd
|
||||
if [ "$(docker ps -q -f name=^emotion-digital-video$)" ]; then
|
||||
docker stop emotion-digital-video
|
||||
fi
|
||||
docker run -d --rm --name emotion-digital-video \
|
||||
-v /usr/share/fonts/opentype/noto:/usr/share/fonts \
|
||||
-p 6900:3000 \
|
||||
emotion-digital-video:${{ gitea.run_id }}
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
113
Dockerfile
Normal file
113
Dockerfile
Normal file
@ -0,0 +1,113 @@
|
||||
# 使用官方Node.js运行时作为基础镜像
|
||||
FROM node:18-alpine
|
||||
|
||||
# 安装系统依赖和监控工具
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
procps \
|
||||
curl \
|
||||
&& npm install -g yarn nodemon
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制package.json和yarn.lock(如果存在)
|
||||
COPY package.json yarn.lock* ./
|
||||
|
||||
# 安装项目依赖
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
# 复制项目文件
|
||||
COPY . .
|
||||
|
||||
# 创建videos目录(如果不存在)
|
||||
RUN mkdir -p videos
|
||||
|
||||
# 创建CPU监控和重启脚本
|
||||
RUN cat > /app/monitor.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# CPU阈值设置(百分比)
|
||||
CPU_THRESHOLD=80
|
||||
# 检查间隔(秒)
|
||||
CHECK_INTERVAL=30
|
||||
# 日志文件
|
||||
LOG_FILE="/app/monitor.log"
|
||||
|
||||
log_message() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
get_cpu_usage() {
|
||||
# 获取Node.js进程的CPU使用率
|
||||
local pid=$(pgrep -f "node.*server.js" | head -1)
|
||||
if [ -n "$pid" ]; then
|
||||
ps -p $pid -o %cpu --no-headers | awk '{print int($1)}'
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
restart_app() {
|
||||
log_message "CPU使用率过高,重启应用..."
|
||||
pkill -f "node.*server.js"
|
||||
sleep 5
|
||||
cd /app
|
||||
yarn dev &
|
||||
log_message "应用已重启"
|
||||
}
|
||||
|
||||
log_message "开始CPU监控,阈值: ${CPU_THRESHOLD}%"
|
||||
|
||||
while true; do
|
||||
cpu_usage=$(get_cpu_usage)
|
||||
log_message "当前CPU使用率: ${cpu_usage}%"
|
||||
|
||||
if [ "$cpu_usage" -gt "$CPU_THRESHOLD" ]; then
|
||||
log_message "警告: CPU使用率 ${cpu_usage}% 超过阈值 ${CPU_THRESHOLD}%"
|
||||
restart_app
|
||||
fi
|
||||
|
||||
sleep $CHECK_INTERVAL
|
||||
done
|
||||
EOF
|
||||
|
||||
# 给监控脚本执行权限
|
||||
RUN chmod +x /app/monitor.sh
|
||||
|
||||
# 创建启动脚本
|
||||
RUN cat > /app/start.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# 启动应用
|
||||
echo "启动WebRTC应用..."
|
||||
cd /app
|
||||
yarn dev &
|
||||
|
||||
# 等待应用启动
|
||||
sleep 10
|
||||
|
||||
# 启动CPU监控
|
||||
echo "启动CPU监控..."
|
||||
/app/monitor.sh &
|
||||
|
||||
# 保持容器运行
|
||||
wait
|
||||
EOF
|
||||
|
||||
# 给启动脚本执行权限
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
# 暴露端口(默认3000,支持环境变量配置)
|
||||
EXPOSE 3000
|
||||
|
||||
# 设置环境变量
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD curl -f http://localhost:$PORT || exit 1
|
||||
|
||||
# 启动应用和监控
|
||||
CMD ["/app/start.sh"]
|
||||
26
docker-compose.yml
Normal file
26
docker-compose.yml
Normal file
@ -0,0 +1,26 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
webrtc-app:
|
||||
build: .
|
||||
ports:
|
||||
- "3000:3000" # 映射到主机的3000端口,外网可访问
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
volumes:
|
||||
- ./videos:/app/videos # 挂载视频文件目录
|
||||
- ./logs:/app/logs # 挂载日志目录
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
networks:
|
||||
- webrtc-network
|
||||
|
||||
networks:
|
||||
webrtc-network:
|
||||
driver: bridge
|
||||
Loading…
x
Reference in New Issue
Block a user