瀏覽代碼

walle 2.0 alpha - add detection

walle 6 年之前
父節點
當前提交
e491a73494
共有 2 個文件被更改,包括 51 次插入7 次删除
  1. 23 1
      walle/api/project.py
  2. 28 6
      walle/service/deployer.py

+ 23 - 1
walle/api/project.py

@@ -17,10 +17,11 @@ from walle.model.member import MemberModel
 from walle.model.project import ProjectModel
 from walle.service.extensions import permission
 from walle.service.rbac.role import *
+from walle.service.deployer import Deployer
 
 
 class ProjectAPI(SecurityResource):
-    actions = ['members', 'copy']
+    actions = ['members', 'copy', 'detection']
 
     @permission.upper_reporter
     def get(self, action=None, project_id=None):
@@ -171,3 +172,24 @@ class ProjectAPI(SecurityResource):
         project_new_info = project_new.add(dict(project))
 
         return self.render_json(data=project_new_info)
+
+    def detection(self, project_id):
+        """
+
+        :param project_id:
+        :return:
+        """
+        # walle LOCAL_SERVER_USER => walle user
+        # show ssh_rsa.pub
+
+        # LOCAL_SERVER_USER => git
+
+        # LOCAL_SERVER_USER => target_servers
+
+
+        # webroot is directory
+
+        # remote release directory
+
+        errors = Deployer(project_id=project_id).project_detection()
+        return self.render_json(data=errors)

+ 28 - 6
walle/service/deployer.py

@@ -8,7 +8,7 @@
 import time
 from datetime import datetime
 
-import os
+import os, pwd
 import re
 from flask import current_app
 from flask_socketio import emit
@@ -108,11 +108,6 @@ class Deployer:
         self.stage = self.stage_prev_deploy
         self.sequence = 1
 
-        # 检查 当前用户
-        command = 'whoami'
-        current_app.logger.info(command)
-        result = self.local.run(command, wenv=self.config())
-
         # 检查 python 版本
         command = 'python --version'
         result = self.local.run(command, wenv=self.config())
@@ -308,6 +303,31 @@ class Deployer:
             command = 'sudo service nginx restart'
             result = waller.run(command, wenv=self.config())
 
+    def project_detection(self):
+        errors = []
+        #  walle user => walle LOCAL_SERVER_USER
+        # show ssh_rsa.pub (maybe not necessary)
+        command = 'whoami'
+        current_app.logger.info(command)
+        result = self.local.run(command, exception=False, wenv=self.config())
+        if result.failed:
+            errors.append({
+                'title': '本地免密码登录',
+                'why': result.stdout,
+                'how': '在宿主机中配置免密码登录,把walle启动用户%s的~/.ssh/ssh_rsa.pub添加到LOCAL_SERVER_USER用户%s的~/.ssh/authorized_keys。了解更多:http://walle-web.io/docs/troubleshooting.html' % (pwd.getpwuid(os.getuid())[0], current_app.config.get('LOCAL_SERVER_USER')),
+            })
+
+        # LOCAL_SERVER_USER => git
+
+        # LOCAL_SERVER_USER => target_servers
+
+
+        # webroot is directory
+
+        # remote release directory
+        return errors
+
+
     def list_tag(self):
         with self.local.cd(self.dir_codebase_project):
             command = 'git tag -l'
@@ -440,3 +460,5 @@ class Deployer:
             emit('fail', {'event': 'console', 'data': {'message': Code.code_msg[Code.deploy_fail]}}, room=self.task_id)
 
         return {'success': self.success, 'errors': self.errors}
+
+