Commit ea251230 authored by xuezj's avatar xuezj

支持定义规则顺序

parent 7fe54549
......@@ -8,22 +8,21 @@ import os.path
import re
import copy
import sys
# import requests
opApiHost = 'http://172.30.220.22:3003'
f = io.open('replace_config.yaml', 'r', encoding='utf-8')
res = yaml.load(f)
print("全部配置信息:", res)
# 查看配置中是否有当前项目
# 获取当前项目的配置
env = os.environ
project = env.get('SYSTEM_NAME')
distPath = os.path.abspath(project + '/dist')
config = res.get(project, res.get('common'))
config = sorted(config.items(), key=lambda rule: (rule[1]['order'], rule[0]))
print(project, "的配置信息:", config)
print("dist路径:", distPath)
# 根据内容进行替换
namespace = env.get('NAMESPACE')
print('namespace:', namespace)
......@@ -46,16 +45,11 @@ findFile(distPath)
for file in files:
for line in fileinput.input(file, inplace = 1):
for item in config:
if not config[item]:
continue
rule = copy.deepcopy(config[item])
rule = copy.deepcopy(item[1])
if rule.get('useNamespace', None) and rule['to']:
rule['to'] = '-' + namespace + rule['to']
if rule.get('useDomain',None):
# domain = requests.get(opApiHost + '/proconfig/get_host?system_name=' + project)
# domain = domain.json['data'].split('.')[0]
if rule.get('useDomain', None):
domain = sys.argv[1].split('.')[0]
rule['to'] = '//' + domain + rule['to']
......
# reg: 匹配的正则
# to: 正则匹配后替换需要的值
# useNamespace: 是否在替换的值前追加 '-[namespace名称]'
# order 默认0
rule: &rule
reg: ''
to: ''
useNamespace: false
order: 0
lkbDomain: &lkbDomain '.liangkebang.com'
# 替换xyqbapi
xyqbApiRule: &xyqbApiRule
<<: *rule
reg: '(?<=\w).xyqb.com'
to: *lkbDomain
useNamespace: true
# 替换quantgroupApi
quantgroupApiRule: &quantgroupApiRule
<<: *rule
reg: '(?<=\w).quantgroup.cn'
to: *lkbDomain
useNamespace: true
# 替换cookie
xyqbCookieRule: &xyqbCookieRule
<<: *rule
reg: '(?<![\w]).xyqb.com'
to: *lkbDomain
qgApiRule: &qgApiRule
<<: *rule
reg: '(?<=\w).q-gp.com'
to: *lkbDomain
useNamespace: true
qgCookieRule: &qgCookieRule
<<: *rule
reg: '(?<![\w]).q-gp.com'
to: *lkbDomain
# todo: 看哪个项目需要
h5AuthRule: &h5AuthRule
<<: *rule
reg: 'auth[-a-z]*\.[a-z]*\.[a-z]*'
to: 'operator.liangkebang.com'
# staticRule: &staticRule
# reg: '//static[-/0-9a-z.]*public'
# to: ''
staticRule: &staticRule
<<: *rule
reg: '//static[-/0-9a-z.]*public'
to: *lkbDomain
useNamespace: true
......
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