Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정민우
/
vps_service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
정민우
2021-06-11 04:14:10 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
23c3870085d98b9de5910c187168dacae3d618ec
23c38700
1 parent
620d9df4
[Add] Container start/stop 추가
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
2 deletions
backend/controllers/dockerController.js
backend/controllers/dockerController.js
View file @
23c3870
...
...
@@ -137,6 +137,7 @@ exports.listImage = async (req, res) => {
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
buildImage
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
,
'name'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
...
...
@@ -175,6 +176,7 @@ exports.buildImage = async (req, res) => {
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
removeImage
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
...
...
@@ -252,15 +254,67 @@ exports.listContainer = async (req, res) => {
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
createContainer
=
async
(
req
,
res
)
=>
{
}
exports
.
startContainer
=
async
(
req
,
res
)
=>
{
exports
.
startContainer
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
if
(
required
)
{
logging
(
'container'
,
'error'
,
{
code
:
400
,
message
:
'missingKey:${required}'
},
req
)
return
sendError
(
res
,
400
,
`missingKey:
${
required
}
`
)
}
try
{
const
containerId
=
req
.
body
.
id
let
container
=
await
Image
.
findByPk
(
containerId
)
if
(
!
container
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoContainerFound'
},
req
)
return
sendError
(
res
,
404
,
'NoContainerFound'
)
}
docker
.
listContainers
(
function
(
err
,
containers
)
{
containers
.
forEach
(
function
(
containerInfo
)
{
if
(
containerInfo
.
names
===
container
.
name
)
{
docker
.
getContainer
(
containerInfo
.
Id
).
start
(
cb
)
return
sendResponse
(
res
,
containerInfo
,
200
)
}
})
})
}
catch
(
error
)
{
logging
(
'container'
,
'error'
,
{
code
:
500
,
message
:
error
.
message
},
req
)
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
stopContainer
=
async
(
req
,
res
)
=>
{
exports
.
stopContainer
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
if
(
required
)
{
logging
(
'container'
,
'error'
,
{
code
:
400
,
message
:
'missingKey:${required}'
},
req
)
return
sendError
(
res
,
400
,
`missingKey:
${
required
}
`
)
}
try
{
const
containerId
=
req
.
body
.
id
let
container
=
await
Image
.
findByPk
(
containerId
)
if
(
!
container
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoContainerFound'
},
req
)
return
sendError
(
res
,
404
,
'NoContainerFound'
)
}
docker
.
listContainers
(
function
(
err
,
containers
)
{
containers
.
forEach
(
function
(
containerInfo
)
{
if
(
containerInfo
.
names
===
container
.
name
)
{
docker
.
getContainer
(
containerInfo
.
Id
).
stop
(
cb
)
return
sendResponse
(
res
,
containerInfo
,
200
)
}
})
})
}
catch
(
error
)
{
logging
(
'container'
,
'error'
,
{
code
:
500
,
message
:
error
.
message
},
req
)
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
removeContainer
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
...
...
Please
register
or
login
to post a comment