Migrate Sirupsen to sirupsen.

This commit is contained in:
Ludovic Fernandez 2018-01-22 12:16:03 +01:00 committed by Traefiker
parent c134dcd6fe
commit fb4ba7af2b
684 changed files with 92394 additions and 33943 deletions

View file

@ -5,13 +5,19 @@ import (
"fmt"
"strings"
"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
)
var defaultValues = make(map[string]string)
func isNum(c uint8) bool {
return c >= '0' && c <= '9'
}
func validVariableDefault(c uint8, line string, pos int) bool {
return (c == ':' && line[pos+1] == '-') || (c == '-')
}
func validVariableNameChar(c uint8) bool {
return c == '_' ||
c >= 'A' && c <= 'Z' ||
@ -36,6 +42,30 @@ func parseVariable(line string, pos int, mapping func(string) string) (string, i
return mapping(buffer.String()), pos, true
}
func parseDefaultValue(line string, pos int) (string, int, bool) {
var buffer bytes.Buffer
// only skip :, :- and - at the beginning
for ; pos < len(line); pos++ {
c := line[pos]
if c == ':' || c == '-' {
continue
}
break
}
for ; pos < len(line); pos++ {
c := line[pos]
if c == '}' {
return buffer.String(), pos - 1, true
}
err := buffer.WriteByte(c)
if err != nil {
return "", pos, false
}
}
return "", 0, false
}
func parseVariableWithBraces(line string, pos int, mapping func(string) string) (string, int, bool) {
var buffer bytes.Buffer
@ -49,10 +79,13 @@ func parseVariableWithBraces(line string, pos int, mapping func(string) string)
if bufferString == "" {
return "", 0, false
}
return mapping(buffer.String()), pos, true
case validVariableNameChar(c):
buffer.WriteByte(c)
case validVariableDefault(c, line, pos):
defaultValue := ""
defaultValue, pos, _ = parseDefaultValue(line, pos)
defaultValues[buffer.String()] = defaultValue
default:
return "", 0, false
}
@ -143,10 +176,19 @@ func Interpolate(key string, data *interface{}, environmentLookup EnvironmentLoo
values := environmentLookup.Lookup(s, nil)
if len(values) == 0 {
if val, ok := defaultValues[s]; ok {
return val
}
logrus.Warnf("The %s variable is not set. Substituting a blank string.", s)
return ""
}
if strings.SplitN(values[0], "=", 2)[1] == "" {
if val, ok := defaultValues[s]; ok {
return val
}
}
// Use first result if many are given
value := values[0]

View file

@ -6,11 +6,12 @@ import (
"fmt"
"strings"
"reflect"
"github.com/docker/docker/pkg/urlutil"
"github.com/docker/libcompose/utils"
composeYaml "github.com/docker/libcompose/yaml"
"gopkg.in/yaml.v2"
"reflect"
)
var (
@ -229,8 +230,6 @@ func readEnvFile(resourceLookup ResourceLookup, inFile string, serviceData RawSe
serviceData["environment"] = vars
delete(serviceData, "env_file")
return serviceData, nil
}

View file

@ -4,8 +4,8 @@ import (
"fmt"
"path"
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/utils"
"github.com/sirupsen/logrus"
)
// MergeServicesV1 merges a v1 compose file into an existing set of service configs

View file

@ -5,8 +5,8 @@ import (
"path"
"strings"
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/utils"
"github.com/sirupsen/logrus"
)
// MergeServicesV2 merges a v2 compose file into an existing set of service configs

View file

@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"
"github.com/Sirupsen/logrus"
"github.com/docker/cli/cli/command/image/build"
"github.com/docker/docker/api/types"
"github.com/docker/docker/builder/dockerignore"
@ -20,6 +19,7 @@ import (
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/term"
"github.com/docker/libcompose/logger"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
)
@ -42,6 +42,7 @@ type DaemonBuilder struct {
ForceRemove bool
Pull bool
BuildArgs map[string]*string
CacheFrom []string
LoggerFactory logger.Factory
}
@ -96,6 +97,7 @@ func (d *DaemonBuilder) Build(ctx context.Context, imageName string) error {
Dockerfile: d.Dockerfile,
AuthConfigs: d.AuthConfigs,
BuildArgs: d.BuildArgs,
CacheFrom: d.CacheFrom,
})
if err != nil {
return err

View file

@ -11,12 +11,10 @@ import (
"golang.org/x/net/context"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/pkg/term"
"github.com/docker/go-connections/nat"
@ -24,6 +22,7 @@ import (
"github.com/docker/libcompose/labels"
"github.com/docker/libcompose/logger"
"github.com/docker/libcompose/project"
"github.com/sirupsen/logrus"
)
// Container holds information about a docker container and the service it is tied on.
@ -180,6 +179,7 @@ func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfi
errCh chan error
out, stderr io.Writer
in io.ReadCloser
inFd uintptr
)
if configOverride.StdinOpen {
@ -202,18 +202,22 @@ func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfi
return -1, err
}
// set raw terminal
inFd, _ := term.GetFdInfo(in)
state, err := term.SetRawTerminal(inFd)
if err != nil {
return -1, err
if configOverride.StdinOpen {
// set raw terminal
inFd, _ = term.GetFdInfo(in)
state, err := term.SetRawTerminal(inFd)
if err != nil {
return -1, err
}
// restore raw terminal
defer term.RestoreTerminal(inFd, state)
}
// restore raw terminal
defer term.RestoreTerminal(inFd, state)
// holdHijackedConnection (in goroutine)
errCh = promise.Go(func() error {
return holdHijackedConnection(configOverride.Tty, in, out, stderr, resp)
})
errCh = make(chan error, 1)
go func() {
errCh <- holdHijackedConnection(configOverride.Tty, in, out, stderr, resp)
}()
if err := c.client.ContainerStart(ctx, c.container.ID, types.ContainerStartOptions{}); err != nil {
return -1, err

View file

@ -32,7 +32,7 @@ func ListByFilter(ctx context.Context, clientInstance client.ContainerAPIClient,
func Get(ctx context.Context, clientInstance client.ContainerAPIClient, id string) (*types.ContainerJSON, error) {
container, err := clientInstance.ContainerInspect(ctx, id)
if err != nil {
if client.IsErrContainerNotFound(err) {
if client.IsErrNotFound(err) {
return nil, nil
}
return nil, err

View file

@ -7,7 +7,6 @@ import (
"io"
"os"
"github.com/Sirupsen/logrus"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
@ -15,6 +14,7 @@ import (
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/registry"
"github.com/docker/libcompose/docker/auth"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
)
@ -22,7 +22,7 @@ import (
func Exists(ctx context.Context, clt client.ImageAPIClient, image string) (bool, error) {
_, err := InspectImage(ctx, clt, image)
if err != nil {
if client.IsErrImageNotFound(err) {
if client.IsErrNotFound(err) {
return false, nil
}
return false, err

View file

@ -35,7 +35,9 @@ func (n *Network) fullName() string {
// Inspect inspect the current network
func (n *Network) Inspect(ctx context.Context) (types.NetworkResource, error) {
return n.client.NetworkInspect(ctx, n.fullName(), false)
return n.client.NetworkInspect(ctx, n.fullName(), types.NetworkInspectOptions{
Verbose: true,
})
}
// Remove removes the current network (from docker engine)
@ -53,13 +55,13 @@ func (n *Network) Remove(ctx context.Context) error {
func (n *Network) EnsureItExists(ctx context.Context) error {
networkResource, err := n.Inspect(ctx)
if n.external {
if client.IsErrNetworkNotFound(err) {
if client.IsErrNotFound(err) {
// FIXME(vdemeester) introduce some libcompose error type
return fmt.Errorf("Network %s declared as external, but could not be found. Please create the network manually using docker network create %s and try again", n.fullName(), n.fullName())
}
return err
}
if err != nil && client.IsErrNetworkNotFound(err) {
if err != nil && client.IsErrNotFound(err) {
return n.create(ctx)
}
if n.driver != "" && networkResource.Driver != n.driver {

View file

@ -3,7 +3,6 @@ package docker
import (
"golang.org/x/net/context"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/libcompose/config"
@ -15,6 +14,7 @@ import (
"github.com/docker/libcompose/docker/volume"
"github.com/docker/libcompose/labels"
"github.com/docker/libcompose/project"
"github.com/sirupsen/logrus"
)
// NewProject creates a Project with the specified context.

View file

@ -4,10 +4,10 @@ import (
"fmt"
"strings"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/strslice"
"github.com/docker/docker/runconfig/opts"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
"github.com/docker/libcompose/config"

View file

@ -7,7 +7,6 @@ import (
"golang.org/x/net/context"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
@ -26,6 +25,7 @@ import (
"github.com/docker/libcompose/project/options"
"github.com/docker/libcompose/utils"
"github.com/docker/libcompose/yaml"
"github.com/sirupsen/logrus"
)
// Service is a project.Service implementations.
@ -257,7 +257,7 @@ func (s *Service) Run(ctx context.Context, commandParts []string, options option
return -1, err
}
configOverride := &config.ServiceConfig{Command: commandParts, Tty: true, StdinOpen: true}
configOverride := &config.ServiceConfig{Command: commandParts, Tty: !options.DisableTty, StdinOpen: !options.DisableTty}
c, err := s.createContainer(ctx, namer, "", configOverride, true)
if err != nil {
@ -357,7 +357,7 @@ func (s *Service) connectContainerToNetworks(ctx context.Context, c *container.C
}
if s.serviceConfig.Networks != nil {
for _, network := range s.serviceConfig.Networks.Networks {
existingNetwork, ok := connectedNetworks[network.Name]
existingNetwork, ok := connectedNetworks[network.RealName]
if ok {
// FIXME(vdemeester) implement alias checking (to not disconnect/reconnect for nothing)
aliasPresent := false
@ -488,7 +488,7 @@ func (s *Service) OutOfSync(ctx context.Context, c *container.Container) (bool,
image, err := image.InspectImage(ctx, s.clientFactory.Create(s), c.ImageConfig())
if err != nil {
if client.IsErrImageNotFound(err) {
if client.IsErrNotFound(err) {
logrus.Debugf("Image %s do not exist, do not know if it's out of sync", c.Image())
return false, nil
}

View file

@ -7,7 +7,6 @@ import (
"golang.org/x/net/context"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
@ -17,6 +16,7 @@ import (
"github.com/docker/libcompose/project"
"github.com/docker/libcompose/project/events"
util "github.com/docker/libcompose/utils"
"github.com/sirupsen/logrus"
)
func (s *Service) createContainer(ctx context.Context, namer Namer, oldContainer string, configOverride *config.ServiceConfig, oneOff bool) (*composecontainer.Container, error) {

View file

@ -51,13 +51,13 @@ func (v *Volume) Remove(ctx context.Context) error {
func (v *Volume) EnsureItExists(ctx context.Context) error {
volumeResource, err := v.Inspect(ctx)
if v.external {
if client.IsErrVolumeNotFound(err) {
if client.IsErrNotFound(err) {
// FIXME(shouze) introduce some libcompose error type
return fmt.Errorf("Volume %s declared as external, but could not be found. Please create the volume manually using docker volume create %s and try again", v.name, v.name)
}
return err
}
if err != nil && client.IsErrVolumeNotFound(err) {
if err != nil && client.IsErrNotFound(err) {
return v.create(ctx)
}
if volumeResource.Driver != v.driver {

View file

@ -3,7 +3,7 @@ package lookup
import (
"strings"
"github.com/docker/docker/runconfig/opts"
"github.com/docker/cli/opts"
"github.com/docker/libcompose/config"
)

View file

@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"
"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
)
// relativePath returns the proper relative path for the given file path. If

View file

@ -9,9 +9,9 @@ import (
"regexp"
"strings"
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/config"
"github.com/docker/libcompose/logger"
"github.com/sirupsen/logrus"
)
var projectRegexp = regexp.MustCompile("[^a-zA-Z0-9_.-]")

View file

@ -3,8 +3,8 @@ package project
import (
"bytes"
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/project/events"
"github.com/sirupsen/logrus"
)
var (

View file

@ -30,7 +30,8 @@ type Create struct {
// Run holds options of compose run.
type Run struct {
Detached bool
Detached bool
DisableTty bool
}
// Up holds options of compose up.

View file

@ -10,13 +10,13 @@ import (
"golang.org/x/net/context"
log "github.com/Sirupsen/logrus"
"github.com/docker/libcompose/config"
"github.com/docker/libcompose/logger"
"github.com/docker/libcompose/lookup"
"github.com/docker/libcompose/project/events"
"github.com/docker/libcompose/utils"
"github.com/docker/libcompose/yaml"
log "github.com/sirupsen/logrus"
)
// ComposeVersion is name of docker-compose.yml file syntax supported version

View file

@ -2,6 +2,7 @@ package project
import (
"fmt"
"sync"
"golang.org/x/net/context"
@ -12,6 +13,8 @@ import (
// the Filter struct.
func (p *Project) Containers(ctx context.Context, filter Filter, services ...string) ([]string, error) {
containers := []string{}
var lock sync.Mutex
err := p.forEach(services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) {
wrapper.Do(nil, events.NoEvent, events.NoEvent, func(service Service) error {
serviceContainers, innerErr := service.Containers(ctx)
@ -37,7 +40,9 @@ func (p *Project) Containers(ctx context.Context, filter Filter, services ...str
return fmt.Errorf("Invalid container filter: %s", filter.State)
}
containerID := container.ID()
lock.Lock()
containers = append(containers, containerID)
lock.Unlock()
}
return nil
})

View file

@ -5,7 +5,7 @@ import (
"golang.org/x/net/context"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
)
// Scale scales the specified services.

View file

@ -3,8 +3,8 @@ package project
import (
"sync"
log "github.com/Sirupsen/logrus"
"github.com/docker/libcompose/project/events"
log "github.com/sirupsen/logrus"
)
type serviceWrapper struct {

View file

@ -5,7 +5,7 @@ import (
"sync"
"time"
"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)