mirror of https://github.com/openspug/spug
U api update
parent
2519ffad33
commit
2d755ddcee
|
@ -32,9 +32,9 @@ def deploy_dispatch(request, req, token):
|
||||||
)
|
)
|
||||||
if req.deploy.extend == '1':
|
if req.deploy.extend == '1':
|
||||||
env.update(json.loads(req.deploy.extend_obj.custom_envs))
|
env.update(json.loads(req.deploy.extend_obj.custom_envs))
|
||||||
_ext1_deploy(request, req, helper, env)
|
_ext1_deploy(req, helper, env)
|
||||||
else:
|
else:
|
||||||
_ext2_deploy(request, req, helper, env)
|
_ext2_deploy(req, helper, env)
|
||||||
req.status = '3'
|
req.status = '3'
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
req.status = '-3'
|
req.status = '-3'
|
||||||
|
@ -45,7 +45,7 @@ def deploy_dispatch(request, req, token):
|
||||||
req.save()
|
req.save()
|
||||||
|
|
||||||
|
|
||||||
def _ext1_deploy(request, req, helper, env):
|
def _ext1_deploy(req, helper, env):
|
||||||
extend = req.deploy.extend_obj
|
extend = req.deploy.extend_obj
|
||||||
extras = json.loads(req.extra)
|
extras = json.loads(req.extra)
|
||||||
if extras[0] == 'branch':
|
if extras[0] == 'branch':
|
||||||
|
@ -90,7 +90,7 @@ def _ext1_deploy(request, req, helper, env):
|
||||||
raise t.exception()
|
raise t.exception()
|
||||||
|
|
||||||
|
|
||||||
def _ext2_deploy(request, req, helper, env):
|
def _ext2_deploy(req, helper, env):
|
||||||
extend = req.deploy.extend_obj
|
extend = req.deploy.extend_obj
|
||||||
extras = json.loads(req.extra)
|
extras = json.loads(req.extra)
|
||||||
host_actions = json.loads(extend.host_actions)
|
host_actions = json.loads(extend.host_actions)
|
||||||
|
@ -123,7 +123,7 @@ def _deploy_ext1_host(helper, h_id, extend, env):
|
||||||
if code == 0:
|
if code == 0:
|
||||||
helper.send_error(host.id, f'please make sure the {extend.dst_dir!r} is not exists.')
|
helper.send_error(host.id, f'please make sure the {extend.dst_dir!r} is not exists.')
|
||||||
# clean
|
# clean
|
||||||
clean_command = f'ls -rd {env.SPUG_APP_ID}_* | tail -n +{extend.versions + 1} | xargs rm -rf'
|
clean_command = f'ls -rd {extend.deploy_id}_* | tail -n +{extend.versions + 1} | xargs rm -rf'
|
||||||
helper.remote(host.id, ssh, f'cd {extend.dst_repo} && rm -rf {env.SPUG_VERSION} && {clean_command}')
|
helper.remote(host.id, ssh, f'cd {extend.dst_repo} && rm -rf {env.SPUG_VERSION} && {clean_command}')
|
||||||
# transfer files
|
# transfer files
|
||||||
tar_gz_file = f'{env.SPUG_VERSION}.tar.gz'
|
tar_gz_file = f'{env.SPUG_VERSION}.tar.gz'
|
||||||
|
@ -198,7 +198,7 @@ class Helper:
|
||||||
self.rds.rpush(self.token, json.dumps({'key': key, 'step': step, 'data': data}))
|
self.rds.rpush(self.token, json.dumps({'key': key, 'step': step, 'data': data}))
|
||||||
|
|
||||||
def local(self, command, env=None):
|
def local(self, command, env=None):
|
||||||
# print(f'helper.local: {command!r}')
|
command = 'set -e\n' + command
|
||||||
task = subprocess.Popen(command, env=env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
task = subprocess.Popen(command, env=env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
while True:
|
while True:
|
||||||
message = task.stdout.readline()
|
message = task.stdout.readline()
|
||||||
|
@ -209,8 +209,7 @@ class Helper:
|
||||||
self.send_error('local', f'exit code: {task.returncode}')
|
self.send_error('local', f'exit code: {task.returncode}')
|
||||||
|
|
||||||
def remote(self, key, ssh, command, env=None):
|
def remote(self, key, ssh, command, env=None):
|
||||||
# print(f'helper.remote: {command!r} env: {env!r}')
|
command, code = 'set -e\n' + command, -1
|
||||||
code = -1
|
|
||||||
try:
|
try:
|
||||||
for code, out in ssh.exec_command_with_stream(command, environment=env):
|
for code, out in ssh.exec_command_with_stream(command, environment=env):
|
||||||
self.send_info(key, out)
|
self.send_info(key, out)
|
||||||
|
|
Loading…
Reference in New Issue