Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit d4e0845

Browse files
eunomiendeloof
authored andcommitted
use relocation map on fixup
When the fixup is performed, if the image cannot be resolved try with the image in the relocation map if it exists. This way a pulled application can be pushed without to require to download locally and push all the images are they already exist in the registry See cnabio/cnab-to-oci#82 to have more details about the change. Signed-off-by: Yves Brissaud <[email protected]>
1 parent 1681023 commit d4e0845

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

e2e/relocation_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,44 @@ func TestRelocationMapRun(t *testing.T) {
9191
})
9292
}
9393

94+
func TestPushPulledApplication(t *testing.T) {
95+
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
96+
cmd := info.configuredCmd
97+
cfg := getDockerConfigDir(t, cmd)
98+
99+
path := filepath.Join("testdata", "local")
100+
ref := info.registryAddress + "/test/local:a-tag"
101+
bundlePath := filepath.Join(cfg, "app", "bundles", strings.Replace(info.registryAddress, ":", "_", 1), "test", "local", "_tags", "a-tag")
102+
103+
// Given an application pushed on a registry
104+
build(t, cmd, dockerCli, ref, path)
105+
cmd.Command = dockerCli.Command("app", "push", ref)
106+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
107+
// And given local images are removed
108+
cmd.Command = dockerCli.Command("rmi", "web", "local:1.1.0-beta1-invoc", "worker")
109+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
110+
// And given application files are remove
111+
assert.NilError(t, os.RemoveAll(bundlePath))
112+
_, err := os.Stat(filepath.Join(bundlePath, relocated.BundleFilename))
113+
assert.Assert(t, os.IsNotExist(err))
114+
115+
// And given application is pulled from the registry
116+
cmd.Command = dockerCli.Command("app", "pull", ref)
117+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
118+
119+
// Then the application can still be pushed
120+
cmd.Command = dockerCli.Command("app", "push", ref)
121+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
122+
123+
// If relocation map is removed
124+
assert.NilError(t, os.RemoveAll(filepath.Join(bundlePath, relocated.RelocationMapFilename)))
125+
126+
// Then the application cannot be pushed
127+
cmd.Command = dockerCli.Command("app", "push", ref)
128+
icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 1})
129+
})
130+
}
131+
94132
func TestRelocationMapOnInspect(t *testing.T) {
95133
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
96134
cmd := info.configuredCmd

internal/commands/push.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func pushBundle(dockerCli command.Cli, bndl *relocated.Bundle, cnabRef reference
102102
remotes.WithEventCallback(display.onEvent),
103103
remotes.WithAutoBundleUpdate(),
104104
remotes.WithPushImages(dockerCli.Client(), dockerCli.Out()),
105+
remotes.WithRelocationMap(bndl.RelocationMap),
105106
}
106107
// bundle fixup
107108
relocationMap, err := remotes.FixupBundle(context.Background(), bndl.Bundle, cnabRef, resolver, fixupOptions...)

0 commit comments

Comments
 (0)