diff --git a/Dockerfile.dind b/Dockerfile.dind index ccc1f0a..3ed7bc2 100644 --- a/Dockerfile.dind +++ b/Dockerfile.dind @@ -2,10 +2,11 @@ FROM docker:17.04.0-ce-dind RUN apk add --no-cache git tmux py2-pip apache2-utils vim build-base gettext-dev curl bash-completion bash util-linux jq -ENV COMPOSE_VERSION=1.11.1 +ENV COMPOSE_VERSION=1.12.0 +ENV MACHINE_VERSION=v0.10.0 # Install Compose and Machine RUN pip install docker-compose==${COMPOSE_VERSION} -RUN curl -L https://github.com/docker/machine/releases/download/v0.9.0-rc1/docker-machine-Linux-x86_64 \ +RUN curl -L https://github.com/docker/machine/releases/download/${MACHINE_VERSION}/docker-machine-Linux-x86_64 \ -o /usr/bin/docker-machine && chmod +x /usr/bin/docker-machine # Compile and install httping diff --git a/services/docker.go b/services/docker.go index 82edc19..331c5ce 100644 --- a/services/docker.go +++ b/services/docker.go @@ -5,7 +5,6 @@ import ( "io" "log" "os" - "sort" "strconv" "strings" @@ -101,7 +100,7 @@ func SetInstanceSwarmPorts(i *Instance) error { return nil } -func GetUsedPorts(i *Instance) ([]int, error) { +func GetUsedPorts(i *Instance) ([]uint16, error) { if i.dockerClient == nil { return nil, fmt.Errorf("Docker client for DinD (%s) is not ready", i.IP) } @@ -111,16 +110,15 @@ func GetUsedPorts(i *Instance) ([]int, error) { return nil, err } - openPorts := sort.IntSlice{} + openPorts := []uint16{} for _, c := range containers { for _, p := range c.Ports { // When port is not published on the host docker return public port as 0, so we need to avoid it if p.PublicPort != 0 { - openPorts = append(openPorts, int(p.PublicPort)) + openPorts = append(openPorts, p.PublicPort) } } } - sort.Sort(openPorts) return openPorts, nil } diff --git a/services/instance.go b/services/instance.go index e83c43f..ac2bcdb 100644 --- a/services/instance.go +++ b/services/instance.go @@ -17,6 +17,12 @@ import ( var rw sync.Mutex +type UInt16Slice []uint16 + +func (p UInt16Slice) Len() int { return len(p) } +func (p UInt16Slice) Less(i, j int) bool { return p[i] < p[j] } +func (p UInt16Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + type Instance struct { session *Session `json:"-"` Name string `json:"name"` @@ -28,11 +34,11 @@ type Instance struct { IsManager *bool `json:"is_manager"` Mem string `json:"mem"` Cpu string `json:"cpu"` - Ports []uint16 `json:"ports"` - tempPorts []uint16 `json:"-"` - ServerCert []byte `json:"server_cert"` - ServerKey []byte `json:"server_key"` - cert *tls.Certificate `json:"-"` + Ports UInt16Slice + tempPorts []uint16 `json:"-"` + ServerCert []byte `json:"server_cert"` + ServerKey []byte `json:"server_key"` + cert *tls.Certificate `json:"-"` } func (i *Instance) setUsedPort(port uint16) { diff --git a/services/instance_images.go b/services/instance_images.go index 9d6c04d..4738803 100644 --- a/services/instance_images.go +++ b/services/instance_images.go @@ -5,6 +5,7 @@ func InstanceImages() []string { return []string{ dindImage, "franela/dind:overlay2-dev", + "franela/dind:overlay2-ucp", } } diff --git a/services/session.go b/services/session.go index b1f11c1..4c975df 100644 --- a/services/session.go +++ b/services/session.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "os" + "sort" "strings" "sync" "time" @@ -131,8 +132,10 @@ func (s *Session) SchedulePeriodicTasks() { wg.Wait() // broadcast all information for _, ins := range s.Instances { - ins.Ports = ins.tempPorts + ins.Ports = UInt16Slice(ins.tempPorts) + sort.Sort(ins.Ports) ins.tempPorts = []uint16{} + wsServer.BroadcastTo(ins.session.Id, "instance stats", ins.Name, ins.Mem, ins.Cpu, ins.IsManager, ins.Ports) } }