Skip to content

Commit

Permalink
Merge pull request #97 from kuafuai/feat/optimize
Browse files Browse the repository at this point in the history
Feat/optimize
  • Loading branch information
yakeJiang authored Sep 1, 2023
2 parents c0d815a + 4acfbc2 commit db2461f
Show file tree
Hide file tree
Showing 37 changed files with 917 additions and 107 deletions.
7 changes: 5 additions & 2 deletions backend/app/controllers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ def add():
default_target_branch = request.json.get('app_default_target_branch')
description = request.json.get('app_description')
services = request.json.get('service')
cd_config = request.json.get('app_cd_config')
ci_config = request.json.get('app_ci_config')
git_config = request.json.get('app_git_config')
creater = session['username']

try:
if app_id:
app = Application.update_application(app_id, name=name, description=description, default_source_branch=default_source_branch, default_target_branch=default_target_branch)
app = Application.update_application(app_id, name=name, description=description, default_source_branch=default_source_branch, default_target_branch=default_target_branch, cd_config=cd_config, ci_config=ci_config, git_config=git_config)
ApplicationService.delete_service_by_app_id(app_id)
appID = app_id
else:
app = Application.create(tenant_id, creater, name, description, default_source_branch, default_target_branch)
app = Application.create(tenant_id, creater, name, description, default_source_branch, default_target_branch, git_config, ci_config, cd_config)
appID = app.app_id

for service in services:
Expand Down
80 changes: 79 additions & 1 deletion backend/app/controllers/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from flask import Blueprint
from app.pkgs.tools.i18b import getI18n
from app.models.setting import getGitConfigList, getCIConfigList, getCDConfigList, getLLMConfigList
from app.models.tenant_git_config_pro import TenantGitConfig
from app.models.tenant_cd_config_pro import TenantCDConfig
from app.models.tenant_ci_config_pro import TenantCIConfig

bp = Blueprint('setting', __name__, url_prefix='/setting')

Expand Down Expand Up @@ -46,10 +49,85 @@ def get_cd_config_list():
@json_response
def get_llm_config_list():
_ = getI18n("controllers")
raise Exception(_("Failed to get git config list."))
tenantID = session['tenant_id']

gitList, success = getLLMConfigList(tenantID, 0)
if not success:
raise Exception(_("Failed to get git config list."))

return gitList
return gitList

@bp.route('/edit_git', methods=['POST'])
@json_response
def edit_git():
_ = getI18n("controllers")
git_email = request.json.get('git_email')
git_provider = request.json.get('git_provider')
git_token = request.json.get('git_token')
git_url = request.json.get('git_url')
git_username = request.json.get('git_username')
git_config_id = request.json.get('git_config_id')
name = request.json.get('git_name')
creater = session['username']
tenant_id = session['tenant_id']

try:
if git_config_id:
TenantGitConfig.update_config(git_config_id, name=name, git_email=git_email, git_provider=git_provider, git_token=git_token, git_url=git_url, git_username=git_username)
id = git_config_id
else:
data = TenantGitConfig.create_config(tenant_id, creater, name, git_url, git_token, git_provider, git_username, git_email)
id = data.git_config_id

return {'success': id}
except Exception as e:
raise Exception(_("Failed to edit setting."))

@bp.route('/edit_ci', methods=['POST'])
@json_response
def edit_ci():
_ = getI18n("controllers")
ci_api_url = request.json.get('ci_api_url')
ci_token = request.json.get('ci_token')
ci_provider = request.json.get('ci_provider')
ci_config_id = request.json.get('ci_config_id')
name = request.json.get('ci_name')
creater = session['username']
tenant_id = session['tenant_id']

try:
if ci_config_id:
TenantCIConfig.update_config(ci_config_id, name=name, ci_api_url=ci_api_url, ci_token=ci_token, ci_provider=ci_provider)
id = ci_config_id
else:
data = TenantCIConfig.create_config(tenant_id, creater, name, ci_api_url, ci_token, ci_provider)
id = data.ci_config_id

