Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
install.api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Script
install.api
Commits
19d52cf1
Commit
19d52cf1
authored
Mar 12, 2020
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试
parent
82a0a5c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
43 deletions
+43
-43
upgrade_service.py
app/upgrade/upgrade_service.py
+43
-43
No files found.
app/upgrade/upgrade_service.py
View file @
19d52cf1
...
...
@@ -33,51 +33,51 @@ class UpgradeService():
sql
=
f
'''select * from app_upgrade_log_dtl where log_id={log_id}'''
image_info_list
=
session
.
query_sql
(
sql
)
# 找出升级版本号
upgrade_no
=
data
.
get
(
'upgrade_no
'
)
# 找到这个版本备份的compose文件
docker_compose_file_dir
=
self
.
find_compose_by_upgrade_no
(
upgrade_no
)
# 挨个去找对应版本中的镜像然后逐一tag
for
image_info
in
image_info_list
:
app_image_id
=
image_info
[
'app_image_id'
]
app_image_name
=
image_info
[
'app_image_name'
]
# 系统中找镜像,如果镜像是None,重新tag,如果不是None,就不用处理了
find_image_command
=
"docker images |grep "
+
app_image_id
[:
12
]
+
" | awk '{print $2}'"
with
os
.
popen
(
find_image_command
)
as
command
:
actual_image_verison
=
command
.
read
()
if
not
actual_image_verison
:
raise
HSException
(
f
'找不到对应的{app_image_id}的镜像'
)
logger
.
info
(
f
'镜像{app_image_id}的镜像版本号为{actual_image_verison}'
)
# tag它
if
actual_image_verison
==
'<none>'
:
logger
.
info
(
f
'tag镜像{app_image_id}为{app_image_name}'
)
res
=
os
.
system
(
f
'docker tag {app_image_id[:12]} {app_image_name}'
)
if
res
==
1
:
raise
HSException
(
f
'Tag{app_image_name}镜像失败'
)
else
:
# 有版本就不管
pass
# 找到app_list
app_list
=
self
.
get_app_list_from_compose_file
(
docker_compose_file_dir
)
# docker-compose
project_info
=
ConnectionService
()
.
get_project_info
()
host_ip
=
project_info
[
'host_ip'
]
ssh_conenct
=
SSHConnect
(
user_name
=
'root'
,
password
=
'huansi.net'
,
host_port
=
'1111'
,
host_ip
=
host_ip
)
with
ssh_conenct
as
ssh
:
out
,
err
=
ssh
.
exec_command
(
f
'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&
\
# 找出升级版本号
upgrade_no
=
data
.
get
(
'
'
)
# 找到这个版本备份的compose文件
docker_compose_file_dir
=
self
.
find_compose_by_upgrade_no
(
upgrade_no
)
# 挨个去找对应版本中的镜像然后逐一tag
for
image_info
in
image_info_list
:
app_image_id
=
image_info
[
'app_image_id'
]
app_image_name
=
image_info
[
'app_image_name'
]
# 系统中找镜像,如果镜像是None,重新tag,如果不是None,就不用处理了
find_image_command
=
"docker images |grep "
+
app_image_id
[:
12
]
+
" | awk '{print $2}'"
with
os
.
popen
(
find_image_command
)
as
command
:
actual_image_verison
=
command
.
read
()
if
not
actual_image_verison
:
raise
HSException
(
f
'找不到对应的{app_image_id}的镜像'
)
logger
.
info
(
f
'镜像{app_image_id}的镜像版本号为{actual_image_verison}'
)
# tag它
if
actual_image_verison
==
'<none>'
:
logger
.
info
(
f
'tag镜像{app_image_id}为{app_image_name}'
)
res
=
os
.
system
(
f
'docker tag {app_image_id[:12]} {app_image_name}'
)
if
res
==
1
:
raise
HSException
(
f
'Tag{app_image_name}镜像失败'
)
else
:
# 有版本就不管
pass
# 找到app_list
app_list
=
self
.
get_app_list_from_compose_file
(
docker_compose_file_dir
)
# docker-compose
project_info
=
ConnectionService
()
.
get_project_info
()
host_ip
=
project_info
[
'host_ip'
]
ssh_conenct
=
SSHConnect
(
user_name
=
'root'
,
password
=
'huansi.net'
,
host_port
=
'1111'
,
host_ip
=
host_ip
)
with
ssh_conenct
as
ssh
:
out
,
err
=
ssh
.
exec_command
(
f
'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&
\
source /etc/profile.d/huansi.sh &&
\
docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.yml -p deploy up -d --force-recreate --no-deps {app_list}'''
)
# 会有问题,docker-compose编译的时候,会把过程放到err上,所以注释这段
# if err:
# raise HSException(f'回滚失败:{err}')
if
err
:
logger
.
info
(
f
"有报错信息:{err}"
)
logger
.
info
(
f
'回滚{app_list}成功:{out}'
)
# 会有问题,docker-compose编译的时候,会把过程放到err上,所以注释这段
# if err:
# raise HSException(f'回滚失败:{err}')
if
err
:
logger
.
info
(
f
"有报错信息:{err}"
)
logger
.
info
(
f
'回滚{app_list}成功:{out}'
)
with
db_driver
as
session
:
# 对应的版本信息修改为当前版本
...
...
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