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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -156,36 +156,31 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C
|
|||
return []containers.Container{}, err
|
||||
}
|
||||
|
||||
if _, ok := group.Tags[singleContainerTag]; ok {
|
||||
if group.Containers == nil || len(*group.Containers) < 1 {
|
||||
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
|
||||
if group.Containers == nil || len(*group.Containers) < 1 {
|
||||
return []containers.Container{}, fmt.Errorf("no containers found in ACI container group %s", *containerGroup.Name)
|
||||
}
|
||||
|
||||
for _, container := range *group.Containers {
|
||||
var containerID string
|
||||
// don't list sidecar container
|
||||
if *container.Name == convert.ComposeDNSSidecarName {
|
||||
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)
|
||||
res = append(res, c)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func getContainer(containerID string, ipAddress *containerinstance.IPAddress, container containerinstance.Container) containers.Container {
|
||||
status := statusUnknown
|
||||
if container.InstanceView != nil && container.InstanceView.CurrentState != nil {
|
||||
status = *container.InstanceView.CurrentState.State
|
||||
}
|
||||
status := getStatus(container)
|
||||
return containers.Container{
|
||||
ID: containerID,
|
||||
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 {
|
||||
if strings.Contains(r.ID, 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})
|
||||
})
|
||||
|
||||
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) {
|
||||
res := c.RunDockerCmd("rm", container)
|
||||
res.Assert(t, icmd.Expected{Out: container})
|
||||
|
|
Loading…
Reference in New Issue