return {'success': id}
except Exception as e:
raise Exception(_("Failed to edit setting."))

@bp.route('/edit_cd', methods=['POST'])
@json_response
def edit_cd():
_ = getI18n("controllers")
cd_config_id = request.json.get('cd_config_id')
access_key = request.json.get('ACCESS_KEY')
secret_key = request.json.get('SECRET_KEY')
cd_provider = request.json.get('cd_provider')
name = request.json.get('cd_name')
creater = session['username']
tenant_id = session['tenant_id']

try:
if cd_config_id:
TenantCDConfig.update_config(cd_config_id, name=name, access_key=access_key, secret_key=secret_key, cd_provider=cd_provider)
id = cd_config_id
else:
data = TenantCDConfig.create_config(tenant_id, creater, name, access_key, secret_key, cd_provider)
id = data.cd_config_id

return {'success': id}
except Exception as e:
raise Exception(_("Failed to edit setting."))
14 changes: 13 additions & 1 deletion backend/app/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
class Application(db.Model):
app_id = db.Column(db.Integer, primary_key=True)
tenant_id = db.Column(db.Integer, nullable=False)
git_config = db.Column(db.Integer, nullable=False)
ci_config = db.Column(db.Integer, nullable=False)
cd_config = db.Column(db.Integer, nullable=False)
creater = db.Column(db.String(255), nullable=False)
name = db.Column(db.String(255), nullable=False)
description = db.Column(db.Text)
default_source_branch = db.Column(db.String(255))
default_target_branch = db.Column(db.String(255))

def create(tenant_id, creater, name, description, default_source_branch, default_target_branch):
def create(tenant_id, creater, name, description, default_source_branch, default_target_branch, git_config, ci_config, cd_config):
if not tenant_id:
tenant_id = 0

