-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
64 lines (39 loc) · 1.3 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as express from 'express'
import * as bodyParser from 'body-parser'
import { execDocker } from './exec-docker'
const app = express()
app.use( bodyParser.urlencoded({ extended: true }) );
app.use( bodyParser.json() );
const port = 8080
const router = express.Router()
router.route( '/services' )
.get( ( req, res ) => {
res.sendStatus( 501 );
} )
.post( ( req, res ) => {
const portParam = req.body.servicePort
const options = portParam ? `-p ${ portParam }` : ''
const exec = execDocker( `service create`, req.body.imageName, options )
const output = {
exec: exec,
serviceId: exec.stdout
} as any
if ( portParam ) {
output.port = execDocker(
'service inspect',
output.serviceId,
`--format="'{{(index .Endpoint.Ports 0).PublishedPort}}'"`
).stdout
}
res.json( output )
})
router.route( '/services/:serviceId' )
.get( ( req, res ) => {
res.json( execDocker( 'service inspect', req.params.serviceId ) )
} )
.delete( ( req, res ) => {
res.json( execDocker( 'service rm', req.params.serviceId ) )
} )
app.use( '/', router )
app.listen( port )
console.log( `Check port ${ port }` )