添加keys 发布接口
This commit is contained in:
parent
290c568c9c
commit
230d3bf90f
@ -8,28 +8,36 @@ from config.config import args
|
|||||||
import os
|
import os
|
||||||
import tarfile
|
import tarfile
|
||||||
import svn
|
import svn
|
||||||
|
import shutil
|
||||||
define_logger("/data/logs/ops/deploy_keys.log")
|
define_logger("/data/logs/ops/deploy_keys.log")
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DeployKeys:
|
class DeployKeys:
|
||||||
def __init__(self, project):
|
def __init__(self, project):
|
||||||
|
self.env='test'
|
||||||
self.project = project
|
self.project = project
|
||||||
self.svn_base = "/data/publish/svn"
|
self.svn_base = f"/data/publish/svn/{self.env}"
|
||||||
self.svn_paths = f"{self.svn_base}/{self.project}"
|
self.svn_paths = f"{self.svn_base}/{self.project}"
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
svn_path, ipadr = self.get_config()
|
svn_path, ipadr = self.get_config()
|
||||||
if svn_path:
|
if svn_path:
|
||||||
|
shutil.rmtree(svn_path)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
os.system(f"mkdir -p {svn_path}")
|
||||||
key_path = f"{svn_path}/keys"
|
key_path = f"{svn_path}/keys"
|
||||||
args = dict()
|
args = dict()
|
||||||
tar_file = self.build_svn_tar(key_path)
|
tar_file = self.build_svn_tar(key_path)
|
||||||
|
if tar_file:
|
||||||
hostfile = self.build_hostfile()
|
hostfile = self.build_hostfile()
|
||||||
args['hostfile'] = hostfile
|
args['hostfile'] = hostfile
|
||||||
args['tar_file'] = tar_file
|
args['tar_file'] = tar_file
|
||||||
self.ansible_deploy(args)
|
self.ansible_deploy(args)
|
||||||
|
else:
|
||||||
|
log.error(f"tar file no found with {self.project}")
|
||||||
|
|
||||||
|
|
||||||
def get_config(self):
|
def get_config(self):
|
||||||
@ -40,7 +48,7 @@ class DeployKeys:
|
|||||||
`deploy_projectmanage`
|
`deploy_projectmanage`
|
||||||
WHERE
|
WHERE
|
||||||
project_name="{self.project}"
|
project_name="{self.project}"
|
||||||
and env='prod'"""
|
and env='{self.env}'"""
|
||||||
|
|
||||||
mydb = MysqlBase(**args)
|
mydb = MysqlBase(**args)
|
||||||
data = mydb.query(sql)
|
data = mydb.query(sql)
|
||||||
@ -96,8 +104,8 @@ class DeployKeys:
|
|||||||
|
|
||||||
def ansible_deploy(self, args):
|
def ansible_deploy(self, args):
|
||||||
an = AnsibleAPI(args['hostfile'])
|
an = AnsibleAPI(args['hostfile'])
|
||||||
data = {'tga': 'x', 'source': 'x', 'project': 'x'}
|
data = {'dest_filename': 'x', 'source': 'x', 'project': 'x'}
|
||||||
resule = an.run_playbook('deploy_keys.yml', **args)
|
resule = an.run_playbook('deploy_keys.yml', **data)
|
||||||
if not (resule['failed'] or resule['unreachable']):
|
if not (resule['failed'] or resule['unreachable']):
|
||||||
log.info(f"deploy keys with {self.p} success!")
|
log.info(f"deploy keys with {self.p} success!")
|
||||||
else:
|
else:
|
||||||
|
@ -4,5 +4,8 @@
|
|||||||
- name: rsync deploy file
|
- name: rsync deploy file
|
||||||
copy: src={{ source }} dest=/data/apps/{{ dest_filename }}
|
copy: src={{ source }} dest=/data/apps/{{ dest_filename }}
|
||||||
|
|
||||||
|
- name: back old config file
|
||||||
|
shell: "rsync -avcp /data/app{{ project }}/keys /data/app{{ project }}/keys.old"
|
||||||
|
|
||||||
- name: decomp file
|
- name: decomp file
|
||||||
shell: "cd /data/backups_app/ && mkdir -p {{ tag }} && tar zxvf {{ dest_filename }} -C {{ tag }} && chown -R kingsome. {{ tag }}"
|
shell: "cd /data/app/ && tar zxvf {{ dest_filename }} -C /data/apps/{{ project }} "
|
Loading…
x
Reference in New Issue
Block a user