app = Application(
tenant_id=tenant_id,
creater=creater,
name=name,
git_config=git_config,
ci_config=ci_config,
cd_config=cd_config,
description=description,
default_source_branch=default_source_branch,
default_target_branch=default_target_branch
Expand All @@ -40,6 +46,9 @@ def get_all_application(owner, appID):
'tenant_id': app.tenant_id,
'creater': app.creater,
'name': app.name,
'git_config': app.git_config,
'ci_config': app.ci_config,
'cd_config': app.cd_config,
'description': app.description,
'default_source_branch': app.default_source_branch,
'default_target_branch': app.default_target_branch,
Expand All @@ -56,6 +65,9 @@ def get_application_by_id(appID):
'tenant_id': app.tenant_id,
'creater': app.creater,
'name': app.name,
'git_config': app.git_config,
'ci_config': app.ci_config,
'cd_config': app.cd_config,
'description': app.description,
'default_source_branch': app.default_source_branch,
'default_target_branch': app.default_target_branch,
Expand Down
2 changes: 2 additions & 0 deletions backend/app/models/application_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ApplicationService(db.Model):
STATUS_DELETE = "DELETED"
STATUS_OK = "OK"

LANGUAGE_JAVA = "Java"

def create_service(app_id, name, git_path, git_workflow, role, language, framework, database, api_type, api_location,
cd_container_name, cd_container_group, cd_region, cd_public_ip, cd_security_group, cd_subnet, struct_cache):
service = ApplicationService(
Expand Down
3 changes: 3 additions & 0 deletions backend/app/models/setting_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SettingBasic(SettingInterface):
def getGitConfigList(self, tenantID, appID):
gitList = []
gitList.append({
"name" : "Default(from env.yaml)",
"git_provider" : DEVOPS_TOOLS,
"git_url" : GIT_URL,
"git_token" : GIT_TOKEN,
Expand All @@ -18,6 +19,7 @@ def getGitConfigList(self, tenantID, appID):
def getCIConfigList(self, tenantID, appID):
gitList = []
gitList.append({
"name" : "Default(from env.yaml)",
"ci_provider" : DEVOPS_TOOLS,
"ci_config_id" : 0,
"ci_api_url" : GIT_API,
Expand All @@ -30,6 +32,7 @@ def getCIConfigList(self, tenantID, appID):
def getCDConfigList(self, tenantID, appID):
gitList = []
gitList.append({
"name" : "Default(from env.yaml)",
"cd_provider" : CD_TOOLS,
"ACCESS_KEY" : CD_ACCESS_KEY,
"SECRET_KEY" : CD_SECRET_KEY,
Expand Down
3 changes: 3 additions & 0 deletions backend/app/models/tenant_cd_config_pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class TenantCDConfig():
def test():
pass
3 changes: 3 additions & 0 deletions backend/app/models/tenant_ci_config_pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class TenantCIConfig():
def test():
pass
3 changes: 3 additions & 0 deletions backend/app/models/tenant_git_config_pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class TenantGitConfig():
def test():
pass
12 changes: 6 additions & 6 deletions backend/app/pkgs/devops/devops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def triggerPipeline(requirementID, branchName, serviceInfo, ciConfig):

if DEVOPS_TOOLS == 'local':
obj = DevopsLocal()
elif DEVOPS_TOOLS == 'gitlab':
elif DEVOPS_TOOLS == 'gitlab' or DEVOPS_TOOLS == 'GitLab':
obj = DevopsGitlab()
elif DEVOPS_TOOLS == 'github':
elif DEVOPS_TOOLS == 'github' or DEVOPS_TOOLS == 'GitHub':
obj = DevopsGitHub()

result, piplineID, piplineUrl, success = obj.triggerPipeline(branchName, serviceInfo, ciConfig)
Expand All @@ -26,9 +26,9 @@ def getPipelineStatus(piplineId, repoPath, ciConfig):

if DEVOPS_TOOLS == 'local':
obj = DevopsLocal()
elif DEVOPS_TOOLS == 'gitlab':
elif DEVOPS_TOOLS == 'gitlab' or DEVOPS_TOOLS == 'GitLab':
obj = DevopsGitlab()
elif DEVOPS_TOOLS == 'github':
elif DEVOPS_TOOLS == 'github' or DEVOPS_TOOLS == 'GitHub':
obj = DevopsGitHub()

return obj.getPipelineStatus(piplineId, repoPath, ciConfig)
Expand All @@ -38,9 +38,9 @@ def getPipelineJobLogs(repopath, pipeline_id, job_id, ciConfig):

if DEVOPS_TOOLS == 'local':
obj = DevopsLocal()
elif DEVOPS_TOOLS == 'gitlab':
elif DEVOPS_TOOLS == 'gitlab' or DEVOPS_TOOLS == 'GitLab':
obj = DevopsGitlab()
elif DEVOPS_TOOLS == 'github':
elif DEVOPS_TOOLS == 'github' or DEVOPS_TOOLS == 'GitHub':
obj = DevopsGitHub()

return obj.getPipelineJobLogs(obj, repopath, pipeline_id, job_id, ciConfig)
5 changes: 3 additions & 2 deletions backend/app/pkgs/devops/devops_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

class DevopsGitHub(DevopsInterface):
def triggerPipeline(self, branch_name, serviceInfo, ciConfig):
gitURL = ciConfig["git_url"]
print(ciConfig)

ciURL = ciConfig["ci_api_url"]
ciToken = ciConfig["ci_token"]
repopath = serviceInfo["git_path"]
Expand Down Expand Up @@ -39,7 +40,7 @@ def triggerPipeline(self, branch_name, serviceInfo, ciConfig):
run_id = run["id"]
break

return "Get pipline status...", run_id, f"{gitURL}/{repopath}/actions/runs/{run_id}", True
return "Get pipline status...", run_id, f"{repopath}/actions/runs/{run_id}", True
else:
return f"Failed to trigger pipeline giturl:{ciURL} repopath:{repopath} branch:{branch_name} gitWorkflow:{gitWorkflow}, Error: {str(e)}", 0, "", False
except Exception as e:
Expand Down
16 changes: 16 additions & 0 deletions backend/app/pkgs/tools/i18b.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,20 @@ def getFrontendText():
"bill_date": _("Billing date"),
"remarks": _("Remarks"),
"operate": _("Operate"),
"git_provider": _("Git provider"),
"git_url": _("Git URL"),
"git_token": _("Git token"),
"git_username": _("Git username"),
"git_email": _("Git email"),
"ci_token": _("CI Token"),
"ci_api_url": _("CI API URL"),
"ci_provider": _("CI provider"),
"cd_provider": _("CD provider"),
"ACCESS_KEY": _("ACCESS_KEY"),
"SECRET_KEY": _("SECRET_KEY"),
"configuration": _("Configuration"),
"config_name": _("Config name"),
"app_cd_config": _("Associated CD Config"),
"app_ci_config": _("Associated CI Config"),
"app_git_config": _("Associated Git Config"),
}
Binary file modified db/database.db
Binary file not shown.
14 changes: 13 additions & 1 deletion frontend/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="./static/js/diff.min.js"></script>
<script src="./static/js/coder.js?v=75"></script>
<script src="./static/js/app.js?v=75"></script>
<script src="./static/js/setting.js?v=75"></script>
</head>

<body>
Expand All @@ -29,7 +30,6 @@
<a class="item" href="index.html"><span class="f_start_task"></span></a>
<a class="item" href="requirement.html"><span class="f_requirement_list"></span></a>
<a class="active item" href="app.html"><span class="f_app_list"></span></a>
<a class="item" href="setting.html"><span class="f_setting"></span></a>
<a href="#" class="ui right floated dropdown item">
<span class="f_more_operations"></span> <i class="dropdown icon"></i>
<div class="menu">
Expand Down Expand Up @@ -88,6 +88,18 @@
<label><span class="f_app_feat_branch"></span></label>
<input type="text" id="app_default_target_branch">
</div>
<div class="field">
<label><span class="f_app_git_config"></span></label>
<select class="ui fluid dropdown" id="app_git_config"></select>
</div>
<div class="field">
<label><span class="f_app_ci_config"></span></label>
<select class="ui fluid dropdown" id="app_ci_config"></select>
</div>
<div class="field">
<label><span class="f_app_cd_config"></span></label>
<select class="ui fluid dropdown" id="app_cd_config"></select>
</div>
<div class="field" style="margin-bottom:20px">
<button class="ui linkedin button" id="add-service">
<i class="plus square outline icon"></i>
Expand Down
1 change: 0 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<a class="active item" href="index.html"><span class="f_start_task"></span></a>
<a class="item" href="requirement.html"><span class="f_requirement_list"></span></a>
<a class="item" href="app.html"><span class="f_app_list"></span></a>
<a class="item" href="setting.html"><span class="f_setting"></span></a>
<a href="#" class="ui right floated dropdown item">
<span class="f_more_operations"></span> <i class="dropdown icon"></i>
<div class="menu">
Expand Down
1 change: 0 additions & 1 deletion frontend/requirement.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<a class="item" href="index.html"><span class="f_start_task"></span></a>
<a class="active item" href="requirement.html"><span class="f_requirement_list"></span></a>
<a class="item" href="app.html"><span class="f_app_list"></span></a>
<a class="item" href="setting.html"><span class="f_setting"></span></a>
<a href="#" class="ui right floated dropdown item">
<span class="f_more_operations"></span> <i class="dropdown icon"></i>
<div class="menu">
Expand Down
Loading

0 comments on commit db2461f

Please sign in to comment.