Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-deploy-utils
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-deploy-utils
Commits
7613cf97
Commit
7613cf97
authored
Mar 22, 2018
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.gitignore
parent
3ac64cd8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
169 deletions
+172
-169
.gitignore
.gitignore
+1
-2
get_project_config_server.js
qa_shell_script/config_server/get_project_config_server.js
+168
-165
package.json
qa_shell_script/config_server/package.json
+3
-2
No files found.
.gitignore
View file @
7613cf97
...
...
@@ -9,5 +9,4 @@
.DS_Store
qa_shell_script/config_server/node_modules
.log
./qa_shell_script/config_server/package.json
./qa_shell_script/config_server/package-lock.json
qa_shell_script/config_server/package-lock.json
qa_shell_script/config_server/get_project_config_server.js
View file @
7613cf97
...
...
@@ -14,16 +14,16 @@ var options = {
type
:
'
application/octet-stream
'
};
// 同步进行接口转发
function
requestPromise
(
option
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
option
,
function
(
err
,
res
,
body
)
{
if
(
err
)
{
reject
(
err
)
}
else
{
resolve
(
body
)
}
function
requestPromise
(
option
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
option
,
function
(
err
,
res
,
body
)
{
if
(
err
)
{
reject
(
err
)
}
else
{
resolve
(
body
)
}
})
})
})
}
// mongoose.connect('mongodb://localhost/my_database');
mongoose
.
connect
(
'
mongodb://172.30.220.22:27017/qaHome
'
)
...
...
@@ -93,69 +93,72 @@ function parseJson2Str(json) {
let
db_conf
=
db_config
.
db_config
();
let
db_conf_keys
=
Object
.
keys
(
db_conf
);
// 从mongo中获取配置
function
getProjectConfigPromise
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
// mongoose.model("ProConfig",new mongoose.Schema({}))
ProConfig
.
find
({}).
exec
().
then
(
res
=>
{
let
_pros
=
JSON
.
parse
(
JSON
.
stringify
(
res
));
let
re
=
{},
hosts
=
{};
for
(
let
pro
of
_pros
)
{
hosts
[
pro
[
"
project_name
"
]]
=
pro
[
"
host_name
"
];
if
(
pro
[
"
project_name
"
]
==
"
xjd-ui
"
)
{
hosts
[
"
xyqb-ui--xjd-ui
"
]
=
pro
[
"
host_name
"
];
}
else
if
(
pro
[
"
project_name
"
]
==
"
new-paycenter-ui
"
)
{
hosts
[
"
paycenter-ui--new-paycenter-ui
"
]
=
pro
[
"
host_name
"
];
}
// else if(pro["project_name"] == "new-spider-center-ui"){
// hosts["spider-center-ui--new-spider-center-ui"] = pro["host_name"];
// }
let
temp
=
{
project_group
:
""
,
name
:
pro
[
"
project_name
"
],
type
:
pro
[
"
type
"
],
url
:
pro
[
"
host_name
"
].
replace
(
"
.xyqb.com
"
,
""
).
replace
(
"
.quantgroup.cn
"
,
""
),
www
:
pro
[
"
host_name
"
],
git_path
:
pro
[
"
git_path
"
],
log_name
:
pro
[
"
log_path
"
],
config_file
:
pro
[
"
config_path
"
],
command
:
""
,
command_
:
""
,
command2
:
""
,
node_version
:
""
,
port
:
`
${
pro
[
"
port
"
]}
`
,
desc
:
pro
[
"
des
"
],
is_active
:
pro
[
"
is_active
"
],
auth
:
pro
[
"
auth
"
],
target_path
:
""
}
if
(
pro
[
"
type
"
]
==
"
java
"
)
{
temp
.
node_version
=
pro
[
"
command1
"
];
temp
.
target_path
=
pro
[
"
jar_path
"
];
temp
.
command2
=
pro
[
"
build_command
"
];
temp
.
command
=
pro
[
"
start_command
"
];
}
else
if
(
pro
[
"
type
"
]
==
"
ui
"
)
{
temp
.
command
=
pro
[
"
build_command
"
]
}
else
if
(
pro
[
"
type
"
]
==
"
node
"
)
{
temp
.
command
=
pro
[
"
start_command
"
]
temp
.
command2
=
pro
[
"
stop_command
"
]
}
else
if
(
pro
[
"
type
"
]
==
"
python
"
)
{
function
getProjectConfigPromise
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
// mongoose.model("ProConfig",new mongoose.Schema({}))
ProConfig
.
find
({}).
exec
().
then
(
res
=>
{
let
_pros
=
JSON
.
parse
(
JSON
.
stringify
(
res
));
let
re
=
{},
hosts
=
{};
for
(
let
pro
of
_pros
)
{
hosts
[
pro
[
"
project_name
"
]]
=
pro
[
"
host_name
"
];
if
(
pro
[
"
project_name
"
]
==
"
xjd-ui
"
)
{
hosts
[
"
xyqb-ui--xjd-ui
"
]
=
pro
[
"
host_name
"
];
}
else
if
(
pro
[
"
project_name
"
]
==
"
new-paycenter-ui
"
)
{
hosts
[
"
paycenter-ui--new-paycenter-ui
"
]
=
pro
[
"
host_name
"
];
}
// else if(pro["project_name"] == "new-spider-center-ui"){
// hosts["spider-center-ui--new-spider-center-ui"] = pro["host_name"];
// }
let
temp
=
{
project_group
:
""
,
name
:
pro
[
"
project_name
"
],
type
:
pro
[
"
type
"
],
url
:
pro
[
"
host_name
"
].
replace
(
"
.xyqb.com
"
,
""
).
replace
(
"
.quantgroup.cn
"
,
""
),
www
:
pro
[
"
host_name
"
],
git_path
:
pro
[
"
git_path
"
],
log_name
:
pro
[
"
log_path
"
],
config_file
:
pro
[
"
config_path
"
],
command
:
""
,
command_
:
""
,
command2
:
""
,
node_version
:
""
,
port
:
`
${
pro
[
"
port
"
]}
`
,
desc
:
pro
[
"
des
"
],
is_active
:
pro
[
"
is_active
"
],
auth
:
pro
[
"
auth
"
],
target_path
:
""
}
if
(
pro
[
"
type
"
]
==
"
java
"
)
{
temp
.
node_version
=
pro
[
"
command1
"
];
temp
.
target_path
=
pro
[
"
jar_path
"
];
temp
.
command2
=
pro
[
"
build_command
"
];
temp
.
command
=
pro
[
"
start_command
"
];
}
else
if
(
pro
[
"
type
"
]
==
"
ui
"
)
{
temp
.
command
=
pro
[
"
build_command
"
]
}
else
if
(
pro
[
"
type
"
]
==
"
node
"
)
{
temp
.
command
=
pro
[
"
start_command
"
]
temp
.
command2
=
pro
[
"
stop_command
"
]
}
else
if
(
pro
[
"
type
"
]
==
"
python
"
)
{
}
re
[
temp
[
"
name
"
]]
=
temp
;
}
resolve
({
projects
:
re
,
hosts
:
hosts
})
}).
catch
((
err
)
=>
{
reject
(
err
)
});
})
}
re
[
temp
[
"
name
"
]]
=
temp
;
}
resolve
({
projects
:
re
,
hosts
:
hosts
})
}).
catch
((
err
)
=>
{
reject
(
err
)
});
})
}
//
admin
.
get
(
'
/get_db_config/:name/:attr
'
,
function
(
req
,
res
)
{
admin
.
get
(
'
/get_db_config/:name/:attr
'
,
function
(
req
,
res
)
{
console
.
log
(
111
,
req
)
console
.
log
(
222
,
res
)
let
str
=
""
if
(
req
.
params
.
name
==
"
all
"
)
{
if
(
req
.
params
.
attr
==
"
name
"
)
{
...
...
@@ -171,14 +174,14 @@ admin.get('/get_db_config/:name/:attr', function(req, res) {
}
});
admin
.
get
(
'
/get_db_dump_command/:name/:opt
'
,
function
(
req
,
res
)
{
admin
.
get
(
'
/get_db_dump_command/:name/:opt
'
,
function
(
req
,
res
)
{
if
(
req
.
params
.
opt
!=
"
opt
"
)
{
res
.
send
(
db_config
.
get_mysql_dump_table
(
req
.
params
.
name
));
}
else
{
res
.
send
(
db_config
.
get_mysql_dump_opt
(
req
.
params
.
name
));
}
});
admin
.
get
(
'
/get_db_config/refersh
'
,
function
()
{
admin
.
get
(
'
/get_db_config/refersh
'
,
function
()
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
db_conf
=
db_config
.
db_config
();
db_conf_keys
=
Object
.
keys
(
db_conf
);
...
...
@@ -187,17 +190,17 @@ admin.get('/get_db_config/refersh', function() {
// 获取节点命令
admin
.
get
(
'
/get_node_command/:name
'
,
async
function
(
req
,
res
)
{
admin
.
get
(
'
/get_node_command/:name
'
,
async
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
let
configs
=
await
getProjectConfigPromise
();
let
configs
=
await
getProjectConfigPromise
();
let
projects
=
configs
.
projects
let
pro
=
projects
[
req
.
params
.
name
];
let
pro
=
projects
[
req
.
params
.
name
];
res
.
send
({
configPath
:
pro
.
config_file
,
buildCmd
:
pro
.
command
,
gitGroup
:
pro
.
gitPathHead
});
});
// 获取项目配置
admin
.
get
(
'
/get_project_attr/:name
'
,
async
function
(
req
,
res
)
{
admin
.
get
(
'
/get_project_attr/:name
'
,
async
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
var
names
=
req
.
params
.
name
.
split
(
"
--
"
);
var
p_name
=
""
;
...
...
@@ -206,75 +209,75 @@ admin.get('/get_project_attr/:name', async function(req, res) {
}
else
{
p_name
=
req
.
params
.
name
}
try
{
let
configs
=
await
getProjectConfigPromise
();
let
projects
=
configs
.
projects
let
pro
=
projects
[
p_name
];
let
rs
=
{};
for
(
let
item
of
attrComs
)
{
rs
[
item
]
=
pro
[
attrs
[
item
]]
}
res
.
send
(
rs
);
}
catch
(
e
)
{
console
.
log
(
e
)
res
.
send
(
e
)
}
try
{
let
configs
=
await
getProjectConfigPromise
();
let
projects
=
configs
.
projects
let
pro
=
projects
[
p_name
];
let
rs
=
{};
for
(
let
item
of
attrComs
)
{
rs
[
item
]
=
pro
[
attrs
[
item
]]
}
res
.
send
(
rs
);
}
catch
(
e
)
{
console
.
log
(
e
)
res
.
send
(
e
)
}
});
// 获取所有域名
admin
.
get
(
'
/get_hosts
'
,
async
function
(
req
,
res
)
{
admin
.
get
(
'
/get_hosts
'
,
async
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
let
configs
=
await
getProjectConfigPromise
();
let
configs
=
await
getProjectConfigPromise
();
res
.
send
(
configs
.
hosts
);
});
// 根据类型获取系统名称
function
getfrontendbackend
(
pros
){
let
temp
=
{
frontend
:
[],
backend
:
[],
ui
:
[],
node
:
[],
java
:
[],
python
:
[]
}
let
keys
=
Object
.
keys
(
pros
)
// console.log(keys)
for
(
let
key
of
keys
)
{
let
pro
=
pros
[
key
]
if
(
pro
.
type
==
"
ui
"
)
{
// && pro.name != "spider-center-ui"
if
(
pro
.
name
!=
"
xyqb-ui
"
&&
pro
.
name
!=
"
paycenter-ui
"
)
{
if
(
pro
.
name
==
"
xjd-ui
"
)
{
temp
.
frontend
.
push
(
"
xyqb-ui--xjd-ui
"
);
temp
[
pro
.
type
].
push
(
"
xyqb-ui--xjd-ui
"
)
}
else
if
(
pro
.
name
==
"
new-paycenter-ui
"
)
{
temp
.
frontend
.
push
(
"
paycenter-ui--new-paycenter-ui
"
);
temp
[
pro
.
type
].
push
(
"
paycenter-ui--new-paycenter-ui
"
)
}
// else if(pro.name == "new-spider-center-ui"){
// temp.frontend.push("spider-center-ui--new-spider-center-ui");
// temp[pro.type].push("spider-center-ui--new-spider-center-ui")
// }
else
{
temp
.
frontend
.
push
(
pro
.
name
);
temp
[
pro
.
type
].
push
(
pro
.
name
)
}
}
}
else
{
temp
.
backend
.
push
(
pro
.
name
);
temp
[
pro
.
type
].
push
(
pro
.
name
)
}
}
return
temp
function
getfrontendbackend
(
pros
)
{
let
temp
=
{
frontend
:
[],
backend
:
[],
ui
:
[],
node
:
[],
java
:
[],
python
:
[]
}
let
keys
=
Object
.
keys
(
pros
)
// console.log(keys)
for
(
let
key
of
keys
)
{
let
pro
=
pros
[
key
]
if
(
pro
.
type
==
"
ui
"
)
{
// && pro.name != "spider-center-ui"
if
(
pro
.
name
!=
"
xyqb-ui
"
&&
pro
.
name
!=
"
paycenter-ui
"
)
{
if
(
pro
.
name
==
"
xjd-ui
"
)
{
temp
.
frontend
.
push
(
"
xyqb-ui--xjd-ui
"
);
temp
[
pro
.
type
].
push
(
"
xyqb-ui--xjd-ui
"
)
}
else
if
(
pro
.
name
==
"
new-paycenter-ui
"
)
{
temp
.
frontend
.
push
(
"
paycenter-ui--new-paycenter-ui
"
);
temp
[
pro
.
type
].
push
(
"
paycenter-ui--new-paycenter-ui
"
)
}
// else if(pro.name == "new-spider-center-ui"){
// temp.frontend.push("spider-center-ui--new-spider-center-ui");
// temp[pro.type].push("spider-center-ui--new-spider-center-ui")
// }
else
{
temp
.
frontend
.
push
(
pro
.
name
);
temp
[
pro
.
type
].
push
(
pro
.
name
)
}
}
}
else
{
temp
.
backend
.
push
(
pro
.
name
);
temp
[
pro
.
type
].
push
(
pro
.
name
)
}
}
return
temp
}
admin
.
get
(
'
/get_systems_by_type
'
,
async
function
(
req
,
res
)
{
admin
.
get
(
'
/get_systems_by_type
'
,
async
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
let
configs
=
await
getProjectConfigPromise
();
let
pros
=
configs
.
projects
;
let
fb
=
getfrontendbackend
(
pros
);
let
configs
=
await
getProjectConfigPromise
();
let
pros
=
configs
.
projects
;
let
fb
=
getfrontendbackend
(
pros
);
res
.
send
({
common
:
"
db,redis,rabbitmq,zookeeper
"
,
frontend
:
fb
.
frontend
.
join
(
"
,
"
),
...
...
@@ -283,48 +286,48 @@ admin.get('/get_systems_by_type',async function(req, res) {
});
// 给jenkins使用根据类型获取系统名称
admin
.
get
(
'
/get_systems_by_type_for_jenkins/:_type
'
,
async
function
(
req
,
res
)
{
let
str
=
""
;
let
configs
=
await
getProjectConfigPromise
();
let
pros
=
configs
.
projects
;
let
fb
=
getfrontendbackend
(
pros
);
if
(
req
.
params
.
_type
===
"
frontend
"
)
{
res
.
send
(
fb
.
frontend
.
join
(
"
"
));
}
else
{
res
.
send
(
fb
.
backend
.
join
(
"
"
));
}
admin
.
get
(
'
/get_systems_by_type_for_jenkins/:_type
'
,
async
function
(
req
,
res
)
{
let
str
=
""
;
let
configs
=
await
getProjectConfigPromise
();
let
pros
=
configs
.
projects
;
let
fb
=
getfrontendbackend
(
pros
);
if
(
req
.
params
.
_type
===
"
frontend
"
)
{
res
.
send
(
fb
.
frontend
.
join
(
"
"
));
}
else
{
res
.
send
(
fb
.
backend
.
join
(
"
"
));
}
});
// 给jenkins使用根据类型获取系统名称
admin
.
get
(
'
/get_systems_by_type_for_temp
'
,
async
function
(
req
,
res
)
{
let
configs
=
await
getProjectConfigPromise
();
let
pros
=
configs
.
projects
;
let
fb
=
getfrontendbackend
(
pros
);
res
.
send
({
ui
:
fb
.
ui
.
join
(
"
"
),
java
:
fb
.
java
.
join
(
"
"
),
node
:
fb
.
node
.
join
(
"
"
),
python
:
fb
.
python
.
join
(
"
"
)
});
admin
.
get
(
'
/get_systems_by_type_for_temp
'
,
async
function
(
req
,
res
)
{
let
configs
=
await
getProjectConfigPromise
();
let
pros
=
configs
.
projects
;
let
fb
=
getfrontendbackend
(
pros
);
res
.
send
({
ui
:
fb
.
ui
.
join
(
"
"
),
java
:
fb
.
java
.
join
(
"
"
),
node
:
fb
.
node
.
join
(
"
"
),
python
:
fb
.
python
.
join
(
"
"
)
});
});
// 给jenkins使用获取环境的namespace
admin
.
get
(
'
/get_namespace_by_type_for_jenkins/:_type
'
,
async
function
(
req
,
res
)
{
let
url
=
""
;
if
(
req
.
params
.
_type
==
"
old
"
)
{
url
=
"
http://192.168.6.13/api/qahome/list_env
"
}
let
ns
=
await
requestPromise
({
url
:
url
,
method
:
"
GET
"
});
ns
=
JSON
.
parse
(
ns
);
let
ns_array
=
[];
for
(
let
ist
of
ns
.
details
.
instances
)
{
ns_array
.
push
(
ist
.
name
)
}
res
.
send
(
ns_array
.
join
(
"
\n
"
));
admin
.
get
(
'
/get_namespace_by_type_for_jenkins/:_type
'
,
async
function
(
req
,
res
)
{
let
url
=
""
;
if
(
req
.
params
.
_type
==
"
old
"
)
{
url
=
"
http://192.168.6.13/api/qahome/list_env
"
}
let
ns
=
await
requestPromise
({
url
:
url
,
method
:
"
GET
"
});
ns
=
JSON
.
parse
(
ns
);
let
ns_array
=
[];
for
(
let
ist
of
ns
.
details
.
instances
)
{
ns_array
.
push
(
ist
.
name
)
}
res
.
send
(
ns_array
.
join
(
"
\n
"
));
});
// 增加一个新的nginx映射
admin
.
post
(
'
/add_new_proxy
'
,
function
(
req
,
res
)
{
admin
.
post
(
'
/add_new_proxy
'
,
function
(
req
,
res
)
{
let
request
=
req
.
body
;
let
new_namespace
=
request
[
"
namespace
"
],
new_ip
=
request
[
"
ip
"
],
...
...
@@ -347,7 +350,7 @@ admin.post('/add_new_proxy', function(req, res) {
// 删除一个namespace映射
admin
.
post
(
'
/remove_proxy
'
,
function
(
req
,
res
)
{
admin
.
post
(
'
/remove_proxy
'
,
function
(
req
,
res
)
{
let
request
=
req
.
body
;
console
.
log
(
request
);
let
new_namespace
=
request
[
"
namespace
"
];
...
...
@@ -369,7 +372,7 @@ admin.post('/remove_proxy', function(req, res) {
});
// 获取现有映射关系
admin
.
get
(
'
/get_proxy
'
,
function
(
req
,
res
)
{
admin
.
get
(
'
/get_proxy
'
,
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
var
str
=
execSync
(
`cat ../ngrok/docker_env_name.sh`
)
res
.
send
({
namespace
:
String
(
str
)
});
...
...
qa_shell_script/config_server/package.json
View file @
7613cf97
...
...
@@ -12,8 +12,9 @@
"body-parser"
:
"^1.18.2"
,
"child_process"
:
"^1.0.2"
,
"express"
:
"^4.16.2"
,
"request"
:
"^2.83.0"
,
"mongodb"
:
"^2.2.33"
,
"pm2"
:
"^2.7.2"
"mongoose"
:
"^5.0.11"
,
"pm2"
:
"^2.7.2"
,
"request"
:
"^2.83.0"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment