diff --git a/config/config.go b/config/config.go index bf93d78f..c526551b 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/selenoid.go b/selenoid.go index 9aefdb72..62307c1b 100644 --- a/selenoid.go +++ b/selenoid.go @@ -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() { @@ -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, diff --git a/service/docker.go b/service/docker.go index bddd837d..b65c5a19 100644 --- a/service/docker.go +++ b/service/docker.go @@ -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 != "" { diff --git a/service/service.go b/service/service.go index 2edf382d..3d244a75 100644 --- a/service/service.go +++ b/service/service.go @@ -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() } diff --git a/service_test.go b/service_test.go index 1475ce7b..e8623813 100644 --- a/service_test.go +++ b/service_test.go @@ -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() diff --git a/session/session.go b/session/session.go index ba20dc2f..5f2c727d 100644 --- a/session/session.go +++ b/session/session.go @@ -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{}