Skip to content

Commit e59150b

Browse files
ndeloofglours
authored andcommitted
fix OCI compose override support
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 6a90742 commit e59150b

File tree

7 files changed

+60
-1
lines changed

7 files changed

+60
-1
lines changed

internal/oci/resolver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"io"
2222
"net/url"
23+
"os"
2324
"strings"
2425

2526
"github.com/containerd/containerd/v2/core/remotes"
@@ -50,6 +51,11 @@ func NewResolver(config *configfile.ConfigFile) remotes.Resolver {
5051
return auth.Username, auth.Password, nil
5152
}),
5253
)),
54+
docker.WithPlainHTTP(func(s string) (bool, error) {
55+
// Used for testing **only**
56+
_, b := os.LookupEnv("__TEST__INSECURE__REGISTRY__")
57+
return b, nil
58+
}),
5359
),
5460
})
5561
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
app:
3+
env_file: test.env
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
app:
3+
extends:
4+
file: extends.yaml
5+
service: test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
test:
3+
image: alpine
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HELLO=WORLD

pkg/e2e/publish_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package e2e
1818

1919
import (
20+
"fmt"
2021
"strings"
2122
"testing"
2223

@@ -173,3 +174,43 @@ FOO=bar`), out)
173174
assert.Assert(t, strings.Contains(output, "Private Key\n\"\": -----BEGIN DSA PRIVATE KEY-----\nwxyz+ABC=\n-----END DSA PRIVATE KEY-----"), output)
174175
})
175176
}
177+
178+
func TestPublish(t *testing.T) {
179+
c := NewParallelCLI(t)
180+
const projectName = "compose-e2e-publish"
181+
const registryName = projectName + "-registry"
182+
c.RunDockerCmd(t, "run", "--name", registryName, "-P", "-d", "registry:3")
183+
port := c.RunDockerCmd(t, "inspect", "--format", `{{ (index (index .NetworkSettings.Ports "5000/tcp") 0).HostPort }}`, registryName).Stdout()
184+
registry := "localhost:" + strings.TrimSpace(port)
185+
t.Cleanup(func() {
186+
c.RunDockerCmd(t, "rm", "--force", registryName)
187+
})
188+
189+
cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/publish/oci/compose.yaml", "-f", "./fixtures/publish/oci/compose-override.yaml",
190+
"-p", projectName, "publish", "--with-env", "--yes", registry+"/test:test")
191+
icmd.RunCmd(cmd, func(cmd *icmd.Cmd) {
192+
cmd.Env = append(cmd.Env, "__TEST__INSECURE__REGISTRY__=true")
193+
}).Assert(t, icmd.Expected{ExitCode: 0})
194+
195+
// docker exec -it compose-e2e-publish-registry tree /var/lib/registry/docker/registry/v2/
196+
197+
cmd = c.NewDockerComposeCmd(t, "--verbose", "--project-name=oci", "-f", fmt.Sprintf("oci://%s/test:test", registry), "config")
198+
res := icmd.RunCmd(cmd, func(cmd *icmd.Cmd) {
199+
cmd.Env = append(cmd.Env,
200+
"XDG_CACHE_HOME="+t.TempDir(),
201+
"__TEST__INSECURE__REGISTRY__=true")
202+
})
203+
res.Assert(t, icmd.Expected{ExitCode: 0})
204+
assert.Equal(t, res.Stdout(), `name: oci
205+
services:
206+
app:
207+
environment:
208+
HELLO: WORLD
209+
image: alpine
210+
networks:
211+
default: null
212+
networks:
213+
default:
214+
name: oci_default
215+
`)
216+
}

pkg/remote/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func writeComposeFile(layer spec.Descriptor, i int, local string, content []byte
223223
return err
224224
}
225225
}
226-
f, err := os.Create(filepath.Join(local, file))
226+
f, err := os.OpenFile(filepath.Join(local, file), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
227227
if err != nil {
228228
return err
229229
}

0 commit comments

Comments
 (0)