Commit cf53ec4e authored by xiaolin.zhu's avatar xiaolin.zhu

add diff config

parent c47f04cd
var source_file,java_config_path,L,key,value,FL
var IP_REG = new RegExp(/((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))/g);
process.argv.forEach(function (val, index, array) {
if(index == 2){
source_file = val;
}else{
java_config_path = val;
}
});
console.log("本地配置文件:%s",source_file)
console.log("项目配置文件:%s",java_config_path)
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}
var list_source_file_keys = {},diff_list=[],value_of_diff_change;
var java_config_data,java_config_data_lines;
var fs=require("fs");
var path = require('path');
var list_source_file_data = fs.readFileSync(source_file,'utf-8');
var lines = list_source_file_data.split("\n")
for (var i = 0; i < lines.length; ++i) {
L = lines[i].split("=")
key = L[0]
value = L[1]
FL = L[0].replace(/\s/g,"");
if( FL[0] != "#" && FL.length != 0){
list_source_file_keys[L[0]] = L[1];
}
}
fs.readdir(java_config_path,function(err,files){
var count = files.length;
files.forEach(function(filename){
if(filename.indexOf(".properties") != -1){
var java_config_data = fs.readFileSync(path.join(java_config_path,filename),'utf-8');
var java_config_data_lines = java_config_data.split("\n")
for (var i = 0; i < java_config_data_lines.length; ++i) {
L = java_config_data_lines[i].split("=")
key = L[0]
value = L[1]
FL = L[0].replace(/\s/g,"");
if( FL[0] != "#" && FL.length != 0){
if(typeof list_source_file_keys[L[0]] == "undefined"){
console.log("Warning!!!: \"%s\"\t",L[0]);
diff_list.push({name:L[0],value:L[1]})
}
}
}
}
})
if(diff_list.length > 0){
fs.appendFile(source_file, "#时间:"+getNowFormatDate() + ",差异追加如下:\n");
}
for( var i = 0; i < diff_list.length; ++i ){
if (IP_REG.test(diff_list[i].value)) {
IP_REG.lastIndex = 0;
fs.appendFile(source_file, "#"+diff_list[i].name + "=" + diff_list[i].value + "\n");
value_of_diff_change = diff_list[i].value.replace(/((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))/g,"localhost")
fs.appendFile(source_file, diff_list[i].name + "=" + value_of_diff_change + "\n");
}else{
fs.appendFile(source_file, diff_list[i].name + "=" + diff_list[i].value + "\n");
}
}
})
......@@ -34,23 +34,54 @@ else
echo "Step 1: skip checkout branch: $branch_name"
fi
# 增加文件差异对比 2017-01-15 田亚伟
echo "Step 1.1: checkout properties files: "
config_path=`pwd`
expect -c "
spawn scp root@${host}:/home/quant_group/${module}/*.properties ./
expect {
\"*assword\" {
send \"!QAZ2wsx\n\"
}
}
expect eof"
echo "------------------------config_fidd:begin------------------------------"
echo `node ${utils_path}/sh-utils/deploy/check_file_diff.js ${config_path}/application.properties /home/quant_group/jenkins/workspace/deploy_${module}/src/main/resources/config/test/`
sed $(echo -e "s/\r//") application.properties > application_last.properties
echo `pwd`
expect -c "
spawn scp ${config_path}/application_last.properties root@${host}:/home/quant_group/${module}/application.properties
expect {
\"*assword\" {
send \"!QAZ2wsx\n\"
}
}
expect eof"
echo "-------------------------config_fidd:end-------------------------------"
# 增加文件差异对比 结束2017-01-15 田亚伟
if [ "$build_java" = true ]; then
echo "Step 2: build project: $branch_name"
sh ${utils_path}/sh-utils/center/2_build_java.sh $profile $module $host $close_captcha
# sh ${utils_path}/sh-utils/center/2_build_java.sh $profile $module $host $close_captcha
else
echo "Step 2: skip build project: $branch_name"
fi
if [ "$remote_copy" = true ]; then
echo "Step 3: remote copy project: "
sh ${utils_path}/sh-utils/center/3_remote_copy.sh $module $host java
# sh ${utils_path}/sh-utils/center/3_remote_copy.sh $module $host java
else
echo "Step 3: skip remote copy project"
fi
if [ "$restart_java" = true ]; then
echo "Step 4: restart project: "
sh ${utils_path}/sh-utils/center/4_java_restart.sh $module $host "${re_load_config}" "${use_pulic_ip}"
# sh ${utils_path}/sh-utils/center/4_java_restart.sh $module $host "${re_load_config}" "${use_pulic_ip}"
else
echo "Step 4: skip restart project"
fi
......
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