Skip to content

Commit

Permalink
remove the need to bind host port
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Oct 18, 2022
1 parent 84f9f60 commit c90d0dd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions integration/hsic/hsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/integration/dockertestutil"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
)

const hsicHashLength = 6
Expand Down Expand Up @@ -46,7 +45,6 @@ func New(

hostname := fmt.Sprintf("hs-%s", hash)
portProto := fmt.Sprintf("%d/tcp", port)
dockerPort := docker.Port(portProto)

currentPath, err := os.Getwd()
if err != nil {
Expand All @@ -64,9 +62,6 @@ func New(
},
ExposedPorts: []string{portProto},
// TODO(kradalby): WHY do we need to bind these now that we run fully in docker?
PortBindings: map[docker.Port][]docker.PortBinding{
dockerPort: {{HostPort: fmt.Sprintf("%d", port)}},
},
Networks: []*dockertest.Network{network},
Cmd: []string{"headscale", "serve"},
}
Expand Down Expand Up @@ -116,24 +111,26 @@ func (t *HeadscaleInContainer) GetPort() string {
}

func (t *HeadscaleInContainer) GetHealthEndpoint() string {
hostEndpoint := fmt.Sprintf("%s:%s",
hostEndpoint := fmt.Sprintf("%s:%d",
t.GetIP(),
t.GetPort())
t.port)

return fmt.Sprintf("http://%s/health", hostEndpoint)
}

func (t *HeadscaleInContainer) GetEndpoint() string {
hostEndpoint := fmt.Sprintf("%s:%s",
hostEndpoint := fmt.Sprintf("%s:%d",
t.GetIP(),
t.GetPort())
t.port)

return fmt.Sprintf("http://%s", hostEndpoint)
}

func (t *HeadscaleInContainer) WaitForReady() error {
url := t.GetHealthEndpoint()

log.Printf("waiting for headscale to be ready at %s", url)

return t.pool.Retry(func() error {
resp, err := http.Get(url)
if err != nil {
Expand Down

0 comments on commit c90d0dd

Please sign in to comment.