diff --git a/azure/backend.go b/azure/backend.go index 639110d15..1a6e7bdf4 100644 --- a/azure/backend.go +++ b/azure/backend.go @@ -21,6 +21,8 @@ import ( "github.com/docker/api/context/store" ) +const singleContainerName = "single--container--aci" + func init() { backend.Register("aci", "aci", func(ctx context.Context) (backend.Service, error) { return New(ctx) @@ -110,12 +112,18 @@ func (cs *aciContainerService) List(ctx context.Context) ([]containers.Container } for _, container := range *group.Containers { + var containerID string + if *container.Name == singleContainerName { + containerID = *containerGroup.Name + } else { + containerID = *containerGroup.Name + "_" + *container.Name + } status := "Unknown" if container.InstanceView != nil && container.InstanceView.CurrentState != nil { status = *container.InstanceView.CurrentState.State } res = append(res, containers.Container{ - ID: *container.Name, + ID: containerID, Image: *container.Image, Status: status, }) @@ -138,7 +146,7 @@ func (cs *aciContainerService) Run(ctx context.Context, r containers.ContainerCo Config: types.Config{ Services: []types.ServiceConfig{ { - Name: r.ID, + Name: singleContainerName, Image: r.Image, Ports: ports, }, @@ -155,8 +163,21 @@ func (cs *aciContainerService) Run(ctx context.Context, r containers.ContainerCo return createACIContainers(ctx, cs.ctx, groupDefinition) } +func getGrouNameContainername(containerID string) (groupName string, containerName string) { + tokens := strings.Split(containerID, "_") + groupName = tokens[0] + if len(tokens) > 1 { + containerName = tokens[len(tokens)-1] + groupName = containerID[:len(containerID)-(len(containerName)+1)] + } else { + containerName = singleContainerName + } + return groupName, containerName +} + func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error { - containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, name, name) + groupName, containerAciName := getGrouNameContainername(name) + containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, groupName, containerAciName) if err != nil { return err } @@ -171,7 +192,8 @@ func (cs *aciContainerService) Exec(ctx context.Context, name string, command st } func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error { - logs, err := getACIContainerLogs(ctx, cs.ctx, containerName, containerName) + groupName, containerAciName := getGrouNameContainername(containerName) + logs, err := getACIContainerLogs(ctx, cs.ctx, groupName, containerAciName) if err != nil { return err } @@ -204,6 +226,7 @@ func (cs *aciComposeService) Up(ctx context.Context, opts compose.ProjectOptions } logrus.Debugf("Up on project with name %q\n", project.Name) groupDefinition, err := convert.ToContainerGroup(cs.ctx, *project) + if err != nil { return err } diff --git a/azure/backend_test.go b/azure/backend_test.go new file mode 100644 index 000000000..46d7557c7 --- /dev/null +++ b/azure/backend_test.go @@ -0,0 +1,24 @@ +package azure + +import ( + "testing" + + . "github.com/onsi/gomega" +) + +// TestGetContainerName ensures we can read container group name / container name from a containerID +func TestGetContainerName(t *testing.T) { + RegisterTestingT(t) + + group, container := getGrouNameContainername("docker1234") + Expect(group).To(Equal("docker1234")) + Expect(container).To(Equal(singleContainerName)) + + group, container = getGrouNameContainername("compose_service1") + Expect(group).To(Equal("compose")) + Expect(container).To(Equal("service1")) + + group, container = getGrouNameContainername("compose_stack_service1") + Expect(group).To(Equal("compose_stack")) + Expect(container).To(Equal("service1")) +} diff --git a/azure/convert/convert.go b/azure/convert/convert.go index 8759e6aa2..490599e69 100644 --- a/azure/convert/convert.go +++ b/azure/convert/convert.go @@ -12,7 +12,6 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/docker/api/compose" "github.com/docker/api/context/store" - "github.com/sirupsen/logrus" ) const ( @@ -20,7 +19,6 @@ const ( volumeDriveroptsShareNameKey = "share_name" volumeDriveroptsAccountNameKey = "storage_account_name" volumeDriveroptsAccountKeyKey = "storage_account_key" - singleContainerName = "single--container--aci" secretInlineMark = "inline:" ) @@ -56,9 +54,6 @@ func ToContainerGroup(aciContext store.AciContext, p compose.Project) (container for _, s := range project.Services { service := serviceConfigAciHelper(s) - if s.Name != singleContainerName { - logrus.Debugf("Adding %q\n", service.Name) - } containerDefinition, err := service.getAciContainer(volumesCache) if err != nil { return containerinstance.ContainerGroup{}, err diff --git a/tests/aci-e2e/e2e-aci.go b/tests/aci-e2e/e2e-aci.go index 81a6454b0..0f45688e8 100644 --- a/tests/aci-e2e/e2e-aci.go +++ b/tests/aci-e2e/e2e-aci.go @@ -89,7 +89,7 @@ func main() { */ It("deploys a compose app", func() { - NewDockerCommand("compose", "up", "-f", "./composefiles/aci-demo/aci_demo_port.yaml").ExecOrDie() + NewDockerCommand("compose", "up", "-f", "./tests/composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie() //Expect(output).To(ContainSubstring("Successfully deployed")) output := NewDockerCommand("ps").ExecOrDie() Lines := Lines(output) @@ -115,15 +115,13 @@ func main() { */ }) - /* - It("get logs from web service", func() { - output := NewDockerCommand("logs", "aci-demo_web").ExecOrDie() - Expect(output).To(ContainSubstring("Listening on port 80")) - }) - */ + It("get logs from web service", func() { + output := NewDockerCommand("logs", "acidemo_web").ExecOrDie() + Expect(output).To(ContainSubstring("Listening on port 80")) + }) It("shutdown compose app", func() { - NewDockerCommand("compose", "down", "-f", "./composefiles/aci-demo/aci_demo_port.yaml").ExecOrDie() + NewDockerCommand("compose", "down", "-f", "./tests/composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie() }) It("switches back to default context", func() { output := NewCommand("docker", "context", "use", "default").ExecOrDie() diff --git a/composefiles/aci-demo/aci_demo_port.yaml b/tests/composefiles/aci-demo/aci_demo_port.yaml similarity index 100% rename from composefiles/aci-demo/aci_demo_port.yaml rename to tests/composefiles/aci-demo/aci_demo_port.yaml diff --git a/composefiles/aci-demo/aci_demo_port_secrets.yaml b/tests/composefiles/aci-demo/aci_demo_port_secrets.yaml similarity index 100% rename from composefiles/aci-demo/aci_demo_port_secrets.yaml rename to tests/composefiles/aci-demo/aci_demo_port_secrets.yaml diff --git a/composefiles/aci-demo/aci_demo_port_secrets_volumes.yaml b/tests/composefiles/aci-demo/aci_demo_port_secrets_volumes.yaml similarity index 100% rename from composefiles/aci-demo/aci_demo_port_secrets_volumes.yaml rename to tests/composefiles/aci-demo/aci_demo_port_secrets_volumes.yaml diff --git a/composefiles/aci-demo/db/Dockerfile b/tests/composefiles/aci-demo/db/Dockerfile similarity index 100% rename from composefiles/aci-demo/db/Dockerfile rename to tests/composefiles/aci-demo/db/Dockerfile diff --git a/composefiles/aci-demo/db/words.sql b/tests/composefiles/aci-demo/db/words.sql similarity index 100% rename from composefiles/aci-demo/db/words.sql rename to tests/composefiles/aci-demo/db/words.sql diff --git a/composefiles/aci-demo/img/dockercon-barcelona-logo.svg b/tests/composefiles/aci-demo/img/dockercon-barcelona-logo.svg similarity index 100% rename from composefiles/aci-demo/img/dockercon-barcelona-logo.svg rename to tests/composefiles/aci-demo/img/dockercon-barcelona-logo.svg diff --git a/composefiles/aci-demo/img/dockercon_EU_17.jpg b/tests/composefiles/aci-demo/img/dockercon_EU_17.jpg similarity index 100% rename from composefiles/aci-demo/img/dockercon_EU_17.jpg rename to tests/composefiles/aci-demo/img/dockercon_EU_17.jpg diff --git a/composefiles/aci-demo/my_secret1.txt b/tests/composefiles/aci-demo/my_secret1.txt similarity index 100% rename from composefiles/aci-demo/my_secret1.txt rename to tests/composefiles/aci-demo/my_secret1.txt diff --git a/composefiles/aci-demo/my_secret2.txt b/tests/composefiles/aci-demo/my_secret2.txt similarity index 100% rename from composefiles/aci-demo/my_secret2.txt rename to tests/composefiles/aci-demo/my_secret2.txt diff --git a/composefiles/aci-demo/web/Dockerfile b/tests/composefiles/aci-demo/web/Dockerfile similarity index 100% rename from composefiles/aci-demo/web/Dockerfile rename to tests/composefiles/aci-demo/web/Dockerfile diff --git a/composefiles/aci-demo/web/dispatcher.go b/tests/composefiles/aci-demo/web/dispatcher.go similarity index 100% rename from composefiles/aci-demo/web/dispatcher.go rename to tests/composefiles/aci-demo/web/dispatcher.go diff --git a/composefiles/aci-demo/web/static/angular.min.js b/tests/composefiles/aci-demo/web/static/angular.min.js similarity index 100% rename from composefiles/aci-demo/web/static/angular.min.js rename to tests/composefiles/aci-demo/web/static/angular.min.js diff --git a/composefiles/aci-demo/web/static/app.js b/tests/composefiles/aci-demo/web/static/app.js similarity index 100% rename from composefiles/aci-demo/web/static/app.js rename to tests/composefiles/aci-demo/web/static/app.js diff --git a/composefiles/aci-demo/web/static/favicon.ico b/tests/composefiles/aci-demo/web/static/favicon.ico similarity index 100% rename from composefiles/aci-demo/web/static/favicon.ico rename to tests/composefiles/aci-demo/web/static/favicon.ico diff --git a/composefiles/aci-demo/web/static/fonts/font1.woff2 b/tests/composefiles/aci-demo/web/static/fonts/font1.woff2 similarity index 100% rename from composefiles/aci-demo/web/static/fonts/font1.woff2 rename to tests/composefiles/aci-demo/web/static/fonts/font1.woff2 diff --git a/composefiles/aci-demo/web/static/fonts/font2.woff2 b/tests/composefiles/aci-demo/web/static/fonts/font2.woff2 similarity index 100% rename from composefiles/aci-demo/web/static/fonts/font2.woff2 rename to tests/composefiles/aci-demo/web/static/fonts/font2.woff2 diff --git a/composefiles/aci-demo/web/static/images/dockercon-log.png b/tests/composefiles/aci-demo/web/static/images/dockercon-log.png similarity index 100% rename from composefiles/aci-demo/web/static/images/dockercon-log.png rename to tests/composefiles/aci-demo/web/static/images/dockercon-log.png diff --git a/composefiles/aci-demo/web/static/images/homes.png b/tests/composefiles/aci-demo/web/static/images/homes.png similarity index 100% rename from composefiles/aci-demo/web/static/images/homes.png rename to tests/composefiles/aci-demo/web/static/images/homes.png diff --git a/composefiles/aci-demo/web/static/images/lego_blue.png b/tests/composefiles/aci-demo/web/static/images/lego_blue.png similarity index 100% rename from composefiles/aci-demo/web/static/images/lego_blue.png rename to tests/composefiles/aci-demo/web/static/images/lego_blue.png diff --git a/composefiles/aci-demo/web/static/images/lego_light_blue.png b/tests/composefiles/aci-demo/web/static/images/lego_light_blue.png similarity index 100% rename from composefiles/aci-demo/web/static/images/lego_light_blue.png rename to tests/composefiles/aci-demo/web/static/images/lego_light_blue.png diff --git a/composefiles/aci-demo/web/static/images/lego_yellow.png b/tests/composefiles/aci-demo/web/static/images/lego_yellow.png similarity index 100% rename from composefiles/aci-demo/web/static/images/lego_yellow.png rename to tests/composefiles/aci-demo/web/static/images/lego_yellow.png diff --git a/composefiles/aci-demo/web/static/images/logo.svg b/tests/composefiles/aci-demo/web/static/images/logo.svg similarity index 100% rename from composefiles/aci-demo/web/static/images/logo.svg rename to tests/composefiles/aci-demo/web/static/images/logo.svg diff --git a/composefiles/aci-demo/web/static/index.html b/tests/composefiles/aci-demo/web/static/index.html similarity index 100% rename from composefiles/aci-demo/web/static/index.html rename to tests/composefiles/aci-demo/web/static/index.html diff --git a/composefiles/aci-demo/web/static/style.css b/tests/composefiles/aci-demo/web/static/style.css similarity index 100% rename from composefiles/aci-demo/web/static/style.css rename to tests/composefiles/aci-demo/web/static/style.css diff --git a/composefiles/aci-demo/words/.dockerignore b/tests/composefiles/aci-demo/words/.dockerignore similarity index 100% rename from composefiles/aci-demo/words/.dockerignore rename to tests/composefiles/aci-demo/words/.dockerignore diff --git a/composefiles/aci-demo/words/Dockerfile b/tests/composefiles/aci-demo/words/Dockerfile similarity index 100% rename from composefiles/aci-demo/words/Dockerfile rename to tests/composefiles/aci-demo/words/Dockerfile diff --git a/composefiles/aci-demo/words/pom.xml b/tests/composefiles/aci-demo/words/pom.xml similarity index 100% rename from composefiles/aci-demo/words/pom.xml rename to tests/composefiles/aci-demo/words/pom.xml diff --git a/composefiles/aci-demo/words/src/main/java/Main.java b/tests/composefiles/aci-demo/words/src/main/java/Main.java similarity index 100% rename from composefiles/aci-demo/words/src/main/java/Main.java rename to tests/composefiles/aci-demo/words/src/main/java/Main.java diff --git a/composefiles/nginx.yaml b/tests/composefiles/nginx.yaml similarity index 100% rename from composefiles/nginx.yaml rename to tests/composefiles/nginx.yaml