Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #317 from vania-pooh/master
Browse files Browse the repository at this point in the history
Showing Docker container IP address in /status (fixes #316)
  • Loading branch information
vania-pooh authored Dec 22, 2017
2 parents f225387 + a99de16 commit ad8a78c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"time"
)

// Session - session id and vnc flaf
// Session - session id and vnc flag
type Session struct {
ID string `json:"id"`
Container string `json:"container,omitempty"`
VNC bool `json:"vnc"`
Screen string `json:"screen"`
Caps session.Caps `json:"caps"`
ID string `json:"id"`
Container *session.Container `json:"container,omitempty"`
VNC bool `json:"vnc"`
Screen string `json:"screen"`
Caps session.Caps `json:"caps"`
}

// Sessions - used count and individual sessions for quota user
Expand Down
6 changes: 3 additions & 3 deletions selenoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func create(w http.ResponseWriter, r *http.Request) {
Quota: quota,
Caps: browser.Caps,
URL: u,
Container: startedService.ID,
Container: startedService.Container,
VNC: startedService.VNCHostPort,
Cancel: cancelAndRenameVideo,
Timeout: onTimeout(timeout, func() {
Expand Down Expand Up @@ -471,9 +471,9 @@ func logs(wsconn *websocket.Conn) {
defer wsconn.Close()
sid := strings.Split(wsconn.Request().URL.Path, "/")[2]
sess, ok := sessions.Get(sid)
if ok && sess.Container != "" {
if ok && sess.Container != nil {
log.Printf("[CONTAINER_LOGS] [%s]\n", sess.Container)
r, err := cli.ContainerLogs(wsconn.Request().Context(), sess.Container, types.ContainerLogsOptions{
r, err := cli.ContainerLogs(wsconn.Request().Context(), sess.Container.ID, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
Expand Down
7 changes: 5 additions & 2 deletions service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ func (d *Docker) StartWithCancel() (*StartedService, error) {
log.Printf("[%d] [SERVICE_STARTED] [%s] [%s] [%v]\n", requestId, image, browserContainerId, time.Since(serviceStartTime))
log.Printf("[%d] [PROXY_TO] [%s] [%s] [%s]\n", requestId, image, browserContainerId, u.String())
s := StartedService{
Url: u,
ID: browserContainerId,
Url: u,
Container: &session.Container{
ID: browserContainerId,
IPAddress: getContainerIP(d.Environment.Network, stat),
},
VNCHostPort: vncHostPort,
Cancel: func() {
if videoContainerId != "" {
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ServiceBase struct {
// StartedService - all started service properties
type StartedService struct {
Url *url.URL
ID string
Container *session.Container
VNCHostPort string
Cancel func()
}
Expand Down
3 changes: 2 additions & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ func testDocker(t *testing.T, env *service.Environment, cfg *config.Config) {
startedService, err := starter.StartWithCancel()
AssertThat(t, err, Is{nil})
AssertThat(t, startedService.Url, Not{nil})
AssertThat(t, startedService.ID, EqualTo{"e90e34656806"})
AssertThat(t, startedService.Container, Not{nil})
AssertThat(t, startedService.Container.ID, EqualTo{"e90e34656806"})
AssertThat(t, startedService.VNCHostPort, EqualTo{"127.0.0.1:5900"})
AssertThat(t, startedService.Cancel, Not{nil})
startedService.Cancel()
Expand Down
8 changes: 7 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ type Caps struct {
HostsEntries string `json:"hostsEntries"`
}

// Container - container information
type Container struct {
ID string `json:"id"`
IPAddress string `json:"ip"`
}

// Session - holds session info
type Session struct {
Quota string
Caps Caps
URL *url.URL
Container string
Container *Container
VNC string
Cancel func()
Timeout chan struct{}
Expand Down

0 comments on commit ad8a78c

Please sign in to comment.