mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
Fixing bind mount with relative path when specifying relative working dir. Added first local compose volume e2e test
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
ab8c97d31e
commit
814536c0bd
@ -800,7 +800,10 @@ func getContainerCreateOptions(p *types.Project, s types.ServiceConfig, number i
|
|||||||
StopTimeout: toSeconds(s.StopGracePeriod),
|
StopTimeout: toSeconds(s.StopGracePeriod),
|
||||||
}
|
}
|
||||||
|
|
||||||
mountOptions := buildContainerMountOptions(p, s, inherit)
|
mountOptions, err := buildContainerMountOptions(p, s, inherit)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
bindings := buildContainerBindingOptions(s)
|
bindings := buildContainerBindingOptions(s)
|
||||||
|
|
||||||
networkMode := getNetworkMode(p, s)
|
networkMode := getNetworkMode(p, s)
|
||||||
@ -844,7 +847,7 @@ func buildContainerBindingOptions(s types.ServiceConfig) nat.PortMap {
|
|||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildContainerMountOptions(p *types.Project, s types.ServiceConfig, inherit *moby.Container) []mount.Mount {
|
func buildContainerMountOptions(p *types.Project, s types.ServiceConfig, inherit *moby.Container) ([]mount.Mount, error) {
|
||||||
mounts := []mount.Mount{}
|
mounts := []mount.Mount{}
|
||||||
var inherited []string
|
var inherited []string
|
||||||
if inherit != nil {
|
if inherit != nil {
|
||||||
@ -872,8 +875,12 @@ func buildContainerMountOptions(p *types.Project, s types.ServiceConfig, inherit
|
|||||||
}
|
}
|
||||||
source := v.Source
|
source := v.Source
|
||||||
if v.Type == "bind" && !filepath.IsAbs(source) {
|
if v.Type == "bind" && !filepath.IsAbs(source) {
|
||||||
// FIXME handle ~/
|
// volume source has already been prefixed with workdir if required, by compose-go project loader
|
||||||
source = filepath.Join(p.WorkingDir, source)
|
var err error
|
||||||
|
source, err = filepath.Abs(source)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mounts = append(mounts, mount.Mount{
|
mounts = append(mounts, mount.Mount{
|
||||||
@ -887,7 +894,7 @@ func buildContainerMountOptions(p *types.Project, s types.ServiceConfig, inherit
|
|||||||
TmpfsOptions: buildTmpfsOptions(v.Tmpfs),
|
TmpfsOptions: buildTmpfsOptions(v.Tmpfs),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return mounts
|
return mounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildBindOption(bind *types.ServiceVolumeBind) *mount.BindOptions {
|
func buildBindOption(bind *types.ServiceVolumeBind) *mount.BindOptions {
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
. "github.com/docker/compose-cli/tests/framework"
|
. "github.com/docker/compose-cli/tests/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLocalBackendComposeUp(t *testing.T) {
|
func TestLocalComposeUp(t *testing.T) {
|
||||||
c := NewParallelE2eCLI(t, binDir)
|
c := NewParallelE2eCLI(t, binDir)
|
||||||
c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success)
|
c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success)
|
||||||
c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success)
|
c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success)
|
||||||
@ -86,3 +86,20 @@ func TestLocalBackendComposeUp(t *testing.T) {
|
|||||||
assert.Equal(t, networkList.Stdout(), networksAfterDown.Stdout())
|
assert.Equal(t, networkList.Stdout(), networksAfterDown.Stdout())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLocalComposeVolume(t *testing.T) {
|
||||||
|
c := NewParallelE2eCLI(t, binDir)
|
||||||
|
c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success)
|
||||||
|
c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success)
|
||||||
|
|
||||||
|
const projectName = "compose-e2e-volume"
|
||||||
|
|
||||||
|
t.Run("up with volume", func(t *testing.T) {
|
||||||
|
c.RunDockerCmd("compose", "up", "--workdir", "volume-test", "--project-name", projectName)
|
||||||
|
|
||||||
|
output := HTTPGetWithRetry(t, "http://localhost:8090", http.StatusOK, 2*time.Second, 20*time.Second)
|
||||||
|
assert.Assert(t, strings.Contains(output, "Hello from Nginx container"))
|
||||||
|
|
||||||
|
_ = c.RunDockerCmd("compose", "down", "--project-name", projectName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
7
local/e2e/volume-test/docker-compose.yml
Normal file
7
local/e2e/volume-test/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
image: nginx
|
||||||
|
volumes:
|
||||||
|
- ./static:/usr/share/nginx/html
|
||||||
|
ports:
|
||||||
|
- 8090:80
|
10
local/e2e/volume-test/static/index.html
Normal file
10
local/e2e/volume-test/static/index.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Docker Nginx</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Hello from Nginx container</h2>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user