mirror of https://github.com/docker/compose.git
Return an error when failing to list containers
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
32005b0bfe
commit
cf7b1441d9
|
@ -261,6 +261,7 @@ func getContainerProgressName(container moby.Container) string {
|
||||||
return "Container " + getCanonicalContainerName(container)
|
return "Container " + getCanonicalContainerName(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceConditionRunningOrHealthy is a service condition on statys running or healthy
|
||||||
const ServiceConditionRunningOrHealthy = "running_or_healthy"
|
const ServiceConditionRunningOrHealthy = "running_or_healthy"
|
||||||
|
|
||||||
func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, dependencies types.DependsOnConfig) error {
|
func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, dependencies types.DependsOnConfig) error {
|
||||||
|
@ -448,7 +449,10 @@ func (s *composeService) createMobyContainer(ctx context.Context, project *types
|
||||||
Networks: inspectedContainer.NetworkSettings.Networks,
|
Networks: inspectedContainer.NetworkSettings.Networks,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
links := s.getLinks(ctx, project.Name, service, number)
|
links, err := s.getLinks(ctx, project.Name, service, number)
|
||||||
|
if err != nil {
|
||||||
|
return created, err
|
||||||
|
}
|
||||||
for _, netName := range service.NetworksByPriority() {
|
for _, netName := range service.NetworksByPriority() {
|
||||||
netwrk := project.Networks[netName]
|
netwrk := project.Networks[netName]
|
||||||
cfg := service.Networks[netName]
|
cfg := service.Networks[netName]
|
||||||
|
@ -477,7 +481,7 @@ func (s *composeService) createMobyContainer(ctx context.Context, project *types
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLinks mimics V1 compose/service.py::Service::_get_links()
|
// getLinks mimics V1 compose/service.py::Service::_get_links()
|
||||||
func (s composeService) getLinks(ctx context.Context, projectName string, service types.ServiceConfig, number int) []string {
|
func (s composeService) getLinks(ctx context.Context, projectName string, service types.ServiceConfig, number int) ([]string, error) {
|
||||||
var links []string
|
var links []string
|
||||||
format := func(k, v string) string {
|
format := func(k, v string) string {
|
||||||
return fmt.Sprintf("%s:%s", k, v)
|
return fmt.Sprintf("%s:%s", k, v)
|
||||||
|
@ -495,7 +499,7 @@ func (s composeService) getLinks(ctx context.Context, projectName string, servic
|
||||||
}
|
}
|
||||||
cnts, err := getServiceContainers(linkServiceName)
|
cnts, err := getServiceContainers(linkServiceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, c := range cnts {
|
for _, c := range cnts {
|
||||||
containerName := getCanonicalContainerName(c)
|
containerName := getCanonicalContainerName(c)
|
||||||
|
@ -510,7 +514,7 @@ func (s composeService) getLinks(ctx context.Context, projectName string, servic
|
||||||
if service.Labels[api.OneoffLabel] == "True" {
|
if service.Labels[api.OneoffLabel] == "True" {
|
||||||
cnts, err := getServiceContainers(service.Name)
|
cnts, err := getServiceContainers(service.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, c := range cnts {
|
for _, c := range cnts {
|
||||||
containerName := getCanonicalContainerName(c)
|
containerName := getCanonicalContainerName(c)
|
||||||
|
@ -531,7 +535,7 @@ func (s composeService) getLinks(ctx context.Context, projectName string, servic
|
||||||
}
|
}
|
||||||
links = append(links, format(externalLink, linkName))
|
links = append(links, format(externalLink, linkName))
|
||||||
}
|
}
|
||||||
return links
|
return links, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shortIDAliasExists(containerID string, aliases ...string) bool {
|
func shortIDAliasExists(containerID string, aliases ...string) bool {
|
||||||
|
|
|
@ -81,7 +81,8 @@ func TestServiceLinks(t *testing.T) {
|
||||||
c := testContainer("db", dbContainerName, false)
|
c := testContainer("db", dbContainerName, false)
|
||||||
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
||||||
|
|
||||||
links := tested.getLinks(context.Background(), testProject, s, 1)
|
links, err := tested.getLinks(context.Background(), testProject, s, 1)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, len(links), 3)
|
assert.Equal(t, len(links), 3)
|
||||||
assert.Equal(t, links[0], "testProject-db-1:db")
|
assert.Equal(t, links[0], "testProject-db-1:db")
|
||||||
|
@ -100,7 +101,8 @@ func TestServiceLinks(t *testing.T) {
|
||||||
c := testContainer("db", dbContainerName, false)
|
c := testContainer("db", dbContainerName, false)
|
||||||
|
|
||||||
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
||||||
links := tested.getLinks(context.Background(), testProject, s, 1)
|
links, err := tested.getLinks(context.Background(), testProject, s, 1)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, len(links), 3)
|
assert.Equal(t, len(links), 3)
|
||||||
assert.Equal(t, links[0], "testProject-db-1:db")
|
assert.Equal(t, links[0], "testProject-db-1:db")
|
||||||
|
@ -119,7 +121,8 @@ func TestServiceLinks(t *testing.T) {
|
||||||
c := testContainer("db", dbContainerName, false)
|
c := testContainer("db", dbContainerName, false)
|
||||||
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
||||||
|
|
||||||
links := tested.getLinks(context.Background(), testProject, s, 1)
|
links, err := tested.getLinks(context.Background(), testProject, s, 1)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, len(links), 3)
|
assert.Equal(t, len(links), 3)
|
||||||
assert.Equal(t, links[0], "testProject-db-1:dbname")
|
assert.Equal(t, links[0], "testProject-db-1:dbname")
|
||||||
|
@ -139,7 +142,9 @@ func TestServiceLinks(t *testing.T) {
|
||||||
c := testContainer("db", dbContainerName, false)
|
c := testContainer("db", dbContainerName, false)
|
||||||
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]moby.Container{c}, nil)
|
||||||
|
|
||||||
links := tested.getLinks(context.Background(), testProject, s, 1)
|
links, err := tested.getLinks(context.Background(), testProject, s, 1)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, len(links), 4)
|
assert.Equal(t, len(links), 4)
|
||||||
assert.Equal(t, links[0], "testProject-db-1:dbname")
|
assert.Equal(t, links[0], "testProject-db-1:dbname")
|
||||||
assert.Equal(t, links[1], "testProject-db-1:db-1")
|
assert.Equal(t, links[1], "testProject-db-1:db-1")
|
||||||
|
@ -170,7 +175,9 @@ func TestServiceLinks(t *testing.T) {
|
||||||
}
|
}
|
||||||
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptionsOneOff).Return([]moby.Container{c}, nil)
|
apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptionsOneOff).Return([]moby.Container{c}, nil)
|
||||||
|
|
||||||
links := tested.getLinks(context.Background(), testProject, s, 1)
|
links, err := tested.getLinks(context.Background(), testProject, s, 1)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, len(links), 3)
|
assert.Equal(t, len(links), 3)
|
||||||
assert.Equal(t, links[0], "testProject-web-1:web")
|
assert.Equal(t, links[0], "testProject-web-1:web")
|
||||||
assert.Equal(t, links[1], "testProject-web-1:web-1")
|
assert.Equal(t, links[1], "testProject-web-1:web-1")
|
||||||
|
|
Loading…
Reference in New Issue