MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / manual_rollback_deploy

Function manual_rollback_deploy

mod/project/git/scripts/deploy.py:174–208  ·  view source on GitHub ↗

手动回滚部署(有分支有commit)

(config, manual_branch, manual_commit)

Source from the content-addressed store, hash-verified

172 return True, ""
173
174def manual_rollback_deploy(config, manual_branch, manual_commit):
175 """手动回滚部署(有分支有commit)"""
176 site_name = config.get('type_parm')
177 deploy_script = config.get('deploy_script', '')
178
179 log(f"回滚代码: {site_name} -> {manual_branch} -> {manual_commit[:8]}")
180
181 # 获取网站信息
182 site_info = get_site_info(site_name)
183 if not site_info:
184 return False, "网站不存在或不是Git仓库"
185
186 site_path = site_info['path']
187 display_git_info(site_path)
188
189 # 切换分支
190 if not run_cmd(f"cd {site_path} && git checkout {manual_branch}"):
191 return False, f"切换到分支失败: {manual_branch}"
192
193 # 回滚到指定commit
194 if not run_cmd(f"cd {site_path} && git reset --hard {manual_commit}"):
195 return False, "回滚失败"
196
197 log(f"🚀 成功回退到commit: {manual_commit[:8]}!")
198
199 # 执行部署脚本
200 success, error_msg = execute_deploy_script(site_path, deploy_script)
201 if not success:
202 return False, error_msg
203
204 # 修正权限
205 run_cmd(f"chown -R www:www {site_path}")
206 log("部署完成", "✅")
207
208 return True, ""
209
210def save_deploy_log(config, success, error_msg="", deploy_mode=1):
211 """保存部署日志到数据库(总是被调用)"""

Callers 1

execute_deploymentFunction · 0.85

Calls 6

get_site_infoFunction · 0.85
display_git_infoFunction · 0.85
execute_deploy_scriptFunction · 0.85
logFunction · 0.70
run_cmdFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected