Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
opms-command
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
赵凯
opms-command
Commits
340b63da
Commit
340b63da
authored
Mar 21, 2024
by
赵凯
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动识别项目集群部署方式,并进行集群部署
parent
54101814
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
7 deletions
+63
-7
.gitignore
.gitignore
+2
-1
task_patch_api.py
apis/task_patch_api.py
+31
-1
opms.py
opms.py
+30
-5
No files found.
.gitignore
View file @
340b63da
...
...
@@ -3,4 +3,5 @@ __pycache__/
config.yaml
*.cache
.DS_Store
.idea/
\ No newline at end of file
.idea/
*.db
\ No newline at end of file
apis/task_patch_api.py
View file @
340b63da
...
...
@@ -26,4 +26,34 @@ def tasksPatch(taskid):
'cookie'
:
cookie
}
response
=
requests
.
request
(
"PATCH"
,
url
,
headers
=
headers
,
data
=
payload
)
print
(
"任务开始执行..."
)
\ No newline at end of file
print
(
"任务开始执行..."
)
# 集群部署任务
def
taskMultiZone
(
taskid
,
target_k8
):
cookie
=
getToken
()
url
=
"https://gw.qimai.shop/api/jenkins/jenkinsjob/tasks/multi_zone/"
# payload = "{\"task_id\":218808,\"target_k8s\":[5]}"
payload
=
f
'{{"task_id":{taskid},"target_k8s":[{target_k8}]}}'
headers
=
{
'cookie'
:
cookie
,
'authority'
:
'gw.qimai.shop'
,
'accept'
:
'application/json, text/plain, */*'
,
'accept-language'
:
'zh-CN,zh;q=0.9'
,
'cache-control'
:
'no-cache'
,
'content-type'
:
'application/json;charset=UTF-8'
,
'origin'
:
'https://opms.qimai.shop'
,
'pragma'
:
'no-cache'
,
'referer'
:
'https://opms.qimai.shop/'
,
'sec-ch-ua'
:
'"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"'
,
'sec-ch-ua-mobile'
:
'?0'
,
'sec-ch-ua-platform'
:
'"macOS"'
,
'sec-fetch-dest'
:
'empty'
,
'sec-fetch-mode'
:
'cors'
,
'sec-fetch-site'
:
'same-site'
,
'user-agent'
:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36'
,
'x-xsrftoken'
:
'undefined'
}
response
=
requests
.
request
(
"POST"
,
url
,
headers
=
headers
,
data
=
payload
)
print
(
"集群部署任务开始执行..."
)
opms.py
View file @
340b63da
...
...
@@ -6,7 +6,7 @@ from apis.login_api import login
from
apis.get_prejects_api
import
getProjects
from
apis.get_gits_api
import
getGits
from
apis.tasks_api
import
tasks
from
apis.task_patch_api
import
tasksPatch
from
apis.task_patch_api
import
tasksPatch
,
taskMultiZone
from
apis.task_status_api
import
taskstatus
...
...
@@ -21,7 +21,19 @@ def checkProjId():
proj_id
=
result
[
'id'
]
print
(
f
'识别出项目: {proj_name}, 项目ID为: {proj_id}'
)
return
proj_id
raise
Exception
(
"无法识别的项目"
)
raise
Exception
(
"无法识别的项目"
)
def
checkProjIdGetResult
():
# 获取当前执行目录
cwd
=
os
.
getcwd
()
rst_results
=
getProjects
()
for
result
in
rst_results
:
if
cwd
.
find
(
result
[
'name'
])
!=
-
1
:
proj_name
=
result
[
'name'
]
proj_id
=
result
[
'id'
]
print
(
f
'识别出项目: {proj_name}, 项目ID为: {proj_id}'
)
return
result
raise
Exception
(
"无法识别的项目"
)
# 获取当前项目,当前环境最新commitid
def
checkCommitid
(
projectid
,
env
):
...
...
@@ -56,14 +68,27 @@ else:
info
=
argv
[
2
]
# 识别项目
projectid
=
checkProjId
()
projectResult
=
checkProjIdGetResult
()
# 项目ID
projectid
=
projectResult
[
'id'
]
# 项目环境部署信息
projectEnvRef
=
next
((
env_ref
for
env_ref
in
projectResult
[
'env_ref'
]
if
env_ref
[
'env'
]
==
env
),
None
)
# print(projectResult)
# print(projectEnvRef)
# 拉取提交节点
commitid
=
checkCommitid
(
projectid
,
env
)
# 创建部署任务
taskid
=
tasks
(
projectid
,
env
,
commitid
,
info
)
time
.
sleep
(
3
)
# 执行部署任务
tasksPatch
(
taskid
)
# 执行部署任务 or 执行集群部署任务
multi_zone_deploy
=
projectEnvRef
.
get
(
'multi_zone_deploy'
,
False
)
k8sname
=
projectEnvRef
.
get
(
'k8sname'
,
0
)
if
multi_zone_deploy
:
taskMultiZone
(
taskid
,
k8sname
)
else
:
tasksPatch
(
taskid
)
# 轮训任务状态
is_continue
=
1
while
is_continue
==
1
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment