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
ch4n3.yoon
2021-05-04 17:08:22 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
17d14bd0457e0461c80aeb2ce47d62fba268bf6d
17d14bd0
1 parent
11e3c3c8
[New] Docker Container Create 화면 구현
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
229 additions
and
2 deletions
frontend/src/App.js
frontend/src/components/DockerContainerCreate.js
frontend/src/components/Index.js
frontend/src/utils/http.js
frontend/src/App.js
View file @
17d14bd
import
React
,
{
useEffect
}
from
'react'
import
{
BrowserRouter
,
Route
,
Redirect
,
Switch
,
Link
}
from
'react-router-dom'
import
{
ChakraProvider
}
from
"@chakra-ui/react"
import
{
ChakraProvider
}
from
'@chakra-ui/react'
import
Index
from
'./components/Index'
import
DockerContainerCreate
from
'./components/DockerContainerCreate'
const
App
=
()
=>
{
return
(
...
...
@@ -9,6 +10,7 @@ const App = () => {
<
BrowserRouter
>
<
Switch
>
<
Route
exact
path
=
"/"
component
=
{
Index
}
/
>
<
Route
exact
path
=
"/docker/container/create"
component
=
{
DockerContainerCreate
}
/
>
<
Redirect
path
=
"*"
to
=
"/"
/>
<
/Switch
>
<
/BrowserRouter
>
...
...
frontend/src/components/DockerContainerCreate.js
0 → 100644
View file @
17d14bd
import
React
,
{
useState
,
useEffect
}
from
'react'
import
{
useHistory
,
Redirect
}
from
'react-router-dom'
import
{
Container
,
Heading
,
Button
,
Segment
,
Message
,
Divider
,
Form
,
Input
,
Transition
,
Select
,
Checkbox
,
FormControl
,
FormLabel
,
FormErrorMessage
,
FormHelperText
,
}
from
'@chakra-ui/react'
import
http
from
'../utils/http'
const
DockerContainerCreate
=
()
=>
{
const
[
images
,
setImages
]
=
useState
([])
const
[
image
,
setImage
]
=
useState
(
''
)
const
[
containerName
,
setContainerName
]
=
useState
(
''
)
const
[
ssh
,
setSsh
]
=
useState
(
''
)
const
[
port
,
setPort
]
=
useState
(
0
)
const
[
randomPort
,
setRandomPort
]
=
useState
(
false
)
const
[
isSuccess
,
setSuccess
]
=
useState
(
false
)
const
[
isLoading
,
setLoading
]
=
useState
(
false
)
const
[
error
,
setError
]
=
useState
(
''
)
const
history
=
useHistory
()
const
loadImages
=
()
=>
{
setLoading
(
true
)
http
.
get
(
'/docker/image/list'
).
then
(
response
=>
{
const
{
status
,
message
}
=
response
.
data
const
images
=
response
.
data
.
data
setLoading
(
false
)
if
(
status
)
{
setImages
(
images
)
}
else
{
setError
(
message
)
console
.
log
(
'[ ERROR ]'
,
message
)
}
}).
catch
(
error
=>
{
console
.
error
(
error
)
})
}
const
getImageDropdownOptions
=
()
=>
{
const
defaultImage
=
{
key
:
999
,
value
:
'default'
,
text
:
'default image'
,
}
return
[
defaultImage
].
concat
(
images
.
map
((
image
,
key
)
=>
{
return
{
key
:
key
,
value
:
image
.
Id
,
text
:
image
.
RepoTags
.
length
>
0
?
image
.
RepoTags
[
0
]
:
' - '
,
}
}))
}
const
createContainer
=
()
=>
{
setLoading
(
true
)
setError
(
''
)
console
.
log
(
'[ DEBUG ] image :'
,
image
)
http
.
post
(
'/docker/container/create'
,
{
name
:
containerName
,
image
:
image
,
port
:
port
,
random_port
:
randomPort
,
}).
then
(
response
=>
{
const
{
status
,
message
}
=
response
.
data
const
{
username
,
password
,
port
}
=
response
.
data
.
data
setLoading
(
false
)
if
(
!
status
)
{
setError
(
message
)
}
else
{
setSuccess
(
true
)
setSsh
(
`ssh
${
username
}
@
${
window
.
location
.
hostname
}
-p
${
port
}
# (password :
${
password
}
)`
)
}
// setTimeout(() => setSuccess(false), 10000);
}).
catch
(
error
=>
{
console
.
error
(
'[ ERROR ]'
,
error
)
})
}
const
handleImage
=
(
e
,
data
)
=>
{
setImage
(
data
.
value
)
}
const
handleContainerName
=
(
e
)
=>
{
setContainerName
(
e
.
target
.
value
)
}
const
handlePort
=
(
e
)
=>
{
setPort
(
e
.
target
.
value
)
}
const
handleRandomPort
=
()
=>
{
setRandomPort
(
!
randomPort
)
}
useEffect
(()
=>
{
loadImages
()
},
[])
return
(
<
Container
>
<
Divider
hidden
/>
<
Segment
raised
>
<
Heading
size
=
'huge'
>
Create
your
own
docker
container
<
/Heading>
<
Divider
hidden
/>
<
FormControl
id
=
"container"
>
<
FormLabel
>
Container
Name
<
/FormLabel>
<
Input
type
=
"email"
placeholder
=
'Container Name'
/>
<
FormHelperText
>
컨테이너
이름을
입력해주세요
.
<
/FormHelperText>
<
/FormControl>
<
div
>
<
Input
label
=
'Container Name'
placeholder
=
'Container Name'
onChange
=
{
handleContainerName
}
/>
<
Select
label
=
'Image'
>
<
option
value
=
"option1"
>
Option
1
<
/option>
<
option
value
=
"option2"
>
Option
2
<
/option>
<
option
value
=
"option3"
>
Option
3
<
/option>
<
/Select>
{
/*<Form.Group>
<Form.Dropdown
label='Image'
selection
options={getImageDropdownOptions()}
defaultValue={getImageDropdownOptions()[0]}
onChange={handleImage}
/>
</Form.Group>*/
}
<
Input
type
=
'number'
label
=
'SSH Port'
placeholder
=
'22'
disabled
=
{
randomPort
}
onChange
=
{
handlePort
}
/>
{
/*<Form.Group>
<Form.Input
type='number'
label='SSH Port'
placeholder='22'
disabled={randomPort}
onChange={handlePort}
/>
</Form.Group>*/
}
<
Checkbox
label
=
'Use random port'
checked
=
{
randomPort
}
onChange
=
{
handleRandomPort
}
/>
<
Button
color
=
'violet'
onClick
=
{
createContainer
}
content
=
'Create'
/>
<
Button
content
=
'Container List'
onClick
=
{()
=>
history
.
push
(
'/docker/container/'
)}
/>
<
/div>
{
/*
<Transition.Group
duration={300}
>
{isSuccess && (
<>
<Divider/>
<Message
success
content={ssh}
/>
</>
)}
{error && (
<>
<Divider/>
<Message
error
content={error}
/>
</>
)}
</Transition.Group>*/
}
<
/Segment>
<
/Container>
)
}
export
default
DockerContainerCreate
frontend/src/components/Index.js
View file @
17d14bd
import
React
,
{
useEffect
}
from
'react'
import
{
BrowserRouter
,
Route
,
Redirect
,
Switch
,
Link
}
from
'react-router-dom'
import
{
Container
}
from
"@chakra-ui/react"
import
{
Container
}
from
'@chakra-ui/react'
const
Index
=
()
=>
{
...
...
frontend/src/utils/http.js
0 → 100644
View file @
17d14bd
import
axios
from
'axios'
const
http
=
axios
.
create
({
baseURL
:
'http://192.168.241.128:3030/'
,
withCredentials
:
true
,
})
export
default
http
Please
register
or
login
to post a comment