From 2d755ddceec11904ec58d94f6682061f98877da4 Mon Sep 17 00:00:00 2001 From: vapao Date: Thu, 9 Jan 2020 22:27:13 +0800 Subject: [PATCH] U api update --- spug_api/apps/deploy/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spug_api/apps/deploy/utils.py b/spug_api/apps/deploy/utils.py index 80b7a0e..9210410 100644 --- a/spug_api/apps/deploy/utils.py +++ b/spug_api/apps/deploy/utils.py @@ -32,9 +32,9 @@ def deploy_dispatch(request, req, token): ) if req.deploy.extend == '1': env.update(json.loads(req.deploy.extend_obj.custom_envs)) - _ext1_deploy(request, req, helper, env) + _ext1_deploy(req, helper, env) else: - _ext2_deploy(request, req, helper, env) + _ext2_deploy(req, helper, env) req.status = '3' except Exception as e: req.status = '-3' @@ -45,7 +45,7 @@ def deploy_dispatch(request, req, token): req.save() -def _ext1_deploy(request, req, helper, env): +def _ext1_deploy(req, helper, env): extend = req.deploy.extend_obj extras = json.loads(req.extra) if extras[0] == 'branch': @@ -90,7 +90,7 @@ def _ext1_deploy(request, req, helper, env): raise t.exception() -def _ext2_deploy(request, req, helper, env): +def _ext2_deploy(req, helper, env): extend = req.deploy.extend_obj extras = json.loads(req.extra) host_actions = json.loads(extend.host_actions) @@ -123,7 +123,7 @@ def _deploy_ext1_host(helper, h_id, extend, env): if code == 0: helper.send_error(host.id, f'please make sure the {extend.dst_dir!r} is not exists.') # 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}') # transfer files 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})) 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) while True: message = task.stdout.readline() @@ -209,8 +209,7 @@ class Helper: self.send_error('local', f'exit code: {task.returncode}') def remote(self, key, ssh, command, env=None): - # print(f'helper.remote: {command!r} env: {env!r}') - code = -1 + command, code = 'set -e\n' + command, -1 try: for code, out in ssh.exec_command_with_stream(command, environment=env): self.send_info(key, out)