Skip to content

Commit 21f98cd

Browse files
authored
Merge pull request #26 from arangodb-helper/up-info
Show user friendly address to reach the coordinator
2 parents 5f97368 + 033bb17 commit 21f98cd

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

service/arangodb.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,28 @@ func (s *Service) startRunning(runner Runner) {
430430
*processVar = p
431431
ctx, cancel := context.WithCancel(s.ctx)
432432
go func() {
433-
if up, cancelled := s.testInstance(ctx, myHost, s.MasterPort+portOffset+serverPortOffset); !cancelled {
433+
port := s.MasterPort + portOffset + serverPortOffset
434+
if up, cancelled := s.testInstance(ctx, myHost, port); !cancelled {
434435
if up {
435436
s.log.Infof("%s up and running.", mode)
437+
if mode == "coordinator" {
438+
hostPort, err := p.HostPort(port)
439+
if err != nil {
440+
if id := p.ContainerID(); id != "" {
441+
s.log.Infof("%s can only be accessed from inside a container.", mode)
442+
}
443+
} else {
444+
scheme := "http"
445+
arangoshScheme := "tcp"
446+
if myPeer.IsSecure {
447+
scheme = "https"
448+
arangoshScheme = "ssl"
449+
}
450+
ip := myPeer.Address
451+
s.log.Infof("Your cluster can now be accessed with a browser at `%s://%s:%d` or", scheme, ip, hostPort)
452+
s.log.Infof("using `arangosh --server.endpoint %s://%s:%d`.", arangoshScheme, ip, hostPort)
453+
}
454+
}
436455
} else {
437456
s.log.Warningf("%s not ready after 5min!", mode)
438457
}

service/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type Process interface {
3232
ContainerID() string
3333
// ContainerIP returns the IP address of the docker container that runs the process.
3434
ContainerIP() string
35+
// HostPort returns the port on the host that is used to access the given port of the process.
36+
HostPort(containerPort int) (int, error)
3537

3638
// Wait until the process has terminated
3739
Wait()

service/runner_docker.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ func (p *dockerContainer) ContainerIP() string {
370370
return ""
371371
}
372372

373+
// HostPort returns the port on the host that is used to access the given port of the process.
374+
func (p *dockerContainer) HostPort(containerPort int) (int, error) {
375+
if hostConfig := p.container.HostConfig; hostConfig != nil {
376+
if hostConfig.NetworkMode == "host" {
377+
return containerPort, nil
378+
}
379+
dockerPort := docker.Port(fmt.Sprintf("%d/tcp", containerPort))
380+
if binding, ok := hostConfig.PortBindings[dockerPort]; ok && len(binding) > 0 {
381+
return strconv.Atoi(binding[0].HostPort)
382+
}
383+
}
384+
return 0, fmt.Errorf("Cannot find port mapping.")
385+
}
386+
373387
func (p *dockerContainer) Wait() {
374388
p.client.WaitContainer(p.container.ID)
375389
}

service/runner_process.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func (p *process) ContainerIP() string {
111111
return ""
112112
}
113113

114+
// HostPort returns the port on the host that is used to access the given port of the process.
115+
func (p *process) HostPort(containerPort int) (int, error) {
116+
return containerPort, nil
117+
}
118+
114119
func (p *process) Wait() {
115120
if proc := p.p; proc != nil {
116121
p.log.Debugf("Waiting on %d", proc.Pid)

0 commit comments

Comments
 (0)