Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/oci/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"io"
"net/url"
"os"
"strings"

"github.com/containerd/containerd/v2/core/remotes"
Expand Down Expand Up @@ -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
}),
),
})
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/e2e/fixtures/publish/oci/compose-override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
app:
env_file: test.env
5 changes: 5 additions & 0 deletions pkg/e2e/fixtures/publish/oci/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
app:
extends:
file: extends.yaml
service: test
3 changes: 3 additions & 0 deletions pkg/e2e/fixtures/publish/oci/extends.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
test:
image: alpine
1 change: 1 addition & 0 deletions pkg/e2e/fixtures/publish/oci/test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HELLO=WORLD
41 changes: 41 additions & 0 deletions pkg/e2e/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package e2e

import (
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -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
`)
}
2 changes: 1 addition & 1 deletion pkg/remote/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down