添加keys 发布接口
This commit is contained in:
parent
290c568c9c
commit
230d3bf90f
@ -8,28 +8,36 @@ from config.config import args
|
||||
import os
|
||||
import tarfile
|
||||
import svn
|
||||
|
||||
import shutil
|
||||
define_logger("/data/logs/ops/deploy_keys.log")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DeployKeys:
|
||||
def __init__(self, project):
|
||||
self.env='test'
|
||||
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}"
|
||||
|
||||
|
||||
def run(self):
|
||||
svn_path, ipadr = self.get_config()
|
||||
if svn_path:
|
||||
key_path = f"{svn_path}/keys"
|
||||
args = dict()
|
||||
tar_file = self.build_svn_tar(key_path)
|
||||
shutil.rmtree(svn_path)
|
||||
else:
|
||||
pass
|
||||
os.system(f"mkdir -p {svn_path}")
|
||||
key_path = f"{svn_path}/keys"
|
||||
args = dict()
|
||||
tar_file = self.build_svn_tar(key_path)
|
||||
if tar_file:
|
||||
hostfile = self.build_hostfile()
|
||||
args['hostfile'] = hostfile
|
||||
args['tar_file'] = tar_file
|
||||
self.ansible_deploy(args)
|
||||
else:
|
||||
log.error(f"tar file no found with {self.project}")
|
||||
|
||||
|
||||
def get_config(self):
|
||||
@ -40,7 +48,7 @@ class DeployKeys:
|
||||
`deploy_projectmanage`
|
||||
WHERE
|
||||
project_name="{self.project}"
|
||||
and env='prod'"""
|
||||
and env='{self.env}'"""
|
||||
|
||||
mydb = MysqlBase(**args)
|
||||
data = mydb.query(sql)
|
||||
@ -96,8 +104,8 @@ class DeployKeys:
|
||||
|
||||
def ansible_deploy(self, args):
|
||||
an = AnsibleAPI(args['hostfile'])
|
||||
data = {'tga': 'x', 'source': 'x', 'project': 'x'}
|
||||
resule = an.run_playbook('deploy_keys.yml', **args)
|
||||
data = {'dest_filename': 'x', 'source': 'x', 'project': 'x'}
|
||||
resule = an.run_playbook('deploy_keys.yml', **data)
|
||||
if not (resule['failed'] or resule['unreachable']):
|
||||
log.info(f"deploy keys with {self.p} success!")
|
||||
else:
|
||||
|
@ -4,5 +4,8 @@
|
||||
- name: rsync deploy file
|
||||
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
|
||||
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