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
5a4d9590
Commit
5a4d9590
authored
Mar 14, 2020
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复一些bug
parent
b5d5d2cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
install_service.py
app/install/install_service.py
+4
-1
upgrade_service.py
app/upgrade/upgrade_service.py
+20
-1
No files found.
app/install/install_service.py
View file @
5a4d9590
# -*- coding:utf-8 -*-
import
os
import
time
from
huansi_utils.exception.exception
import
HSException
from
huansi_utils.server.service_uc
import
HSBaseUCService
...
...
@@ -28,6 +29,7 @@ class InstallService(HSBaseUCService):
:param HSCUSCODE:
:return:
'''
time
.
sleep
(
15
)
self
.
delete_setting_file
()
s1
=
os
.
system
(
"docker run --rm -t -i -v /etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner register
\
-n -u http://47.110.145.204:8085/ -r WwpzH4qk19KjvAjEwoTz --executor docker --docker-image docker
\
...
...
@@ -38,9 +40,10 @@ class InstallService(HSBaseUCService):
self
.
_edit_runner_setting
()
self
.
_remove_old_runner_container
()
self
.
start_runner
()
return
{
"message"
:
"安装runner成功"
}
def
_edit_runner_setting
(
self
):
os
.
system
(
"
sudo
chmod 777 /etc/gitlab-runner/config.toml"
)
os
.
system
(
"chmod 777 /etc/gitlab-runner/config.toml"
)
with
open
(
'/etc/gitlab-runner/config.toml'
,
'r'
)
as
f
:
s
=
f
.
read
()
a
=
s
.
replace
(
'volumes = ["/cache"]'
,
...
...
app/upgrade/upgrade_service.py
View file @
5a4d9590
...
...
@@ -51,7 +51,7 @@ class UpgradeService():
if
not
actual_image_verison
:
raise
HSException
(
f
'找不到对应的{app_image_id}的镜像'
)
logger
.
info
(
f
'镜像{app_image_id}的镜像版本号为{actual_image_verison}'
)
logger
.
info
(
f
'镜像{app_image_id}的
原
镜像版本号为{actual_image_verison}'
)
# tag它
if
actual_image_verison
==
'<none>'
:
...
...
@@ -63,11 +63,14 @@ class UpgradeService():
pass
# 找到app_list
app_list
=
self
.
get_app_list_from_compose_file
(
docker_compose_file_dir
)
logger
.
info
(
'compose中的app_list为:{}'
.
format
(
app_list
))
# docker-compose
project_info
=
ConnectionService
()
.
get_project_info
()
host_ip
=
project_info
[
'host_ip'
]
# 调用本机的docker-compose
ssh_conenct
=
SSHConnect
(
user_name
=
'root'
,
password
=
'huansi.net'
,
host_port
=
'1111'
,
host_ip
=
host_ip
)
with
ssh_conenct
as
ssh
:
# todo 处理*的情况
out
,
err
=
ssh
.
exec_command
(
f
'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&
\
source /etc/profile.d/huansi.sh &&
\
...
...
@@ -125,6 +128,10 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym
upgrade_back_up_dir
=
os
.
path
.
join
(
temp_file_dir
,
'backup'
,
upgrade_no
)
with
ssh_conenct
as
ssh
:
# 验证远端服务器有没有按照docker
self
.
validate_remote_server_install_docker
(
ssh
)
for
files
in
os
.
listdir
(
upgrade_back_up_dir
):
path
=
os
.
path
.
join
(
upgrade_back_up_dir
,
files
)
# 隐藏文件不复制
...
...
@@ -283,3 +290,15 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym
upgrade_no
=
app_info
[
'upgrade_no'
]
return
upgrade_no
def
validate_remote_server_install_docker
(
self
,
ssh
):
'''
验证远端服务器是否安装docker
:param ssh:
:return:
'''
out
,
err
=
ssh
.
exec_command
(
'docker -v'
)
if
'Docker version'
not
in
out
or
err
:
logger
.
info
(
'验证远端服务器是否安装docker日志:{}'
.
format
(
err
))
raise
HSException
(
'远端服务器未安装docker,请先安装后再升级'
)
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