Commit 89fda4f2 authored by jinkaiqiang's avatar jinkaiqiang

每次克隆项目都会删除原来的目录,防止部分机子运行失败

parent aef753e0
Pipeline #28941 passed with stage
in 27 seconds
import os import os
import shutil
import stat
import git import git
from flask import Flask from flask import Flask
...@@ -13,14 +15,34 @@ deploy_repo_path = 'ssh://git@47.110.145.204:2222/hs/deploy.git' ...@@ -13,14 +15,34 @@ deploy_repo_path = 'ssh://git@47.110.145.204:2222/hs/deploy.git'
git_path = os.path.join(temp_file_dir, 'deploy') git_path = os.path.join(temp_file_dir, 'deploy')
# 初始化git仓库
if not os.path.exists(os.path.join(git_path, '.git')):
# docker环境线下老是出现问题,先用代码拉取
os.system(f'git clone {deploy_repo_path} {git_path}')
# repo = git.Repo.clone_from(url=deploy_repo_path, to_path=git_path)
# 初始化git仓库
# if not os.path.exists(os.path.join(git_path, '.git')):
# # docker环境线下老是出现问题,先用代码拉取
# os.system(f'git clone {deploy_repo_path} {git_path}')
# # repo = git.Repo.clone_from(url=deploy_repo_path, to_path=git_path)
#
# repo = git.Repo(git_path)
# repo.git.pull()
# 初始化git仓库(部分机子无法使用上次缓存的项目,直接删除上传缓存,每次都重新下载)
def readonly_handler(func, path, execinfo):
'''
在path目录下的部分文件或目录是只读的,从而会导致该操作失败,
需要在操作出错的时候,将文件或文件夹的状态修改为支持写的模式。
这里需要使用shutil.rmtree的onerror这个参数,
这里需要实现文件权限修改的回调函数,通过onerror带入。
'''
os.chmod(path, stat.S_IWRITE)
func(path)
if os.path.exists(git_path):
shutil.rmtree(git_path, onerror=readonly_handler)
# docker环境线下老是出现问题,先用代码拉取
os.system(f'git clone {deploy_repo_path} {git_path}')
repo = git.Repo(git_path) repo = git.Repo(git_path)
repo.git.pull()
class FlashAppLoader(AppLoaderBase): class FlashAppLoader(AppLoaderBase):
......
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