mirror of https://github.com/docker/compose.git
WIP: replace uses of stringid
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
af4c231b2c
commit
252ddd8da9
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
stringid "github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/api/types/image"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
stringid "github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/compose/v2/pkg/api"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/api/types/container"
|
||||
)
|
||||
|
@ -137,7 +136,7 @@ func (c *ContainerContext) MarshalJSON() ([]byte, error) {
|
|||
// option being set, the full or truncated ID is returned.
|
||||
func (c *ContainerContext) ID() string {
|
||||
if c.trunc {
|
||||
return stringid.TruncateID(c.c.ID)
|
||||
return formatter.TruncateID(c.c.ID)
|
||||
}
|
||||
return c.c.ID
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package compose
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -27,9 +29,9 @@ import (
|
|||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/cli/cli"
|
||||
cmd "github.com/docker/cli/cli/command/container"
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/compose/v2/pkg/api"
|
||||
"github.com/docker/compose/v2/pkg/progress"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
)
|
||||
|
||||
func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
|
||||
|
@ -83,9 +85,9 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
|
|||
return "", err
|
||||
}
|
||||
|
||||
slug := stringid.GenerateRandomID()
|
||||
slug := generateRandomID()
|
||||
if service.ContainerName == "" {
|
||||
service.ContainerName = fmt.Sprintf("%[1]s%[4]s%[2]s%[4]srun%[4]s%[3]s", project.Name, service.Name, stringid.TruncateID(slug), api.Separator)
|
||||
service.ContainerName = fmt.Sprintf("%[1]s%[4]s%[2]s%[4]srun%[4]s%[3]s", project.Name, service.Name, formatter.TruncateID(slug), api.Separator)
|
||||
}
|
||||
one := 1
|
||||
service.Scale = &one
|
||||
|
@ -207,3 +209,14 @@ func (s *composeService) startDependencies(ctx context.Context, project *types.P
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// generateRandomID returns a unique, 64-character ID consisting of a-z, 0-9.
|
||||
func generateRandomID() string {
|
||||
b := make([]byte, 32)
|
||||
for {
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err) // This shouldn't happen
|
||||
}
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue