Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
deploy
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
deploy
Commits
0258961c
Commit
0258961c
authored
Oct 31, 2019
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改引用
parent
6c43eba3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
63 deletions
+63
-63
upgrade_handle.py
upgradeImage/upgrade_handle.py
+9
-9
uploadImage.py
upgradeImage/uploadImage.py
+1
-1
util.py
upgradeImage/util.py
+53
-53
No files found.
upgradeImage/upgrade_handle.py
View file @
0258961c
# -*- coding:utf-8 -*-
from
upgradeImage.util
import
log
from
upgradeImage.uploadImage
import
ImageClass
from
upgradeImage.util
import
SSHConnection
,
ShellManage
from
uploadImage
import
ImageClass
from
util
import
ShellManage
,
log
if
__name__
==
"__main__"
:
log
.
info
(
'*********************************打包开始*********************************'
)
image_instance
=
ImageClass
()
log
.
info
(
'开始复制docker-compose.yml文件'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/docker-compose.yml ./docker-compose.yml'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/d
eploy/d
ocker-compose.yml ./docker-compose.yml'
)
log
.
info
(
'成功复制到当前目录下'
)
log
.
info
(
'开始解析需要升级的镜像'
)
image_instance
.
get_deploy_image
(
'docker-compose.yml'
)
log
.
info
(
'开始打包镜像'
)
image_instance
.
save_images
()
log
.
info
(
'复制docker-compose.yml文件到/data/upgrade下'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/docker-compose.yml /data/upgrade/docker-compose.yml'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/
analysis_file_to_hsright.py /data/upgrade/analysis_file_to_hsright.py
'
)
'cp -f /huansi/gitlab-runner/builds/
deploy/docker-compose.yml /data/upgrade/docker-compose.yml
'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/
analysis_file_to_nginx.py /data/upgrade/analysis_file_to_nginx
.py'
)
'cp -f /huansi/gitlab-runner/builds/
deploy/analysis_file_to_hsright.py /data/upgrade/analysis_file_to_hsright
.py'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/base_util.py /data/upgrade/base_util.py'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/app.conf /data/upgrade/app.conf'
)
'cp -f /huansi/gitlab-runner/builds/deploy/analysis_file_to_nginx.py /data/upgrade/analysis_file_to_nginx.py'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/deploy/base_util.py /data/upgrade/base_util.py'
)
ShellManage
()
.
exec_shell
(
'cp -f /huansi/gitlab-runner/builds/deploy/app.conf /data/upgrade/app.conf'
)
ShellManage
()
.
exec_shell
(
'cp -f ./load_handle.py /data/upgrade/load_handle.py'
)
ShellManage
()
.
exec_shell
(
'cp -f ./load.sh /data/upgrade/load.sh'
)
log
.
info
(
'*********************************打包结束*********************************'
)
...
...
upgradeImage/uploadImage.py
View file @
0258961c
...
...
@@ -2,7 +2,7 @@
import
os
import
re
from
u
pgradeImage.u
til
import
FileHelper
,
log
from
util
import
FileHelper
,
log
class
ImageClass
():
...
...
upgradeImage/util.py
View file @
0258961c
# -*- coding:utf-8 -*-
import
paramiko
#
import paramiko
import
logging
import
os
from
logging
import
handlers
...
...
@@ -108,55 +108,55 @@ class ShellManage():
return
txt
class
SSHConnection
(
object
):
def
__init__
(
self
,
host
=
None
,
port
=
None
,
username
=
None
,
pwd
=
None
):
self
.
__host
=
host
self
.
__port
=
port
self
.
__username
=
username
self
.
__pwd
=
pwd
self
.
__transport
=
None
self
.
__k
=
None
def
connect
(
self
):
# 创建连接对象
transport
=
paramiko
.
Transport
((
self
.
__host
,
self
.
__port
))
transport
.
connect
(
username
=
self
.
__username
,
password
=
self
.
__pwd
)
self
.
__transport
=
transport
def
close
(
self
):
# 关闭连接
self
.
__transport
.
close
()
def
upload
(
self
,
local_path
,
target_path
):
"""
本地上传文件到服务器
:param local_path: 本地文件地址
:param target_path: 目标文件路径
"""
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
self
.
__transport
)
sftp
.
put
(
local_path
,
target_path
)
def
download
(
self
,
remote_path
,
local_path
):
"""
服务器下载文件到本地
:param remote_path: 服务器文件路径
:param local_path: 本地目标路径
"""
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
self
.
__transport
)
sftp
.
get
(
remote_path
,
local_path
)
def
cmd
(
self
,
command
):
"""
执行指定命令
:param command: 命令
:return:输入,输出,错误
"""
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
_transport
=
self
.
__transport
# 执行命令,标准输入,输出,错误
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
command
)
# 获取命令结果
outputs
=
stdout
.
read
()
return
outputs
#
class SSHConnection(object):
#
#
def __init__(self, host=None, port=None, username=None, pwd=None):
#
self.__host = host
#
self.__port = port
#
self.__username = username
#
self.__pwd = pwd
#
self.__transport = None
#
self.__k = None
#
#
def connect(self):
#
# 创建连接对象
#
transport = paramiko.Transport((self.__host, self.__port))
#
transport.connect(username=self.__username, password=self.__pwd)
#
self.__transport = transport
#
#
def close(self):
#
# 关闭连接
#
self.__transport.close()
#
#
def upload(self, local_path, target_path):
#
"""
#
本地上传文件到服务器
#
:param local_path: 本地文件地址
#
:param target_path: 目标文件路径
#
"""
#
sftp = paramiko.SFTPClient.from_transport(self.__transport)
#
sftp.put(local_path, target_path)
#
#
def download(self, remote_path, local_path):
#
"""
#
服务器下载文件到本地
#
:param remote_path: 服务器文件路径
#
:param local_path: 本地目标路径
#
"""
#
sftp = paramiko.SFTPClient.from_transport(self.__transport)
#
sftp.get(remote_path, local_path)
#
#
def cmd(self, command):
#
"""
#
执行指定命令
#
:param command: 命令
#
:return:输入,输出,错误
#
"""
#
ssh = paramiko.SSHClient()
#
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#
ssh._transport = self.__transport
#
# 执行命令,标准输入,输出,错误
#
stdin, stdout, stderr = ssh.exec_command(command)
#
# 获取命令结果
#
outputs = stdout.read()
#
return outputs
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