Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tke-eos
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
tke-eos
Commits
b49b89f2
Commit
b49b89f2
authored
Feb 01, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common service
parent
da7de734
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
169 additions
and
25 deletions
+169
-25
.eslintrc.json
.eslintrc.json
+3
-0
.gitignore
.gitignore
+1
-0
commonService.js
app/commonService.js
+40
-0
index.js
app/index.js
+11
-8
rabbitmq.js
app/rabbitmq.js
+7
-8
service.js
app/service.js
+3
-4
zookeeper.js
app/zookeeper.js
+29
-0
index.js
serviceTemplate/index.js
+10
-2
java.template.txt
serviceTemplate/java.template.txt
+15
-0
mysql.template.txt
serviceTemplate/mysql.template.txt
+24
-0
nodejs.template.txt
serviceTemplate/nodejs.template.txt
+0
-1
rabbitmq.template.txt
serviceTemplate/rabbitmq.template.txt
+0
-1
ui.template.txt
serviceTemplate/ui.template.txt
+0
-1
zookeeper.template.txt
serviceTemplate/zookeeper.template.txt
+26
-0
No files found.
.eslintrc.json
0 → 100644
View file @
b49b89f2
{
"extends"
:
"standard"
}
\ No newline at end of file
.gitignore
View file @
b49b89f2
.DS_Store
node_modules
package-lock.json
/dist
# local env files
...
...
app/commonService.js
0 → 100644
View file @
b49b89f2
const
Router
=
require
(
'
koa-router
'
)
const
yaml
=
require
(
'
js-yaml
'
)
const
templates
=
require
(
'
../serviceTemplate
'
)
const
IMAGES
=
{
zookeeper
:
'
zookeeper:3.4.10
'
,
rabbitmq
:
'
rabbitmq:3.6-management
'
,
mysql
:
'
mysql:5.7
'
}
const
router
=
new
Router
()
module
.
exports
=
router
router
.
post
(
'
/create
'
,
async
ctx
=>
{
let
{
serviceName
,
namespace
}
=
ctx
.
request
.
body
if
(
!
Object
.
keys
(
IMAGES
).
includes
(
serviceName
))
{
ctx
.
body
=
ctx
.
fail
(
'
不支持的服务类型
'
)
return
}
let
data
=
{
namespace
,
image
:
IMAGES
[
serviceName
]
}
let
template
=
templates
[
serviceName
].
replace
(
/{{
([
A-Za-z0-9_
]
+
)
}}/g
,
function
()
{
if
(
data
[
arguments
[
1
]]
===
undefined
)
{
throw
new
Error
(
'
缺少模板所需变量
'
)
}
return
data
[
arguments
[
1
]]
})
let
params
=
yaml
.
load
(
template
)
await
ctx
.
client
.
service_create
(
params
)
ctx
.
body
=
ctx
.
ok
(
'
创建成功
'
)
})
router
.
post
(
'
/delete
'
,
async
ctx
=>
{
let
{
serviceName
,
namespace
}
=
ctx
.
request
.
body
await
ctx
.
client
.
service_delete
(
serviceName
,
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
删除成功
'
)
})
app/index.js
View file @
b49b89f2
...
...
@@ -7,7 +7,9 @@ const result = require('../middleware/result')
const
namespaceRoute
=
require
(
'
./namespace
'
)
const
serviceRoute
=
require
(
'
./service
'
)
const
rabbitmqRoute
=
require
(
'
./rabbitmq
'
)
// const rabbitmqRoute = require('./rabbitmq')
// const zookeeperRoute = require('./zookeeper')
const
commonServiceRoute
=
require
(
'
./commonService
'
)
const
ingressRoute
=
require
(
'
./ingress
'
)
const
client
=
require
(
'
../services/tke.service
'
).
create
({
...
...
@@ -28,20 +30,21 @@ function loadRoutes (router) {
},
bodyParser
())
.
use
(
'
/namespace
'
,
namespaceRoute
.
routes
())
.
use
(
'
/service
'
,
serviceRoute
.
routes
())
.
use
(
'
/rabbitmq
'
,
rabbitmqRoute
.
routes
())
// .use('/rabbitmq', rabbitmqRoute.routes())
// .use('/zookeeper', zookeeperRoute.routes())
.
use
(
'
/commonService
'
,
commonServiceRoute
.
routes
())
.
use
(
'
/ingress
'
,
ingressRoute
.
routes
())
}
exports
.
start
=
function
()
{
// 加载各种服务
const
app
=
new
Koa
();
const
router
=
new
Router
();
const
app
=
new
Koa
()
const
router
=
new
Router
()
// 加载所有路由
loadRoutes
(
router
)
app
.
use
(
router
.
routes
())
;
app
.
listen
(
4000
)
;
app
.
use
(
router
.
routes
())
app
.
listen
(
4000
)
console
.
log
(
'
app start
'
,
4000
)
}
\ No newline at end of file
}
app/rabbitmq.js
View file @
b49b89f2
...
...
@@ -4,16 +4,15 @@ const templates = require('../serviceTemplate')
const
IMAGES
=
[
'
rabbitmq:3.6-management
'
]
const
router
=
new
Router
()
;
const
router
=
new
Router
()
module
.
exports
=
router
router
.
post
(
'
/create
'
,
async
ctx
=>
{
try
{
let
svc
=
await
ctx
.
client
.
service_get
(
serviceName
,
namespace
)
if
(
svc
)
{
return
ctx
.
body
=
ctx
.
fail
(
'
服务已经存在
'
)
}
}
catch
(
e
)
{}
// let svc = await ctx.client.service_get('rabbitmq', ctx.request.body.namespace)
// if (svc) {
// ctx.body = ctx.fail('服务已经存在')
// return
// }
let
data
=
{
namespace
:
ctx
.
request
.
body
.
namespace
,
...
...
@@ -31,6 +30,6 @@ router.post('/create', async ctx => {
})
router
.
post
(
'
/delete
'
,
async
ctx
=>
{
await
client
.
service_delete
(
'
rabbitmq
'
,
ctx
.
request
.
body
.
namespace
)
await
c
tx
.
c
lient
.
service_delete
(
'
rabbitmq
'
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
删除成功
'
)
})
app/service.js
View file @
b49b89f2
...
...
@@ -4,7 +4,7 @@ const templates = require('../serviceTemplate')
const
TYPES
=
[
'
ui
'
,
'
java
'
,
'
nodejs
'
,
'
python
'
,
'
go
'
]
const
router
=
new
Router
()
;
const
router
=
new
Router
()
module
.
exports
=
router
router
.
get
(
'
/
'
,
async
ctx
=>
{
...
...
@@ -13,7 +13,7 @@ router.get('/', async ctx => {
})
router
.
post
(
'
/create
'
,
async
ctx
=>
{
let
{
type
,
serviceName
,
namespace
,
image
,
system_name
}
=
ctx
.
request
.
body
let
{
type
,
serviceName
,
namespace
,
image
,
system_name
}
=
ctx
.
request
.
body
if
(
!
TYPES
.
includes
(
type
))
{
return
ctx
.
body
=
ctx
.
fail
(
'
不支持的服务类型
'
)
}
...
...
@@ -21,7 +21,7 @@ router.post('/create', async ctx => {
// try {
// let svc = await ctx.client.service_get(serviceName, namespace)
// if (svc) {
// return ctx.body = ctx.fail('服务已经存在')
// return ctx.body = ctx.fail('服务已经存在')
// }
// } catch (e) {
// }
...
...
@@ -56,4 +56,3 @@ router.post('/modifyImage', async ctx => {
await
ctx
.
client
.
service_modifyImage
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
image
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
更新成功
'
)
})
app/zookeeper.js
0 → 100644
View file @
b49b89f2
const
Router
=
require
(
'
koa-router
'
)
const
yaml
=
require
(
'
js-yaml
'
)
const
templates
=
require
(
'
../serviceTemplate
'
)
const
IMAGES
=
[
'
zookeeper:3.4.10
'
]
const
router
=
new
Router
()
module
.
exports
=
router
router
.
post
(
'
/create
'
,
async
ctx
=>
{
let
data
=
{
namespace
:
ctx
.
request
.
body
.
namespace
,
image
:
IMAGES
[
0
]
}
let
template
=
templates
[
'
zookeeper
'
].
replace
(
/{{
([
A-Za-z0-9_
]
+
)
}}/g
,
function
()
{
if
(
data
[
arguments
[
1
]]
===
undefined
)
{
throw
new
Error
(
'
缺少模板所需变量
'
)
}
return
data
[
arguments
[
1
]]
})
let
params
=
yaml
.
load
(
template
)
await
ctx
.
client
.
service_create
(
params
)
ctx
.
body
=
ctx
.
ok
(
'
创建成功
'
)
})
router
.
post
(
'
/delete
'
,
async
ctx
=>
{
await
ctx
.
client
.
service_delete
(
'
zookeeper
'
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
删除成功
'
)
})
serviceTemplate/index.js
View file @
b49b89f2
const
fs
=
require
(
'
fs
'
)
const
ui
=
fs
.
readFileSync
(
'
serviceTemplate/ui.template.txt
'
,
'
utf8
'
)
const
java
=
fs
.
readFileSync
(
'
serviceTemplate/java.template.txt
'
,
'
utf8
'
)
const
nodejs
=
fs
.
readFileSync
(
'
serviceTemplate/nodejs.template.txt
'
,
'
utf8
'
)
const
rabbitmq
=
fs
.
readFileSync
(
'
serviceTemplate/rabbitmq.template.txt
'
,
'
utf8
'
)
const
zookeeper
=
fs
.
readFileSync
(
'
serviceTemplate/zookeeper.template.txt
'
,
'
utf8
'
)
const
mysql
=
fs
.
readFileSync
(
'
serviceTemplate/mysql.template.txt
'
,
'
utf8
'
)
module
.
exports
=
{
ui
,
rabbitmq
}
\ No newline at end of file
nodejs
,
java
,
rabbitmq
,
zookeeper
,
mysql
}
serviceTemplate/java.template.txt
0 → 100644
View file @
b49b89f2
serviceName: {{serviceName}}
namespace: {{namespace}}
replicas: 1
accessType: ClusterIP
portMappings.0.protocol: TCP
portMappings.0.lbPort: 80
portMappings.0.containerPort: 80
containers.0.containerName: {{system_name}}
containers.0.image: {{image}}
containers.0.envs.0.name: SYSTEM_NAME
containers.0.envs.0.value: {{system_name}}
containers.0.envs.1.name: NAMESPACE
containers.0.envs.1.value: {{namespace}}
serviceTemplate/mysql.template.txt
0 → 100644
View file @
b49b89f2
serviceName: mysql
namespace: {{namespace}}
replicas: 1
accessType: LoadBalancer
portMappings.0.protocol: TCP
portMappings.0.lbPort: 3306
portMappings.0.containerPort: 3306
containers.0.containerName: mysql
containers.0.image: {{image}}
containers.0.volumeMounts.0.volumeName: mysql-vol
containers.0.volumeMounts.0.mountPath: /var/lib/mysql
containers.0.volumeMounts.0.mode: rw
containers.0.envs.0.name: MYSQL_USER
containers.0.envs.0.value: qa
containers.0.envs.1.name: MYSQL_PASSWORD
containers.0.envs.1.value: qatest
containers.0.envs.2.name: MYSQL_ROOT_PASSWORD
containers.0.envs.2.value: qatest
volumes.0.name: mysql-vol
volumes.0.volumeType: hostPath
volumes.0.hostPath: /var/lib/data/mysql/{{namespace}}
serviceTemplate/nodejs.template.txt
View file @
b49b89f2
...
...
@@ -13,4 +13,3 @@ containers.0.envs.0.name: SYSTEM_NAME
containers.0.envs.0.value: {{serviceName}}
containers.0.envs.1.name: NAMESPACE
containers.0.envs.1.value: {{namespace}}
\ No newline at end of file
serviceTemplate/rabbitmq.template.txt
View file @
b49b89f2
...
...
@@ -24,4 +24,3 @@ containers.0.envs.1.value: qatest
volumes.0.name: rabbitmq-vol
volumes.0.volumeType: hostPath
volumes.0.hostPath: /var/lib/data/rabbitmq/{{namespace}}
\ No newline at end of file
serviceTemplate/ui.template.txt
View file @
b49b89f2
...
...
@@ -13,4 +13,3 @@ containers.0.envs.0.name: SYSTEM_NAME
containers.0.envs.0.value: {{system_name}}
containers.0.envs.1.name: NAMESPACE
containers.0.envs.1.value: {{namespace}}
\ No newline at end of file
serviceTemplate/zookeeper.template.txt
0 → 100644
View file @
b49b89f2
serviceName: zookeeper
namespace: {{namespace}}
replicas: 1
accessType: ClusterIP
portMappings.0.protocol: TCP
portMappings.0.lbPort: 2181
portMappings.0.containerPort: 2181
portMappings.1.protocol: TCP
portMappings.1.lbPort: 9090
portMappings.1.containerPort: 9090
containers.0.containerName: zookeeper
containers.0.image: {{image}}
containers.0.volumeMounts.0.volumeName: zookeeper-vol
containers.0.volumeMounts.0.mountPath: /var/lib/zookeeper
containers.0.volumeMounts.0.mode: rw
containers.0.envs.0.name: ZOO_USER
containers.0.envs.0.value: zookeeper
containers.0.envs.1.name: ZOO_PORT
containers.0.envs.1.value: 2181
volumes.0.name: zookeeper-vol
volumes.0.volumeType: hostPath
volumes.0.hostPath: /var/lib/data/zookeeper/{{namespace}}
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