Commit bc6a7954 by 罗启

Add new file

parent 9e411ac7
# 使用 CircleCI 2.1 版本的配置语法
version: 2.1
# "Jobs" 定义了要执行的具体任务
jobs:
# 将这个任务命名为 "deploy"
deploy:
# 指定运行此任务的环境。我们选择一个预装了常用工具(如 git, ssh)的基础 Docker 镜像
docker:
- image: cimg/base:stable
# "steps" 定义了任务中要按顺序执行的具体步骤
steps:
# 第一步:添加 SSH 密钥,用于连接你的部署服务器
# CircleCI 会从你的项目设置中,加载你预先存好的那个 SSH 私钥
- add_ssh_keys:
fingerprints:
- "SHA256:VsEKAt0iuZUz4zVUWBSmFm1qS/CvL8goIsNDK8zN0VQ"
# 第二步:执行连接服务器并部署的命令
- run:
name: Connect and Deploy to Server
# 这里的 command 就是您提供的部署脚本
command: |
echo "准备连接到部署服务器..."
# 使用 ssh 命令连接你的服务器
# -p $SSH_PORT 指定了你修改后的端口
# -o StrictHostKeyChecking=no 避免了首次连接时需要手动确认主机的提示,这在自动化脚本中是必需的
# $SSH_USER 和 $SSH_HOST 是你需要在 CircleCI 网站上设置的环境变量
ssh -p 19822 -o StrictHostKeyChecking=no root@47.251.104.47 << 'EOF'
# --- 以下是在你的部署服务器上执行的命令 ---
echo "✅ 连接服务器成功,开始执行部署脚本..."
# 1. 进入你的项目工作目录
# 请确保这个目录在服务器上已经存在,并且已经从 GitLab 克隆过一次
echo "进入项目目录: performance-score"
cd performance-score
# 2. 从 master 分支拉取最新的代码
echo "正在从 GitLab (origin) 拉取最新代码..."
git pull origin master
# 3. 使用 Docker Compose 重新构建并启动服务
echo "正在使用 Docker Compose 部署..."
docker compose up -d --build
echo "🚀 部署流程执行完毕!"
# --- 远程服务器上的命令结束 ---
EOF
# "Workflows" 用来编排和组织 Jobs 的执行流程和触发条件
workflows:
# 将这个工作流命名为 "build-and-deploy"
build-and-deploy:
jobs:
- deploy:
# "filters" 是过滤器,用来定义触发此 Job 的条件
filters:
branches:
# "only" 表示只有当代码被推送到指定分支时,才执行这个 Job
only:
- master
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment