mirror of
https://github.com/docker/compose.git
synced 2026-02-09 01:59:22 +08:00
fix OCI compose override support
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
(cherry picked from commit e59150baa8)
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
committed by
Guillaume Lours
parent
47f6d02bef
commit
5dec597d4b
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/v2/core/remotes"
|
||||
@@ -50,6 +51,11 @@ func NewResolver(config *configfile.ConfigFile) remotes.Resolver {
|
||||
return auth.Username, auth.Password, nil
|
||||
}),
|
||||
)),
|
||||
docker.WithPlainHTTP(func(s string) (bool, error) {
|
||||
// Used for testing **only**
|
||||
_, b := os.LookupEnv("__TEST__INSECURE__REGISTRY__")
|
||||
return b, nil
|
||||
}),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
3
pkg/e2e/fixtures/publish/oci/compose-override.yaml
Normal file
3
pkg/e2e/fixtures/publish/oci/compose-override.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
services:
|
||||
app:
|
||||
env_file: test.env
|
||||
5
pkg/e2e/fixtures/publish/oci/compose.yaml
Normal file
5
pkg/e2e/fixtures/publish/oci/compose.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
app:
|
||||
extends:
|
||||
file: extends.yaml
|
||||
service: test
|
||||
3
pkg/e2e/fixtures/publish/oci/extends.yaml
Normal file
3
pkg/e2e/fixtures/publish/oci/extends.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
services:
|
||||
test:
|
||||
image: alpine
|
||||
1
pkg/e2e/fixtures/publish/oci/test.env
Normal file
1
pkg/e2e/fixtures/publish/oci/test.env
Normal file
@@ -0,0 +1 @@
|
||||
HELLO=WORLD
|
||||
@@ -17,6 +17,7 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -173,3 +174,43 @@ FOO=bar`), out)
|
||||
assert.Assert(t, strings.Contains(output, "Private Key\n\"\": -----BEGIN DSA PRIVATE KEY-----\nwxyz+ABC=\n-----END DSA PRIVATE KEY-----"), output)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
c := NewParallelCLI(t)
|
||||
const projectName = "compose-e2e-publish"
|
||||
const registryName = projectName + "-registry"
|
||||
c.RunDockerCmd(t, "run", "--name", registryName, "-P", "-d", "registry:3")
|
||||
port := c.RunDockerCmd(t, "inspect", "--format", `{{ (index (index .NetworkSettings.Ports "5000/tcp") 0).HostPort }}`, registryName).Stdout()
|
||||
registry := "localhost:" + strings.TrimSpace(port)
|
||||
t.Cleanup(func() {
|
||||
c.RunDockerCmd(t, "rm", "--force", registryName)
|
||||
})
|
||||
|
||||
cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/publish/oci/compose.yaml", "-f", "./fixtures/publish/oci/compose-override.yaml",
|
||||
"-p", projectName, "publish", "--with-env", "--yes", registry+"/test:test")
|
||||
icmd.RunCmd(cmd, func(cmd *icmd.Cmd) {
|
||||
cmd.Env = append(cmd.Env, "__TEST__INSECURE__REGISTRY__=true")
|
||||
}).Assert(t, icmd.Expected{ExitCode: 0})
|
||||
|
||||
// docker exec -it compose-e2e-publish-registry tree /var/lib/registry/docker/registry/v2/
|
||||
|
||||
cmd = c.NewDockerComposeCmd(t, "--verbose", "--project-name=oci", "-f", fmt.Sprintf("oci://%s/test:test", registry), "config")
|
||||
res := icmd.RunCmd(cmd, func(cmd *icmd.Cmd) {
|
||||
cmd.Env = append(cmd.Env,
|
||||
"XDG_CACHE_HOME="+t.TempDir(),
|
||||
"__TEST__INSECURE__REGISTRY__=true")
|
||||
})
|
||||
res.Assert(t, icmd.Expected{ExitCode: 0})
|
||||
assert.Equal(t, res.Stdout(), `name: oci
|
||||
services:
|
||||
app:
|
||||
environment:
|
||||
HELLO: WORLD
|
||||
image: alpine
|
||||
networks:
|
||||
default: null
|
||||
networks:
|
||||
default:
|
||||
name: oci_default
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ func writeComposeFile(layer spec.Descriptor, i int, local string, content []byte
|
||||
return err
|
||||
}
|
||||
}
|
||||
f, err := os.Create(filepath.Join(local, file))
|
||||
f, err := os.OpenFile(filepath.Join(local, file), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user