From 5effbdc31f91b15eac489d453c9a568cdeaa8d2f Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Mon, 18 May 2020 11:00:09 +0200 Subject: [PATCH] Add ACI public ip --- azure/backend.go | 3 ++- azure/convert/ports.go | 17 ++++++++++++-- tests/aci-e2e/e2e-aci.go | 49 ++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/azure/backend.go b/azure/backend.go index 3db2cf568..cf3467ea1 100644 --- a/azure/backend.go +++ b/azure/backend.go @@ -133,11 +133,12 @@ func (cs *aciContainerService) List(ctx context.Context) ([]containers.Container if container.InstanceView != nil && container.InstanceView.CurrentState != nil { status = *container.InstanceView.CurrentState.State } + res = append(res, containers.Container{ ID: containerID, Image: *container.Image, Status: status, - Ports: convert.ToPorts(*container.Ports), + Ports: convert.ToPorts(group.IPAddress, *container.Ports), }) } } diff --git a/azure/convert/ports.go b/azure/convert/ports.go index e52aef737..bf63609c5 100644 --- a/azure/convert/ports.go +++ b/azure/convert/ports.go @@ -1,22 +1,35 @@ package convert import ( + "strings" + "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" "github.com/docker/api/containers" ) // ToPorts converts Azure container ports to api ports -func ToPorts(ports []containerinstance.ContainerPort) []containers.Port { +func ToPorts(ipAddr *containerinstance.IPAddress, ports []containerinstance.ContainerPort) []containers.Port { var result []containers.Port for _, port := range ports { if port.Port == nil { continue } + protocol := "tcp" + if port.Protocol != "" { + protocol = string(port.Protocol) + } + ip := "" + if ipAddr != nil { + ip = *ipAddr.IP + } + result = append(result, containers.Port{ + HostPort: uint32(*port.Port), ContainerPort: uint32(*port.Port), - Protocol: "tcp", + HostIP: ip, + Protocol: strings.ToLower(protocol), }) } diff --git a/tests/aci-e2e/e2e-aci.go b/tests/aci-e2e/e2e-aci.go index dfd146892..adce292a5 100644 --- a/tests/aci-e2e/e2e-aci.go +++ b/tests/aci-e2e/e2e-aci.go @@ -3,6 +3,7 @@ package main import ( "context" "log" + "strings" "github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources" "github.com/Azure/go-autorest/autorest/to" @@ -66,8 +67,7 @@ func main() { Expect(len(Lines(output))).To(Equal(1)) }) - var nginxID string - It("runs nginx on port 80 (PORT NOT CHECKED YET!!! REMOVE THAT WHEN IMPLEMENTED)", func() { + It("runs nginx on port 80", func() { output := NewDockerCommand("run", "nginx", "-p", "80:80", "--name", testContainerName).ExecOrDie() Expect(output).To(Equal(testContainerName + "\n")) output = NewDockerCommand("ps").ExecOrDie() @@ -75,20 +75,19 @@ func main() { Expect(len(lines)).To(Equal(2)) containerFields := Columns(lines[1]) - nginxID = containerFields[0] Expect(containerFields[1]).To(Equal("nginx")) Expect(containerFields[2]).To(Equal("Running")) - // exposedIP := containerFields[3] - // Expect(exposedIP).To(ContainSubstring(":80->80/TCP")) + exposedIP := containerFields[3] + Expect(exposedIP).To(ContainSubstring(":80->80/tcp")) - // url := strings.ReplaceAll(exposedIP, "->80/TCP", "") - // output = NewCommand("curl", url).ExecOrDie() - // Expect(output).To(ContainSubstring("Welcome to nginx!")) + url := strings.ReplaceAll(exposedIP, "->80/tcp", "") + output = NewCommand("curl", url).ExecOrDie() + Expect(output).To(ContainSubstring("Welcome to nginx!")) }) It("removes container nginx", func() { - output := NewDockerCommand("rm", nginxID).ExecOrDie() - Expect(Lines(output)[0]).To(Equal(nginxID)) + output := NewDockerCommand("rm", testContainerName).ExecOrDie() + Expect(Lines(output)[0]).To(Equal(testContainerName)) }) It("deploys a compose app", func() { @@ -97,25 +96,25 @@ func main() { output := NewDockerCommand("ps").ExecOrDie() Lines := Lines(output) Expect(len(Lines)).To(Equal(4)) + webChecked := false + for _, line := range Lines[1:] { Expect(line).To(ContainSubstring("Running")) - } - /* - if strings.Contains(line, "acicompose_web") { - webChecked = true - containerFields := Columns(line) - exposedIP := containerFields[3] - Expect(exposedIP).To(ContainSubstring(":80->80/TCP")) + if strings.Contains(line, "acidemo_web") { + webChecked = true + containerFields := Columns(line) + exposedIP := containerFields[3] + Expect(exposedIP).To(ContainSubstring(":80->80/tcp")) - url := strings.ReplaceAll(exposedIP, "->80/TCP", "") - output = NewCommand("curl", url).ExecOrDie() - Expect(output).To(ContainSubstring("Docker Compose demo")) - output = NewCommand("curl", url+"/words/noun").ExecOrDie() - Expect(output).To(ContainSubstring("\"word\":")) - } + url := strings.ReplaceAll(exposedIP, "->80/tcp", "") + output = NewCommand("curl", url).ExecOrDie() + Expect(output).To(ContainSubstring("Docker Compose demo")) + output = NewCommand("curl", url+"/words/noun").ExecOrDie() + Expect(output).To(ContainSubstring("\"word\":")) } - Expect(webChecked).To(BeTrue()) - */ + } + + Expect(webChecked).To(BeTrue()) }) It("get logs from web service", func() {