1
0
mirror of https://github.com/rancher/os.git synced 2025-08-01 23:17:50 +00:00

Merge pull request #1008 from joshwget/legacy-labels

Support legacy Docker Compose labels
This commit is contained in:
Denise 2016-06-13 18:36:46 -07:00 committed by GitHub
commit 6d3ac8d734
6 changed files with 38 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package docker
import (
"fmt"
"github.com/Sirupsen/logrus"
dockerclient "github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
@ -150,7 +152,9 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
return err
}
}
s.rename(ctx)
if err = s.rename(ctx); err != nil {
return err
}
}
if labels[config.CREATE_ONLY] == "true" {
return s.checkReload(labels)
@ -186,7 +190,7 @@ func (s *Service) getContainer(ctx context.Context) (dockerclient.APIClient, typ
}
if len(containers) == 0 {
return nil, types.ContainerJSON{}, nil
return nil, types.ContainerJSON{}, fmt.Errorf("No containers found for %s", s.Name())
}
id, err := containers[0].ID()

View File

@ -15,7 +15,7 @@ github.com/docker/docker 8ba9ee769ba6c451e1d2abf05368580323201667 https://github
github.com/docker/engine-api v0.3.3
github.com/docker/go-connections v0.2.0
github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
github.com/docker/libcompose 8cfb76082bb536e8e76bd51de9db8cdda2c27601 https://github.com/rancher/libcompose.git
github.com/docker/libcompose e9127328a2aa01c6229952f5721b54a854726e0d https://github.com/rancher/libcompose.git
github.com/docker/libnetwork v0.5.6
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
github.com/docker/machine 4a8e93ac9bc2ced1c3bc4a43c03fdaa1c2749205

View File

@ -134,6 +134,11 @@ func (c *Container) Recreate(ctx context.Context, imageName string) (*types.Cont
}
hash := container.Config.Labels[labels.HASH.Str()]
legacyHash := container.Config.Labels[labels.HASH_LEGACY.Str()]
if hash == "" && legacyHash != "" {
hash = legacyHash
}
if hash == "" {
return nil, fmt.Errorf("Failed to find hash on old container: %s", container.Name)
}

View File

@ -63,7 +63,12 @@ func NewNamer(ctx context.Context, client client.APIClient, project, service str
maxNumber := 0
for _, container := range containers {
number, err := strconv.Atoi(container.Labels[labels.NUMBER.Str()])
numberLabel := container.Labels[labels.NUMBER.Str()]
if numberLabel == "" {
namer.currentNumber = 1
return namer, nil
}
number, err := strconv.Atoi(numberLabel)
if err != nil {
return nil, err
}

View File

@ -79,15 +79,29 @@ func (s *Service) collectContainers(ctx context.Context) ([]*Container, error) {
return nil, err
}
legacyContainers, err := GetContainersByFilter(ctx, client, labels.SERVICE_LEGACY.Eq(s.name), labels.PROJECT_LEGACY.Eq(s.context.Project.Name))
if err != nil {
return nil, err
}
if len(containers) == 0 && len(legacyContainers) > 0 {
containers = legacyContainers
}
result := []*Container{}
for _, container := range containers {
containerNumber, err := strconv.Atoi(container.Labels[labels.NUMBER.Str()])
numberLabel := container.Labels[labels.NUMBER.Str()]
name := strings.SplitAfter(container.Names[0], "/")
if numberLabel == "" {
result = append(result, NewContainer(client, name[1], 1, s))
return result, nil
}
containerNumber, err := strconv.Atoi(numberLabel)
if err != nil {
return nil, err
}
// Compose add "/" before name, so Name[1] will store actaul name.
name := strings.SplitAfter(container.Names[0], "/")
result = append(result, NewContainer(client, name[1], containerNumber, s))
}

View File

@ -18,6 +18,10 @@ const (
SERVICE = Label("com.docker.compose.service")
HASH = Label("com.docker.compose.config-hash")
VERSION = Label("com.docker.compose.version")
PROJECT_LEGACY = Label("io.docker.compose.project")
SERVICE_LEGACY = Label("io.docker.compose.service")
HASH_LEGACY = Label("io.docker.compose.config-hash")
)
// EqString returns a label json string representation with the specified value.