def deploy_agent(self): if SUSE and platform.version.startswith('10'): system = 'suse10-{}'.format(platform.cpu) else: system = '{}-{}'.format(platform.system, platform.cpu) if WINDOWS: postfix = 'zip' python_path = 'venv/Scripts/python.exe' else: postfix = 'tar.gz' python_path = 'venv/bin/python' build_cmd = AGENT_BUILD_TEMPLATE_CMD.format( pyton=python_path, branch=self.project_branch, system=system) agent_version = get_version( '{}/manifest.yaml'.format(self.project_name)) agent_name = 'agent-{}-{}-{}.{}'.format(system, platform.cpu, agent_version, postfix) with cd(self.project_name): execute(build_cmd) local_path = os.path.join('dist', agent_name) server_path = REPO_DIR scp_upload_file(local_path, server_path)
def deploy_manager_web(self): with cd(self.project_name): execute(['npm', 'install']) execute(['npm', 'run', 'build']) for filename in ['static', 'frontend', 'build', 'index.html']: local_path = os.path.join(self.project_name, filename) server_path = INSTALL_DIR[self.project_name] scp_upload_file(local_path, server_path)
def _check(project_name, project_url, project_branch='master'): if not nfs.exists(project_name): execute('git clone {} {}'.format(project_url, project_name)) with cd(project_name): execute('git checkout {}'.format(project_branch)) else: with cd(project_name): execute('git checkout {}'.format(project_branch)) execute('git pull')
def deploy_manager(self): with cd(self.project_name): execute('mvn clean install -Dmaven.test.skip=true') cmd = 'sh {}/bin/stop.sh'.format(INSTALL_DIR[self.project_name]) excutor_cmd(cmd) for file in ['manager-core/bin', 'manager-core/lib', 'manager-core/module']: local_path = os.path.join(self.project_name, file) server_path = INSTALL_DIR[self.project_name] scp_upload_file(local_path, server_path) scp_upload_file( '{}/manager-core/conf/i18n'.format(self.project_name), '{}/conf/il8n'.format(INSTALL_DIR[self.project_name])) scp_upload_file( '{}/manager-core/conf/web.xml'.format(self.project_name), '{}/conf/web.xml'.format(INSTALL_DIR[self.project_name])) cmd = 'source /etc/profile && su - uyun -c "sh {}/bin/start.sh"' \ .format(INSTALL_DIR[self.project_name]) excutor_cmd(cmd)
def deploy_dispatcher(self): with cd(self.project_name): execute(['../node/bin/node', '../node/bin/yarn']) execute(['../node/bin/node', '../node/lib/node_modules/npm/bin/npm-cli.js', 'run', 'build']) if nfs.exists('dispatcher'): nfs.remove('dispatcher') nfs.rename('dist', 'dispatcher') cmd = 'su uyun -c "pm2 delete all"' excutor_cmd(cmd) for file in ['node_modules', 'bin', 'scripts', 'install.sh', 'uninstall.sh', 'check_status.sh', 'dispatcher']: local_path = os.path.join(self.project_name, file) server_path = INSTALL_DIR[self.project_name] scp_upload_file(local_path, server_path) cmd = 'cd {} && su uyun -c "pm2 start process.json"'.format( INSTALL_DIR[self.project_name]) excutor_cmd(cmd)
def _test_agent(self): with cd(self.project_name): production = 'requirements/production.txt' development = 'requirements/development.txt' # 修改 production if AIX or SUSE: with open(production) as f: lines = f.readlines() lines = [ line for line in lines if not line.strip().startswith('paramiko') ] with open(production, 'w') as f: f.writelines(lines) # pip 安装依赖 python, pip = maybe_download_python() if WINDOWS: execute([pip, 'install', '-U', '-r', development], shell=False) else: execute([python, pip, 'install', '-U', '-r', development], shell=False) # 单元测试 execute([python, '-m', 'pytest', 'framework'], shell=False)