# -*- coding:utf-8 -*-
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/deploy/docker-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/deploy/docker-compose.yml /data/upgrade/docker-compose.yml')
    ShellManage().exec_shell(
        '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/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('*********************************打包结束*********************************')
    # log.info('开始上传镜像和脚本文件')
    # ssh = SSHConnection(host='localhost', port=1111, username='root', pwd='huansi.net')
    # ssh.connect()
    # log.info('开始在远端服务器执行升级脚本')
    # r = ssh.cmd('mkdir jkqjkq')
    # log.info('返回结果:\n{}'.format(r))
    # log.info('*********************************升级结束*********************************')
