Commit 0258961c authored by 金凯强's avatar 金凯强 🎨

修改引用

parent 6c43eba3
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from upgradeImage.util import log from uploadImage import ImageClass
from upgradeImage.uploadImage import ImageClass from util import ShellManage, log
from upgradeImage.util import SSHConnection, ShellManage
if __name__ == "__main__": if __name__ == "__main__":
log.info('*********************************打包开始*********************************') log.info('*********************************打包开始*********************************')
image_instance = ImageClass() image_instance = ImageClass()
log.info('开始复制docker-compose.yml文件') 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/deploy/docker-compose.yml ./docker-compose.yml')
log.info('成功复制到当前目录下') log.info('成功复制到当前目录下')
log.info('开始解析需要升级的镜像') log.info('开始解析需要升级的镜像')
image_instance.get_deploy_image('docker-compose.yml') image_instance.get_deploy_image('docker-compose.yml')
log.info('开始打包镜像') log.info('开始打包镜像')
image_instance.save_images() image_instance.save_images()
log.info('复制docker-compose.yml文件到/data/upgrade下') 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( 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( 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( ShellManage().exec_shell(
'cp -f /huansi/gitlab-runner/builds/base_util.py /data/upgrade/base_util.py') '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/app.conf /data/upgrade/app.conf') 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_handle.py /data/upgrade/load_handle.py')
ShellManage().exec_shell('cp -f ./load.sh /data/upgrade/load.sh') ShellManage().exec_shell('cp -f ./load.sh /data/upgrade/load.sh')
log.info('*********************************打包结束*********************************') log.info('*********************************打包结束*********************************')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import os import os
import re import re
from upgradeImage.util import FileHelper, log from util import FileHelper, log
class ImageClass(): class ImageClass():
......
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import paramiko # import paramiko
import logging import logging
import os import os
from logging import handlers from logging import handlers
...@@ -108,55 +108,55 @@ class ShellManage(): ...@@ -108,55 +108,55 @@ class ShellManage():
return txt return txt
class SSHConnection(object): # class SSHConnection(object):
#
def __init__(self, host=None, port=None, username=None, pwd=None): # def __init__(self, host=None, port=None, username=None, pwd=None):
self.__host = host # self.__host = host
self.__port = port # self.__port = port
self.__username = username # self.__username = username
self.__pwd = pwd # self.__pwd = pwd
self.__transport = None # self.__transport = None
self.__k = None # self.__k = None
#
def connect(self): # def connect(self):
# 创建连接对象 # # 创建连接对象
transport = paramiko.Transport((self.__host, self.__port)) # transport = paramiko.Transport((self.__host, self.__port))
transport.connect(username=self.__username, password=self.__pwd) # transport.connect(username=self.__username, password=self.__pwd)
self.__transport = transport # self.__transport = transport
#
def close(self): # def close(self):
# 关闭连接 # # 关闭连接
self.__transport.close() # self.__transport.close()
#
def upload(self, local_path, target_path): # def upload(self, local_path, target_path):
""" # """
本地上传文件到服务器 # 本地上传文件到服务器
:param local_path: 本地文件地址 # :param local_path: 本地文件地址
:param target_path: 目标文件路径 # :param target_path: 目标文件路径
""" # """
sftp = paramiko.SFTPClient.from_transport(self.__transport) # sftp = paramiko.SFTPClient.from_transport(self.__transport)
sftp.put(local_path, target_path) # sftp.put(local_path, target_path)
#
def download(self, remote_path, local_path): # def download(self, remote_path, local_path):
""" # """
服务器下载文件到本地 # 服务器下载文件到本地
:param remote_path: 服务器文件路径 # :param remote_path: 服务器文件路径
:param local_path: 本地目标路径 # :param local_path: 本地目标路径
""" # """
sftp = paramiko.SFTPClient.from_transport(self.__transport) # sftp = paramiko.SFTPClient.from_transport(self.__transport)
sftp.get(remote_path, local_path) # sftp.get(remote_path, local_path)
#
def cmd(self, command): # def cmd(self, command):
""" # """
执行指定命令 # 执行指定命令
:param command: 命令 # :param command: 命令
:return:输入,输出,错误 # :return:输入,输出,错误
""" # """
ssh = paramiko.SSHClient() # ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh._transport = self.__transport # ssh._transport = self.__transport
# 执行命令,标准输入,输出,错误 # # 执行命令,标准输入,输出,错误
stdin, stdout, stderr = ssh.exec_command(command) # stdin, stdout, stderr = ssh.exec_command(command)
# 获取命令结果 # # 获取命令结果
outputs = stdout.read() # outputs = stdout.read()
return outputs # return outputs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment