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:02:26 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
620d9df47fd4f5bf9b39d02a746b13c9df48867f
620d9df4
1 parent
34b41c51
[Add] Image Build 추가
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletions
backend/controllers/dockerController.js
backend/controllers/dockerController.js
View file @
620d9df
...
...
@@ -4,7 +4,9 @@ const { currentUser } = require('../utils/auth')
const
{
logging
}
=
require
(
'../utils/log'
)
const
{
checkRequiredExist
,
setValues
}
=
require
(
'../utils/validation'
)
const
fs
=
require
(
'fs'
)
const
randomstring
=
require
(
"randomstring"
);
const
randomstring
=
require
(
"randomstring"
)
const
Docker
=
require
(
'dockerode'
)
const
docker
=
new
Docker
({
socketPath
:
'/var/run/docker.sock'
})
const
Op
=
Sequelize
.
Op
...
...
@@ -136,7 +138,42 @@ exports.listImage = async (req, res) => {
}
}
exports
.
buildImage
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
,
'name'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
if
(
required
)
{
logging
(
'image'
,
'error'
,
{
code
:
400
,
message
:
'missingKey:${required}'
},
req
)
return
sendError
(
res
,
400
,
`missingKey:
${
required
}
`
)
}
try
{
const
user
=
await
currentUser
(
req
.
headers
.
authorization
)
const
dockerfileId
=
req
.
body
.
id
const
imageName
=
req
.
body
.
name
let
dockerfile
=
await
Dockerfile
.
findByPk
(
dockerfileId
)
if
(
!
dockerfile
)
{
logging
(
'dockerfile'
,
'error'
,
{
code
:
404
,
message
:
'NoDockerfileFound'
},
req
)
return
sendError
(
res
,
404
,
'NoDockerfileFound'
)
}
if
(
!
user
||
user
.
id
!==
dockerfile
.
userId
)
{
logging
(
'dockerfile'
,
'error'
,
{
code
:
403
,
message
:
'Unauthorized'
},
req
)
return
sendError
(
res
,
403
,
'Unauthorized'
)
}
docker
.
buildImage
({
context
:
dockerfile
.
filepath
,
src
:
[
'Dockerfile'
]
},
{
t
:
imageName
},
function
(
err
,
response
)
{
if
(
!
err
)
{
return
sendResponse
(
res
,
response
,
200
)
}
else
{
return
sendError
(
res
,
500
,
err
.
message
)
}
})
}
catch
(
error
)
{
logging
(
'image'
,
'error'
,
{
code
:
500
,
message
:
error
.
message
},
req
)
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
removeImage
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
]
...
...
Please
register
or
login
to post a comment