您好,登录后才能下订单哦!
这篇文章给大家分享的是有关如何使用fabric自动化发版的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
功能:使用fabric自动化发版
#-*-coding:utf8-*-
from fabric.api import *
import subprocess
import os
import sys
import glob
import shutil
env.roledefs = {
'cz-oms-core':['czoms@10.2.88.47','czoms@10.2.88.48'],
'cz-oms-core-new':['czoms@10.2.88.37','czoms@10.2.88.46'],
'cz-oms-core-new1':['czoms@10.2.88.40','czoms@10.2.88.41'],
'cz':['appuser@10.2.88.30']
}
env.passwords = {
'czoms@10.2.88.47:22':'fdfdfsdf',
'czoms@10.2.88.48:22':'fdfdfsdf',
'czoms@10.2.88.37:22':'fdfdfsdf',
'czoms@10.2.88.46:22':'fdfdfsdf',
'czoms@10.2.88.40:22':'fdfdfsdf',
'czoms@10.2.88.41:22':'fdfdfsdf',
'appuser@10.2.88.30:22':'appuser@0630',
}
#通用函数
def unzip():
with lcd('patch'):
local('winrar x *.zip')
#Update SVN
def UpdateSVN(path):
p = subprocess.Popen(['svn','update',path],shell=True,stdout=subprocess.PIPE)
print p.stdout.readlines()
#根据filelist生成发版目录
def faban_dir():
count = 0
with open('filelist.txt','r') as f:
for line in f:
if line.startswith('bj-oms-api'):
#filelist文件路径预处理
classpath_filename = line.replace('bj-oms-api/src/main/java/','../online_svn/bj-oms/bj-oms-api/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-oms-api/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-oms-api/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-api/target/classes/','patch/bj-oms-api/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-oms-domain'):
#filelist文件路径预处理
classpath_filename = line.replace('bj-oms-domain/src/main/java/','../online_svn/bj-oms/bj-oms-domain/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-oms-domain/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-oms-domain/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-domain/target/classes/','patch/bj-oms-domain/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-oms-core-new1'): #位置1,不可调换,因为bj-oms-core包含bj-oms-core-new1
#filelist文件路径预处理
classpath_filename = line.replace('bj-oms-core-new1/src/main/java/','../online_svn/bj-oms/bj-oms-core-new1/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-oms-core-new1/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-oms-core-new1/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-core-new1/target/classes/','patch/bj-oms-core-new1/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-oms-core'): #位置2,不可调换,因为bj-oms-core包含bj-oms-core-new1
#filelist文件路径预处理
classpath_filename = line.replace('bj-oms-core/src/main/java/','../online_svn/bj-oms/bj-oms-core/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-oms-core/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-oms-core/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-core/target/classes/','patch/bj-oms-core/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-oms-rest'):
#filelist文件路径预处理
classpath_filename = line.replace('bj-oms-rest/src/main/java/','../online_svn/bj-oms/bj-oms-rest/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-oms-rest/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-oms-rest/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-rest/target/classes/','patch/bj-oms-rest/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-oms-jobs'):
#filelist文件路径预处理
classpath_filename = line.replace('bj-oms-jobs/src/main/java/','../online_svn/bj-oms/bj-oms-jobs/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-oms-jobs/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-oms-jobs/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-jobs/target/classes/','patch/bj-oms-jobs/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-tran'):
#filelist文件路径预处理
classpath_filename = line.replace('bj-tran/src/main/java/','../online_svn/bj-tran/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-tran/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-tran/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-tran/target/classes/','patch/bj-tran/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
elif line.startswith('bj-whm-rest'):
#filelist文件路径预处理
classpath_filename = line.replace('bj-whm-rest/src/main/java/','../online_svn/bj-whm-rest/target/classes/')
classpath_filename = classpath_filename.replace('.java','.class')
classpath_filename = classpath_filename.replace('\n','') #去掉换行符
#构造patch目录结构
patchpath_filename = line.replace('bj-whm-rest/src/main/java/','')
patchpath_filename = patchpath_filename.replace('.java','.class')
patchpath_filename = patchpath_filename.replace('\n','')
patchpath_filename = 'patch/' + 'bj-whm-rest/' + patchpath_filename
patchpath = os.path.dirname(patchpath_filename)
#如果patch目录不存在,就建立目录
try:
os.listdir(patchpath)
except WindowsError:
os.makedirs(patchpath) #makedirs可以在windows 的patch目录下递归建立文件夹
#拷贝父类到patch目录下
parentclass_path_filename = classpath_filename
patchpath_filename = patchpath_filename
print "拷贝svn class文件到patch目录: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
shutil.copy(parentclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功***************" % count
#用glob寻找子类
path_filename = os.path.split(classpath_filename) #split:返回一个二元组,包含文件的路径与文件名
filename_splitext = os.path.splitext(path_filename[1]) #去掉文件扩展名
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
#把子类拷贝到patch目录下
for subclass_path_filename in subclass_path_filenames:
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-whm-rest/target/classes/','patch/bj-whm-rest/')
print "拷贝svn subclass文件到patch目录: %s ---> %s " % (subclass_path_filename,patchpath_filename)
shutil.copy(subclass_path_filename,patchpath_filename)
count += 1
print "***********第%s个文件拷贝成功,注意该文件是子类哦^_^ *****************************************" % count
else:
print "%s:该项目没有配置,请联系管理员" % line
sys.exit()
#down jar包
@hosts('czoms@10.2.88.47')
def download_bj_oms_api_jar():
get('/opt/bj-oms-core/lib/bj-oms-api-1.0-SNAPSHOT.jar','patch/bj-oms-api/')
@hosts('czoms@10.2.88.47')
def download_bj_oms_domain_jar():
get('/opt/bj-oms-core/lib/bj-oms-domain-1.0-SNAPSHOT.jar','patch/bj-oms-domain/')
@hosts('czoms@10.2.88.40')
def download_bj_oms_core_new1_jar():
get('/opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar','patch/bj-oms-core-new1/')
@hosts('appuser@10.2.88.30')
def download_bj_oms_rest_jar():
get('/opt/bj-oms-rest/lib/bj-oms-rest-1.0-SNAPSHOT.jar','patch/bj-oms-rest/')
@hosts('appuser@10.2.88.30')
def download_bj_oms_job_jar():
get('/opt/bj-oms-job/lib/bj-oms-job-1.0-SNAPSHOT.jar','patch/bj-oms-jobs/')
@hosts('czoms@10.2.88.47')
def download_bj_oms_core_jar():
get('/opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar','patch/bj-oms-core/')
#替换jar包里面的文件
def replace_file_to_local_bj_oms_api_jar():
with lcd('patch/bj-oms-api/'):
local('jar -uvf bj-oms-api-1.0-SNAPSHOT.jar * ')
'''
def replace_file_to_local_bj_oms_core_new1_jar():
with lcd('patch/bj-oms-core-new1/'):
local('jar -uvf bj-oms-core-1.0-SNAPSHOT.jar * ')
'''
def replace_file_to_local_bj_oms_domain_jar():
with lcd('patch/bj-oms-domain/'):
local('jar -uvf bj-oms-domain-1.0-SNAPSHOT.jar * ')
def replace_file_to_local_bj_oms_job_jar():
with lcd('patch/bj-oms-job/'):
local('jar -uvf bj-oms-job-1.0-SNAPSHOT.jar * ')
def replace_file_to_local_bj_oms_rest_jar():
with lcd('patch/bj-oms-rest/'):
local('jar -uvf bj-oms-rest-1.0-SNAPSHOT.jar * ')
def replace_file_to_local_bj_oms_core_jar():
with lcd('patch/bj-oms-core/'):
local('jar -uvf bj-oms-core-1.0-SNAPSHOT.jar * ')
#backup
@hosts('czoms@10.2.88.47')
def backup_bj_oms_api_jar():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-api-1.0-SNAPSHOT.jar /backup/$dir1')
puts('bj-oms-api-1.0-SNAPSHOT.jar包备份到了10.2.88.47的/backup目录下')
@hosts('czoms@10.2.88.47')
def backup_bj_oms_domain_jar():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-domain-1.0-SNAPSHOT.jar /backup/$dir1')
puts('bj-oms-domain-1.0-SNAPSHOT.jar包备份到了10.2.88.47的/backup目录下')
@hosts('czoms@10.2.88.40')
def backup_bj_oms_core_new1_jar():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar /backup/$dir1')
puts('bj-oms-core-1.0-SNAPSHOT.jar包备份到了10.2.88.40的/backup目录下')
@hosts('appuser@10.2.88.30')
def backup_bj_oms_rest_jar():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-rest/lib/bj-oms-rest-1.0-SNAPSHOT.jar /backup/$dir1')
puts('bj-oms-rest-1.0-SNAPSHOT.jar包备份到了10.2.88.30的/backup/目录下')
@hosts('appuser@10.2.88.30')
def backup_bj_oms_job_jar():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/bj-oms-job/$dir1 && cp -a /opt/bj-oms-job/lib/bj-oms-job-1.0-SNAPSHOT.jar /backup/bj-oms-job/$dir1')
puts('bj-oms-job-1.0-SNAPSHOT.jar包备份到了10.2.88.30的/backup/目录下')
@hosts('appuser@10.2.88.30')
def backup_bj_web():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/tomcat-oms/webapps/bj-web /backup/$dir1')
puts('bj-web包备份到了10.2.88.30的/backup/目录下')
@hosts('czoms@10.2.88.47')
def backup_bj_oms_core_jar():
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar /backup/$dir1')
puts('bj_oms_core包备份到了10.2.88.30的/backup/目录下')
#发版,上传jar包
@hosts('czoms@10.2.88.47','czoms@10.2.88.48','czoms@10.2.88.37','czoms@10.2.88.46','czoms@10.2.88.40','czoms@10.2.88.41')
def put_bj_oms_api_jar_4748_3746_4041():
with lcd ('patch/bj-oms-api/'):
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib/')
@hosts('appuser@10.2.88.30')
def put_bj_oms_api_jar_30():
with lcd ('patch/bj-oms-api/'):
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/tomcat-oms/webapps/bj-web/WEB-INF/lib')
@hosts('czoms@10.2.88.47','czoms@10.2.88.48','czoms@10.2.88.37','czoms@10.2.88.46','czoms@10.2.88.40','czoms@10.2.88.41')
def put_bj_oms_domain_jar_4748_3746_4041():
with lcd ('patch/bj-oms-domain/'):
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')
@hosts('appuser@10.2.88.30')
def put_bj_oms_domain_jar_30():
with lcd ('patch/bj-oms-domain/'):
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/tomcat-oms/webapps/bj-web/WEB-INF/lib')
@roles('cz-oms-core-new1')
def put_bj_oms_core_new1_jar():
with lcd ('patch/bj-oms-core-new1/'):
put('bj-oms-core-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')
@roles('cz')
def put_bj_oms_rest_jar():
with lcd ('patch/bj-oms-rest/'):
put('bj-oms-rest-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
@roles('cz')
def put_bj_oms_job_jar():
with lcd ('patch/bj-oms-jobs/'):
put('bj-oms-job-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
@roles('cz')
def put_bj_web():
with lcd ('patch/'):
put('bj-web.zip','/opt/tomcat-oms/webapps')
run('cd /opt/tomcat-oms/webapps && unzip -o bj-web.zip && rm -rf bj-web.zip')
@roles('cz-oms-core')
def put_bj_oms_core_jar():
with lcd ('patch/bj-oms-core'):
put('bj-oms-core-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')
#重启服务
@roles('cz-oms-core')
def stop_cz_oms_core_4748():
sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)
@roles('cz-oms-core')
def start_cz_oms_core_4748():
sudo('/opt/bj-oms-core/bin/start.sh',pty=False)
@roles('cz-oms-core-new')
def stop_cz_oms_core__new_3746():
sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)
@roles('cz-oms-core-new')
def start_cz_oms_core__new_3746():
sudo('nohup /opt/bj-oms-core/bin/start.sh &',pty=False)
@roles('cz-oms-core-new1')
def stop_cz_oms_core__new1_4041():
sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)
@roles('cz-oms-core-new1')
def start_cz_oms_core__new1_4041():
sudo('/opt/bj-oms-core/bin/start.sh',pty=False)
@roles('cz')
def stop_cz_bj_oms_rest_30():
sudo('/opt/bj-oms-rest/bin/stop.sh',pty=False)
@roles('cz')
def start_cz_bj_oms_rest_30():
sudo('nohup /opt/bj-oms-rest/bin/start.sh &',pty=False)
@roles('cz')
def stop_cz_bj_oms_job_30():
sudo('/opt/bj-oms-job/bin/stop.sh',pty=False)
@roles('cz')
def start_cz_bj_oms_job_30():
sudo('/opt/bj-oms-job/bin/start.sh',pty=False)
@roles('cz')
def stop_cz_tomcat_oms_30():
sudo('/opt/tomcat-oms/bin/shutdown.sh',pty=False)
@roles('cz')
def start_cz_tomcat_oms_30():
sudo('/opt/tomcat-oms/bin/start.sh',pty=False)
#主程序
if __name__ == '__main__':
#Update SVN
while True:
temp = str(raw_input('1) 请问你要Update SVN吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin Update SVN..."
UpdateSVN('../online_svn/bj-oms/bj-oms-api')
UpdateSVN('../online_svn/bj-oms/bj-oms-core')
UpdateSVN('../online_svn/bj-oms/bj-oms-core-new')
UpdateSVN('../online_svn/bj-oms/bj-oms-core-new1')
UpdateSVN('../online_svn/bj-oms/bj-oms-domain')
UpdateSVN('../online_svn/bj-oms/bj-oms-jobs')
UpdateSVN('../online_svn/bj-oms/bj-oms-rest')
UpdateSVN('../online_svn/bj-tran')
UpdateSVN('../online_svn/bj-whm')
break
elif tips == 'no':
break
#删除patch目录下所有内容
while True:
temp = str(raw_input('2)删除patch目录下所有目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
for line in os.listdir('patch'):
shutil.rmtree('patch/%s' % line)
break
elif tips == 'no':
break
#提示是否eclipse编译代码
while True:
temp = str(raw_input('3) 提示:请问你手工通过eclse编译css代码了吗[yes/no]:'))
tips = temp.strip().lower()
if tips == 'yes':
break
elif tips == 'no':
break
#根据filelist生成发版目录
while True:
temp = str(raw_input('4)根据filelist生成发版目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin generate faban dir..."
faban_dir()
break
elif tips == 'no':
break
#unzip
while True:
temp = str(raw_input('5)解压zip包到本地patch目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin unzip jar to patch dir..."
output = subprocess.check_output(['fab','unzip'],shell=True,stderr = subprocess.STDOUT)
print output
break
elif tips == 'no':
break
#download jar to localpath
while True:
temp = str(raw_input('6)把jar包下载到本地的patch目录吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin download jar to patch dir..."
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
for index,item in enumerate(dirs,1):
if item == 'bj-oms-api':
print "%d: %s is downoading..." % (index,item)
output = subprocess.check_output(['fab','download_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows时可以关闭cmd窗口的回显
print output
elif item == "bj-oms-core-new1":
print "%d: %s is downoading..." % (index,item)
output = subprocess.check_output(['fab','download_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == "bj-oms-rest":
print "%d: %s is downoading..." % (index,item)
output = subprocess.check_output(['fab','download_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == "bj-oms-jobs":
print "%d: %s is downoading..." % (index,item)
output = subprocess.check_output(['fab','download_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == "bj-oms-domain":
print "%d: %s is downoading..." % (index,item)
output = subprocess.check_output(['fab','download_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == "bj-oms-core":
print "%d: %s is downoading..." % (index,item)
output = subprocess.check_output(['fab','download_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == "bj-web":
pass
else:
print('%s下载失败,因为该文件没有在发版程序里面配置,请联系管理员') % item
sys.exit()
break
elif tips == 'no':
break
#replace file to jar
while True:
temp = str(raw_input('7)替换jar包里面的配置文件吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin replace class file from jar ..."
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
for index,item in enumerate(dirs,1):
if item == 'bj-oms-api':
print "%d: %s is replacing jar now..." % (index,item)
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == "bj-oms-core-new1":
while True:
temp = str(raw_input('注意:因bj-oms-core-new1包里面有重复文件,所以需要手工更新jar包里面的内容,你更新了吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
break
elif tips == 'no':
break
elif item == 'bj-oms-domain':
print "%d: %s is replacing jar now..." % (index,item)
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-job':
print "%d: %s is replacing jar now..." % (index,item)
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-rest':
print "%d: %s is replacing jar now..." % (index,item)
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-core':
print "%d: %s is replacing jar now..." % (index,item)
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
print output
break
elif tips == 'no':
break
#backup jar
while True:
temp = str(raw_input('8)在正式发版前希望备份远程服务器的jar包吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin backup jar to /backup..."
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
for index,item in enumerate(dirs,1):
if item == 'bj-oms-api':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows时可以关闭cmd窗口的回显
print output
print
elif item == 'bj-oms-domain':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-core-new1':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-rest':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-jobs':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-web':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_web'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-core':
print "%d: %s is backuping..." % (index,item)
output = subprocess.check_output(['fab','backup_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
print output
break
elif tips == 'no':
break
#发版,上传jar包到生产服务器
while True:
temp = str(raw_input('9)请问开始向生产服务器发版吗?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin publish..."
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
for index,item in enumerate(dirs,1):
if item == 'bj-oms-api':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_oms_api_jar_4748_3746_4041'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows时可以关闭cmd窗口的回显
print output
output = subprocess.check_output(['fab','put_bj_oms_api_jar_30'],shell=True,stderr = subprocess.STDOUT)
print output
print
elif item == 'bj-oms-domain':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_oms_domain_jar_4748_3746_4041'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','put_bj_oms_domain_jar_30'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-core-new1':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-rest':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-jobs':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-web':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_web'],shell=True,stderr = subprocess.STDOUT)
print output
elif item == 'bj-oms-core':
print "%d: %s is publishing..." % (index,item)
output = subprocess.check_output(['fab','put_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
print output
break
elif tips == 'no':
break
#关闭服务
while True:
temp = str(raw_input('10)请问开始关闭服务吗,包含服务tomcat、rest、job、core?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin stop service..."
output = subprocess.check_output(['fab','stop_cz_tomcat_oms_30'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','stop_cz_bj_oms_rest_30'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','stop_cz_bj_oms_job_30'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','stop_cz_oms_core_4748'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','stop_cz_oms_core__new_3746'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','stop_cz_oms_core__new1_4041'],shell=True,stderr = subprocess.STDOUT)
print output
elif tips == 'no':
break
#开启服务
while True:
temp = str(raw_input('11)请问开始启动服务吗,包含服务core、tomcat、rest、job?[yes/no]:'.decode('utf-8').encode('gb2312')))
tips = temp.strip().lower()
if tips == 'yes':
print "Now begin stop service..."
output = subprocess.check_output(['fab','start_cz_oms_core__new1_4041'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','start_cz_oms_core__new_3746'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','start_cz_oms_core_4748'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','start_cz_tomcat_oms_30'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','start_cz_bj_oms_rest_30'],shell=True,stderr = subprocess.STDOUT)
print output
output = subprocess.check_output(['fab','start_cz_bj_oms_job_30'],shell=True,stderr = subprocess.STDOUT)
print output
elif tips == 'no':
break
感谢各位的阅读!关于“如何使用fabric自动化发版”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。