mirror of https://github.com/docker/compose.git
Merge pull request #468 from docker/aci_ps_all
Implement `docker ps —all` filter on ACI
This commit is contained in:
commit
e93da5cf5e
|
@ -131,7 +131,7 @@ type aciContainerService struct {
|
||||||
ctx store.AciContext
|
ctx store.AciContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.Container, error) {
|
func (cs *aciContainerService) List(ctx context.Context, all bool) ([]containers.Container, error) {
|
||||||
groupsClient, err := getContainerGroupsClient(cs.ctx.SubscriptionID)
|
groupsClient, err := getContainerGroupsClient(cs.ctx.SubscriptionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -156,36 +156,31 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C
|
||||||
return []containers.Container{}, err
|
return []containers.Container{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := group.Tags[singleContainerTag]; ok {
|
|
||||||
if group.Containers == nil || len(*group.Containers) < 1 {
|
if group.Containers == nil || len(*group.Containers) < 1 {
|
||||||
return []containers.Container{}, fmt.Errorf("no containers found in ACI container group %s", *containerGroup.Name)
|
return []containers.Container{}, fmt.Errorf("no containers found in ACI container group %s", *containerGroup.Name)
|
||||||
}
|
}
|
||||||
container := (*group.Containers)[0]
|
|
||||||
c := getContainer(*containerGroup.Name, group.IPAddress, container)
|
|
||||||
res = append(res, c)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, container := range *group.Containers {
|
for _, container := range *group.Containers {
|
||||||
var containerID string
|
|
||||||
// don't list sidecar container
|
// don't list sidecar container
|
||||||
if *container.Name == convert.ComposeDNSSidecarName {
|
if *container.Name == convert.ComposeDNSSidecarName {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
containerID = *containerGroup.Name + composeContainerSeparator + *container.Name
|
if !all && getStatus(container) != statusRunning {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
containerID := *containerGroup.Name + composeContainerSeparator + *container.Name
|
||||||
|
if _, ok := group.Tags[singleContainerTag]; ok {
|
||||||
|
containerID = *containerGroup.Name
|
||||||
|
}
|
||||||
c := getContainer(containerID, group.IPAddress, container)
|
c := getContainer(containerID, group.IPAddress, container)
|
||||||
res = append(res, c)
|
res = append(res, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainer(containerID string, ipAddress *containerinstance.IPAddress, container containerinstance.Container) containers.Container {
|
func getContainer(containerID string, ipAddress *containerinstance.IPAddress, container containerinstance.Container) containers.Container {
|
||||||
status := statusUnknown
|
status := getStatus(container)
|
||||||
if container.InstanceView != nil && container.InstanceView.CurrentState != nil {
|
|
||||||
status = *container.InstanceView.CurrentState.State
|
|
||||||
}
|
|
||||||
return containers.Container{
|
return containers.Container{
|
||||||
ID: containerID,
|
ID: containerID,
|
||||||
Image: *container.Image,
|
Image: *container.Image,
|
||||||
|
@ -194,6 +189,14 @@ func getContainer(containerID string, ipAddress *containerinstance.IPAddress, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStatus(container containerinstance.Container) string {
|
||||||
|
status := statusUnknown
|
||||||
|
if container.InstanceView != nil && container.InstanceView.CurrentState != nil {
|
||||||
|
status = *container.InstanceView.CurrentState.State
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *aciContainerService) Run(ctx context.Context, r containers.ContainerConfig) error {
|
func (cs *aciContainerService) Run(ctx context.Context, r containers.ContainerConfig) error {
|
||||||
if strings.Contains(r.ID, composeContainerSeparator) {
|
if strings.Contains(r.ID, composeContainerSeparator) {
|
||||||
return errors.New(fmt.Sprintf("invalid container name. ACI container name cannot include %q", composeContainerSeparator))
|
return errors.New(fmt.Sprintf("invalid container name. ACI container name cannot include %q", composeContainerSeparator))
|
||||||
|
|
|
@ -373,6 +373,18 @@ func TestContainerRunAttached(t *testing.T) {
|
||||||
res.Assert(t, icmd.Expected{Out: container})
|
res.Assert(t, icmd.Expected{Out: container})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("ps stopped container with --all", func(t *testing.T) {
|
||||||
|
res := c.RunDockerCmd("ps", container)
|
||||||
|
res.Assert(t, icmd.Success)
|
||||||
|
out := strings.Split(strings.TrimSpace(res.Stdout()), "\n")
|
||||||
|
assert.Assert(t, is.Len(out, 1))
|
||||||
|
|
||||||
|
res = c.RunDockerCmd("ps", "--all", container)
|
||||||
|
res.Assert(t, icmd.Success)
|
||||||
|
out = strings.Split(strings.TrimSpace(res.Stdout()), "\n")
|
||||||
|
assert.Assert(t, is.Len(out, 2))
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("rm stopped container", func(t *testing.T) {
|
t.Run("rm stopped container", func(t *testing.T) {
|
||||||
res := c.RunDockerCmd("rm", container)
|
res := c.RunDockerCmd("rm", container)
|
||||||
res.Assert(t, icmd.Expected{Out: container})
|
res.Assert(t, icmd.Expected{Out: container})
|
||||||
|
|
Loading…
Reference in New Issue