Skip to content

Commit a5d1ea8

Browse files
committed
Update libcompose according to 1.10 changes
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 55d23b5 commit a5d1ea8

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

docker/builder.go

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"strings"
1010

1111
"github.com/Sirupsen/logrus"
12+
"github.com/docker/docker/builder/dockerignore"
1213
"github.com/docker/docker/pkg/archive"
1314
"github.com/docker/docker/pkg/fileutils"
14-
"github.com/docker/docker/utils"
1515
"github.com/docker/libcompose/project"
1616
dockerclient "github.com/fsouza/go-dockerclient"
1717
)
@@ -129,7 +129,7 @@ func CreateTar(p *project.Project, name string) (io.ReadCloser, error) {
129129
logrus.Warnf("Error while reading .dockerignore (%s) : %s", dockerIgnorePath, err.Error())
130130
excludes = make([]string, 0)
131131
} else {
132-
excludes, err = utils.ReadDockerIgnore(dockerIgnore)
132+
excludes, err = dockerignore.ReadAll(dockerIgnore)
133133
if err != nil {
134134
return nil, err
135135
}
@@ -147,7 +147,7 @@ func CreateTar(p *project.Project, name string) (io.ReadCloser, error) {
147147
includes = append(includes, ".dockerignore", dockerfileName)
148148
}
149149

150-
if err := utils.ValidateContextDirectory(root, excludes); err != nil {
150+
if err := validateContextDirectory(root, excludes); err != nil {
151151
return nil, fmt.Errorf("Error checking context is accessible: '%s'. Please check permissions and try again.", err)
152152
}
153153

@@ -159,3 +159,57 @@ func CreateTar(p *project.Project, name string) (io.ReadCloser, error) {
159159

160160
return archive.TarWithOptions(root, options)
161161
}
162+
163+
// FIXME this is duplicate with docker/docker..
164+
165+
// validateContextDirectory checks if all the contents of the directory
166+
// can be read and returns an error if some files can't be read
167+
// symlinks which point to non-existing files don't trigger an error
168+
func validateContextDirectory(srcPath string, excludes []string) error {
169+
contextRoot, err := getContextRoot(srcPath)
170+
if err != nil {
171+
return err
172+
}
173+
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
174+
// skip this directory/file if it's not in the path, it won't get added to the context
175+
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
176+
return err
177+
} else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil {
178+
return err
179+
} else if skip {
180+
if f.IsDir() {
181+
return filepath.SkipDir
182+
}
183+
return nil
184+
}
185+
186+
if err != nil {
187+
if os.IsPermission(err) {
188+
return fmt.Errorf("can't stat '%s'", filePath)
189+
}
190+
if os.IsNotExist(err) {
191+
return nil
192+
}
193+
return err
194+
}
195+
196+
// skip checking if symlinks point to non-existing files, such symlinks can be useful
197+
// also skip named pipes, because they hanging on open
198+
if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {
199+
return nil
200+
}
201+
202+
if !f.IsDir() {
203+
currentFile, err := os.Open(filePath)
204+
if err != nil && os.IsPermission(err) {
205+
return fmt.Errorf("no permission to read from '%s'", filePath)
206+
}
207+
currentFile.Close()
208+
}
209+
return nil
210+
})
211+
}
212+
213+
func getContextRoot(srcPath string) (string, error) {
214+
return filepath.Join(srcPath, "."), nil
215+
}

docker/container.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"strings"
88

99
"github.com/Sirupsen/logrus"
10-
"github.com/docker/docker/cliconfig"
11-
"github.com/docker/docker/pkg/parsers"
10+
"github.com/docker/docker/reference"
1211
"github.com/docker/docker/registry"
13-
"github.com/docker/docker/utils"
12+
"github.com/docker/engine-api/types"
1413
"github.com/docker/libcompose/logger"
1514
"github.com/docker/libcompose/project"
1615
util "github.com/docker/libcompose/utils"
@@ -507,19 +506,19 @@ func (c *Container) pull(image string) error {
507506
}
508507

509508
func pullImage(client *dockerclient.Client, service *Service, image string) error {
510-
taglessRemote, tag := parsers.ParseRepositoryTag(image)
511-
if tag == "" {
512-
image = utils.ImageReference(taglessRemote, DefaultTag)
509+
distributionRef, err := reference.ParseNamed(image)
510+
if err != nil {
511+
return err
513512
}
514513

515-
repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
514+
repoInfo, err := registry.ParseRepositoryInfo(distributionRef)
516515
if err != nil {
517516
return err
518517
}
519518

520-
authConfig := cliconfig.AuthConfig{}
519+
authConfig := types.AuthConfig{}
521520
if service.context.ConfigFile != nil && repoInfo != nil && repoInfo.Index != nil {
522-
authConfig = registry.ResolveAuthConfig(service.context.ConfigFile, repoInfo.Index)
521+
authConfig = registry.ResolveAuthConfig(service.context.ConfigFile.AuthConfigs, repoInfo.Index)
523522
}
524523

525524
err = client.PullImage(

docker/convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package docker
33
import (
44
"strings"
55

6-
"github.com/docker/docker/pkg/nat"
7-
"github.com/docker/docker/runconfig"
6+
"github.com/docker/docker/runconfig/opts"
7+
"github.com/docker/go-connections/nat"
88
"github.com/docker/libcompose/project"
99
"github.com/docker/libcompose/utils"
1010

@@ -59,7 +59,7 @@ func volumes(c *project.ServiceConfig, ctx *Context) map[string]struct{} {
5959
}
6060

6161
func restartPolicy(c *project.ServiceConfig) (*dockerclient.RestartPolicy, error) {
62-
restart, err := runconfig.ParseRestartPolicy(c.Restart)
62+
restart, err := opts.ParseRestartPolicy(c.Restart)
6363
if err != nil {
6464
return nil, err
6565
}
@@ -181,7 +181,7 @@ func parseDevices(devices []string) ([]dockerclient.Device, error) {
181181
// parse device mappings
182182
deviceMappings := []dockerclient.Device{}
183183
for _, device := range devices {
184-
v, err := runconfig.ParseDevice(device)
184+
v, err := opts.ParseDevice(device)
185185
if err != nil {
186186
return nil, err
187187
}

docker/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55

66
"github.com/Sirupsen/logrus"
7-
"github.com/docker/docker/pkg/nat"
7+
"github.com/docker/go-connections/nat"
88
"github.com/docker/libcompose/project"
99
"github.com/docker/libcompose/utils"
1010
"github.com/fsouza/go-dockerclient"

project/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package project
33
import (
44
"strings"
55

6-
"github.com/docker/docker/runconfig"
6+
"github.com/docker/engine-api/types/container"
77
)
88

99
// DefaultDependentServices return the dependent services (as an array of ServiceRelationship)
@@ -51,7 +51,7 @@ func NameAlias(name string) (string, string) {
5151
// GetContainerFromIpcLikeConfig returns name of the service that shares the IPC
5252
// namespace with the specified service.
5353
func GetContainerFromIpcLikeConfig(p *Project, conf string) string {
54-
ipc := runconfig.IpcMode(conf)
54+
ipc := container.IpcMode(conf)
5555
if !ipc.IsContainer() {
5656
return ""
5757
}

0 commit comments

Comments
 (0)