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 03:55:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
34b41c5134bf0ee8506bf3363fe64f029244c15a
34b41c51
1 parent
bd5de420
[Add] container list,remove 추가
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
7 deletions
backend/controllers/dockerController.js
backend/controllers/dockerController.js
View file @
34b41c5
...
...
@@ -108,18 +108,26 @@ exports.listImage = async (req, res) => {
return
sendError
(
res
,
401
,
'InvalidToken'
)
}
try
{
let
dockerfiles
=
await
Dockerfile
.
findA
ndCountA
ll
({
let
dockerfiles
=
await
Dockerfile
.
findAll
({
where
:
{
userId
:
id
},
attributes
:
[
'id'
]
})
const
dockerfileIds
=
dockerfiles
.
map
(
dockerfile
=>
dockerfile
.
id
)
let
images
=
await
Image
.
findAndCountAll
({
where
:
{
dockerfileId
:
{
[
Op
.
or
]:
dockerfileIds
}
},
order
:
[
[
'createdAt'
,
'desc'
]
]
})
const
result
=
{
count
:
dockerfil
es
.
count
,
data
:
dockerfil
es
.
rows
count
:
imag
es
.
count
,
data
:
imag
es
.
rows
}
return
sendResponse
(
res
,
result
,
200
)
}
catch
(
error
)
{
...
...
@@ -143,8 +151,8 @@ exports.removeImage = async (req, res) => {
const
imageId
=
req
.
body
.
id
let
image
=
await
Image
.
findByPk
(
imageId
)
if
(
!
image
)
{
logging
(
'image'
,
'error'
,
{
code
:
404
,
message
:
'No
Dockerfil
eFound'
},
req
)
return
sendError
(
res
,
404
,
'No
Dockerfil
eFound'
)
logging
(
'image'
,
'error'
,
{
code
:
404
,
message
:
'No
Imag
eFound'
},
req
)
return
sendError
(
res
,
404
,
'No
Imag
eFound'
)
}
let
dockerfile
=
await
Dockerfile
.
findByPk
(
image
.
dockerfileId
)
if
(
!
user
||
user
.
id
!==
dockerfile
.
userId
)
{
...
...
@@ -166,7 +174,46 @@ exports.removeImage = async (req, res) => {
}
exports
.
listContainer
=
async
(
req
,
res
)
=>
{
const
id
=
req
.
decoded
.
id
if
(
!
id
)
{
return
sendError
(
res
,
401
,
'InvalidToken'
)
}
try
{
let
dockerfiles
=
await
Dockerfile
.
findAll
({
where
:
{
userId
:
id
},
attributes
:
[
'id'
]
})
const
dockerfileIds
=
dockerfiles
.
map
(
dockerfile
=>
dockerfile
.
id
)
let
images
=
await
Image
.
findAll
({
where
:
{
dockerfileId
:
{
[
Op
.
or
]:
dockerfileIds
}
},
attributes
:
[
'id'
]
})
const
imageIds
=
images
.
map
(
image
=>
image
.
id
)
let
containers
=
await
Container
.
findAndCountAll
({
where
:
{
dockerfileId
:
{
[
Op
.
or
]:
imageIds
}
},
order
:
[
[
'createdAt'
,
'desc'
]
]
})
const
result
=
{
count
:
containers
.
count
,
data
:
containers
.
rows
}
return
sendResponse
(
res
,
result
,
200
)
}
catch
(
error
)
{
logging
(
'container'
,
'error'
,
{
code
:
500
,
message
:
error
.
message
},
req
)
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
createContainer
=
async
(
req
,
res
)
=>
{
...
...
@@ -178,7 +225,39 @@ exports.stopContainer = async (req, res) => {
}
exports
.
removeContainer
=
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
user
=
await
currentUser
(
req
.
headers
.
authorization
)
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'
)
}
let
image
=
await
Image
.
findByPk
(
container
.
imageId
)
let
dockerfile
=
await
Dockerfile
.
findByPk
(
image
.
dockerfileId
)
if
(
!
user
||
user
.
id
!==
dockerfile
.
userId
)
{
logging
(
'container'
,
'error'
,
{
code
:
403
,
message
:
'Unauthorized'
},
req
)
return
sendError
(
res
,
403
,
'Unauthorized'
)
}
await
Container
.
destroy
({
where
:
{
id
:
container
.
id
}
})
logging
(
'container'
,
'delete'
,
null
,
req
)
return
sendResponse
(
res
,
true
,
201
)
}
catch
(
error
)
{
logging
(
'container'
,
'error'
,
{
code
:
500
,
message
:
error
.
message
},
req
)
return
sendError
(
res
,
500
,
error
.
message
)
}
}
//admin
...
...
Please
register
or
login
to post a comment