Commit c1c11839 authored by 智勇's avatar 智勇

ui run.sh

parent ff0a7eae
...@@ -31,5 +31,7 @@ COPY --from=0 /code/* /home/quant_group/ ...@@ -31,5 +31,7 @@ COPY --from=0 /code/* /home/quant_group/
COPY docker-entrypoint.sh . COPY docker-entrypoint.sh .
COPY run.sh . COPY run.sh .
COPY replace.py .
COPY replace_config.yaml .
RUN chmod +x ./docker-entrypoint.sh RUN chmod +x ./docker-entrypoint.sh
CMD ./docker-entrypoint.sh CMD ./docker-entrypoint.sh
\ No newline at end of file
# coding=UTF-8
from __future__ import print_function
import io
import yaml
import fileinput
import os
import os.path
import re
import copy
import sys
import string
f = io.open('replace_config.yaml', 'r', encoding='utf-8')
res = yaml.load(f)
print("全部配置信息:", res)
# 获取当前项目的配置
env = os.environ
project = env.get('SYSTEM_NAME')
config = res.get(project, res.get('common'))
config = sorted(config.items(), key=lambda rule: (rule[1]['order'], rule[0]))
print(project, "的配置信息:", config)
namespace = env.get('NAMESPACE')
print('namespace:', namespace)
print('host:', sys.argv[1])
files = []
acceptType = {'.html', '.js', '.css'}
def findFile (dir):
if os.path.isfile(dir):
suffix = os.path.splitext(dir)[-1]
if (suffix in acceptType):
files.append(dir)
return
else:
for sub in os.listdir(dir):
findFile(dir + '/' + sub)
distPaths = []
if '--' in project:
distPaths.append(os.path.abspath(project.split('--')[0] + '/dist'))
distPaths.append(os.path.abspath(project.split('--')[1] + '/dist'))
else:
distPaths.append(os.path.abspath(project + '/dist'))
# 过滤符合要求的文件路径
for distPath in distPaths:
print("dist路径:", distPath)
findFile(distPath)
# 替换文件中的内容
for file in files:
for line in fileinput.input(file, inplace = 1):
for item in config:
rule = copy.deepcopy(item[1])
if rule.get('useNamespace', None) and rule['to']:
rule['to'] = '-' + namespace + rule['to']
if rule.get('useHost', None):
domain = sys.argv[1].split('.')[0]
rule['to'] = '//' + domain + rule['to']
if rule['reg']:
p = re.compile(r'' + rule['reg'])
line = re.sub(p, rule['to'], line)
print(line, end = '')
fileinput.close()
f.close()
\ No newline at end of file
# reg: 匹配的正则
# to: 正则匹配后替换需要的值
# useNamespace: 是否在替换的值前追加 '-[namespace名称]'
# useHost: 是否在替换时使用该项目域名的第一段
# order 默认0, 负数用在自定义属性上,在通用规则前生效
rule: &rule
reg: ''
to: ''
useNamespace: false
useHost: 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
h5AuthRule: &h5AuthRule
<<: *rule
# reg: 'auth[-a-z]*\.[a-z]*\.[a-z]*'
reg: 'auth.quantgroup.cn'
to: 'operator.liangkebang.com'
staticRule: &staticRule
<<: *rule
reg: '//static[-/0-9a-z.]*public'
to: *lkbDomain
useNamespace: true
useHost: true
# 神测用户采集
bnRule: &bnRule
<<: *rule
reg: 'bn[-/0-9a-z.]*liangkebang.com'
to: 'bn.xyqb.com'
order: 8
# 神测测试环境
bnDefaultRule: &bnDefaultRule
<<: *rule
reg: '.com/sa.gif?project=production'
to: '.com/sa.gif?project=default'
common: &common
h5AuthRule: *h5AuthRule
qgApiRule: *qgApiRule
qgCookieRule: *qgCookieRule
quantgroupApiRule: *quantgroupApiRule
staticRule: *staticRule
xyqbApiRule: *xyqbApiRule
xyqbCookieRule: *xyqbCookieRule
bnRule: *bnRule
bnDefaultRule: *bnDefaultRule
\ No newline at end of file
...@@ -25,12 +25,10 @@ do ...@@ -25,12 +25,10 @@ do
echo "tar zxf ${current}/$with_ext -C ${current}/$fname" echo "tar zxf ${current}/$with_ext -C ${current}/$fname"
tar zxf ${current}/$with_ext -C ${current}/$fname tar zxf ${current}/$with_ext -C ${current}/$fname
# echo "rm -rf ${package_path}/$with_ext"
# rm -rf ${package_path}/$with_ext
done done
curl -sSL http://git.quantgroup.cn/QA/config_repository/raw/master/yaml/replace.py -o replace.py # curl -sSL http://git.quantgroup.cn/QA/config_repository/raw/master/yaml/replace.py -o replace.py
curl -sSL http://git.quantgroup.cn/QA/config_repository/raw/master/yaml/replace_config.yaml -o replace_config.yaml # curl -sSL http://git.quantgroup.cn/QA/config_repository/raw/master/yaml/replace_config.yaml -o replace_config.yaml
python replace.py $host; python replace.py $host;
echo "/usr/bin/openresty -g 'daemon off;'" echo "/usr/bin/openresty -g 'daemon off;'"
......
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