新增通过SPUG_SET动态更新配置功能

4.0
vapao 2022-10-31 16:26:13 +08:00
parent 36f9f62490
commit fe7881a0b4
5 changed files with 20 additions and 9 deletions

View File

@ -78,10 +78,10 @@ def ext2_deploy(req, helper, env, with_local):
tar_gz_file = os.path.join(REPOS_DIR, env.SPUG_DEPLOY_ID, f'{req.spug_version}.tar.gz')
helper.local_raw(f'cd {sp_dir} && tar -zcf {tar_gz_file} {exclude} {contain}')
helper.send_info('local', '打包完成\r\n')
helper.set_cross_env(req.spug_version, et.get_envs())
helper.set_deploy_success('local')
human_time = human_seconds_time(time.time() - flag)
helper.send_success('local', f'\r\n** 执行完成,耗时:{human_time} **', status='success')
helper.set_cross_env(req.spug_version, et.get_envs())
if host_actions:
env.update(helper.get_cross_env(req.spug_version))

View File

@ -4,9 +4,10 @@
from django.conf import settings
from django.template.defaultfilters import filesizeformat
from django_redis import get_redis_connection
from libs.utils import human_datetime, render_str, str_decode
from libs.utils import SpugError, human_datetime, render_str, str_decode
from libs.spug import Notification
from apps.host.models import Host
from apps.config.utils import update_config_by_var
from functools import partial
from collections import defaultdict
import subprocess
@ -15,10 +16,6 @@ import os
import re
class SpugError(Exception):
pass
class NotifyMixin:
@classmethod
def _make_dd_notify(cls, url, action, req, version, host_str):
@ -311,9 +308,19 @@ class Helper(NotifyMixin, KitMixin):
return {}
def set_cross_env(self, key, envs):
file_envs = {}
for k, v in envs.items():
if k == 'SPUG_SET':
try:
update_config_by_var(v)
except SpugError as e:
self.send_error('local', f'{e}')
elif k.startswith('SPUG_GEV_'):
file_envs[k] = v
file = os.path.join(settings.DEPLOY_DIR, key)
with open(file, 'w') as f:
f.write(json.dumps(envs))
f.write(json.dumps(file_envs))
def add_callback(self, func):
self.callback.append(func)

View File

@ -121,6 +121,6 @@ def _build(rep: Repository, helper, env):
contain = ' '.join(f'{rep.spug_version}/{x}' for x in files)
helper.local_raw(f'mkdir -p {BUILD_DIR} && cd {REPOS_DIR} && tar zcf {tar_file} {exclude} {contain}')
helper.send_success('local', '完成√\r\n')
helper.set_cross_env(rep.spug_version, et.get_envs())
human_time = human_seconds_time(time.time() - flag)
helper.send_success('local', f'\r\n** 构建成功,耗时:{human_time} **\r\n', status='success')
helper.set_cross_env(rep.spug_version, et.get_envs())

View File

@ -18,7 +18,7 @@ class Executor:
def get_envs(self):
envs = {}
_, output = self.exec_command('env | grep SPUG_GEV_')
_, output = self.exec_command('env | grep SPUG_')
if output:
for item in output.splitlines():
if '=' in item:

View File

@ -11,6 +11,10 @@ import random
import json
class SpugError(Exception):
pass
# 转换时间格式到字符串
def human_datetime(date=None):
if date: