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
cf2c173a
Commit
cf2c173a
authored
Mar 20, 2020
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异步安装runner
parent
28d877b1
Pipeline
#21126
passed with stage
in 27 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
conncetion_service.py
app/conncetion/conncetion_service.py
+1
-1
info_service.py
app/info/info_service.py
+3
-1
install_service.py
app/install/install_service.py
+30
-8
No files found.
app/conncetion/conncetion_service.py
View file @
cf2c173a
...
@@ -10,7 +10,7 @@ from sqlalchemy.orm import sessionmaker
...
@@ -10,7 +10,7 @@ from sqlalchemy.orm import sessionmaker
from
app.utils.db_tools
import
db_driver
from
app.utils.db_tools
import
db_driver
class
ConnectionService
(
HSBaseUCService
):
class
ConnectionService
():
def
get_project_info
(
self
):
def
get_project_info
(
self
):
'''
'''
获取项目信息
获取项目信息
...
...
app/info/info_service.py
View file @
cf2c173a
...
@@ -210,5 +210,7 @@ where A.log_id={log_id}'''
...
@@ -210,5 +210,7 @@ where A.log_id={log_id}'''
获取升级日志
获取升级日志
:return:
:return:
'''
'''
logs
=
docker_client
.
logs
(
'install_api'
)
logs
=
docker_client
.
logs
(
'install_api'
,
tail
=
200
)
if
isinstance
(
logs
,
bytes
):
logs
=
logs
.
decode
()
return
logs
return
logs
app/install/install_service.py
View file @
cf2c173a
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
import
os
import
os
import
time
import
time
from
threading
import
Thread
from
huansi_utils.app.apploader
import
logger
from
huansi_utils.exception.exception
import
HSException
from
huansi_utils.exception.exception
import
HSException
from
huansi_utils.server.service_uc
import
HSBaseUCService
from
huansi_utils.server.service_uc
import
HSBaseUCService
...
@@ -16,12 +18,24 @@ class InstallService(HSBaseUCService):
...
@@ -16,12 +18,24 @@ class InstallService(HSBaseUCService):
安装runner
安装runner
:return:
:return:
'''
'''
conncetion_service
=
ConnectionService
()
project_info
=
conncetion_service
.
get_project_info
()
t
=
Thread
(
target
=
self
.
_install_runner
)
if
not
project_info
:
t
.
start
()
raise
HSException
(
'项目信息未查到,请先配置'
)
project_code
=
project_info
[
'project_no'
]
return
{
"message"
:
"开始安装runner"
}
return
self
.
install_huansi_runner
(
project_code
)
def
_install_runner
(
self
):
from
flask_app
import
global_app
with
global_app
.
app_context
():
from
flask
import
g
g
.
user
=
{}
g
.
language
=
'cn'
conncetion_service
=
ConnectionService
()
project_info
=
conncetion_service
.
get_project_info
()
if
not
project_info
:
raise
HSException
(
'项目信息未查到,请先配置'
)
project_code
=
project_info
[
'project_no'
]
self
.
install_huansi_runner
(
project_code
)
def
install_huansi_runner
(
self
,
HSCUSCODE
):
def
install_huansi_runner
(
self
,
HSCUSCODE
):
'''
'''
...
@@ -30,7 +44,7 @@ class InstallService(HSBaseUCService):
...
@@ -30,7 +44,7 @@ class InstallService(HSBaseUCService):
:return:
:return:
'''
'''
self
.
delete_setting_file
()
self
.
delete_setting_file
()
s1
=
os
.
system
(
"docker run --rm -
t -
i -v /etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner register
\
s1
=
os
.
system
(
"docker run --rm -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
\
-n -u http://47.110.145.204:8085/ -r WwpzH4qk19KjvAjEwoTz --executor docker --docker-image docker
\
--description huansi.{hscode}
\
--description huansi.{hscode}
\
--tag-list huansi.{hscode}"
.
format
(
hscode
=
HSCUSCODE
))
--tag-list huansi.{hscode}"
.
format
(
hscode
=
HSCUSCODE
))
...
@@ -39,7 +53,7 @@ class InstallService(HSBaseUCService):
...
@@ -39,7 +53,7 @@ class InstallService(HSBaseUCService):
self
.
_edit_runner_setting
()
self
.
_edit_runner_setting
()
self
.
_remove_old_runner_container
()
self
.
_remove_old_runner_container
()
self
.
start_runner
()
self
.
start_runner
()
return
{
"message"
:
"安装runner成功"
}
logger
.
info
(
'runner安装成功'
)
def
install_huansi_runner_step1
(
self
):
def
install_huansi_runner_step1
(
self
):
'''
'''
...
@@ -84,6 +98,7 @@ class InstallService(HSBaseUCService):
...
@@ -84,6 +98,7 @@ class InstallService(HSBaseUCService):
return
{
"message"
:
"runner重启成功"
,
"step"
:
"3"
,
"status"
:
"success"
}
return
{
"message"
:
"runner重启成功"
,
"step"
:
"3"
,
"status"
:
"success"
}
def
_edit_runner_setting
(
self
):
def
_edit_runner_setting
(
self
):
logger
.
info
(
'修改配置文件'
)
os
.
system
(
"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
:
with
open
(
'/etc/gitlab-runner/config.toml'
,
'r'
)
as
f
:
s
=
f
.
read
()
s
=
f
.
read
()
...
@@ -91,15 +106,19 @@ class InstallService(HSBaseUCService):
...
@@ -91,15 +106,19 @@ class InstallService(HSBaseUCService):
'volumes = ["/var/run/docker.sock:/var/run/docker.sock","/etc/profile.d/huansi.sh:/etc/profile.d/huansi.sh" ,"/cache","/huansi/gitlab-runner/builds:/builds/hs"]'
)
'volumes = ["/var/run/docker.sock:/var/run/docker.sock","/etc/profile.d/huansi.sh:/etc/profile.d/huansi.sh" ,"/cache","/huansi/gitlab-runner/builds:/builds/hs"]'
)
with
open
(
'/etc/gitlab-runner/config.toml'
,
'w'
)
as
f
:
with
open
(
'/etc/gitlab-runner/config.toml'
,
'w'
)
as
f
:
f
.
write
(
a
)
f
.
write
(
a
)
logger
.
info
(
'修改配置文件成功'
)
def
_remove_old_runner_container
(
self
):
def
_remove_old_runner_container
(
self
):
'''
'''
移除旧runner容器,主要作用于第二次第三次的重复安装
移除旧runner容器,主要作用于第二次第三次的重复安装
:return:
:return:
'''
'''
logger
.
info
(
'删除旧容器'
)
os
.
system
(
"docker stop gitlab-runner && docker rm gitlab-runner"
)
os
.
system
(
"docker stop gitlab-runner && docker rm gitlab-runner"
)
logger
.
info
(
'删除旧容器成功'
)
def
start_runner
(
self
):
def
start_runner
(
self
):
logger
.
info
(
'重新启动runner'
)
s
=
os
.
system
(
"docker run -d --name gitlab-runner --restart always
\
s
=
os
.
system
(
"docker run -d --name gitlab-runner --restart always
\
-v /etc/gitlab-runner:/etc/gitlab-runner
\
-v /etc/gitlab-runner:/etc/gitlab-runner
\
-v /var/run/docker.sock:/var/run/docker.sock
\
-v /var/run/docker.sock:/var/run/docker.sock
\
...
@@ -108,9 +127,12 @@ class InstallService(HSBaseUCService):
...
@@ -108,9 +127,12 @@ class InstallService(HSBaseUCService):
if
s
!=
0
:
if
s
!=
0
:
raise
HSException
(
'启动runner失败'
)
raise
HSException
(
'启动runner失败'
)
logger
.
info
(
'重新启动runner成功'
)
def
delete_setting_file
(
self
):
def
delete_setting_file
(
self
):
logger
.
info
(
'删除配置文件'
)
os
.
system
(
'rm -f /etc/gitlab-runner/config.toml'
)
os
.
system
(
'rm -f /etc/gitlab-runner/config.toml'
)
logger
.
info
(
'删除配置文件成功'
)
def
install_remote_service_docker
(
self
):
def
install_remote_service_docker
(
self
):
'''
'''
...
...
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