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

Commit 5361689

Browse files
committed
embed relocation map instead of applying it
Embed the relocation map inside `/cnab/app/relocation-mapping.json` and do not touch the bundle definition. Signed-off-by: Yves Brissaud <[email protected]>
1 parent e404042 commit 5361689

File tree

9 files changed

+20
-92
lines changed

9 files changed

+20
-92
lines changed

internal/cnab/driver.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package cnab
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"io"
67
"os"
78
"strings"
89

10+
"github.com/pkg/errors"
11+
912
"github.com/docker/app/internal/cliopts"
1013
"github.com/docker/app/internal/store"
1114

@@ -131,3 +134,14 @@ func SetupDriver(installation *store.Installation, dockerCli command.Cli, opts *
131134
driverImpl, errBuf := prepareDriver(dockerCli, bind, stdout)
132135
return driverImpl, errBuf, nil
133136
}
137+
138+
func WithRelocationMap(installation *store.Installation) func(op *driver.Operation) error {
139+
return func(op *driver.Operation) error {
140+
data, err := json.Marshal(installation.RelocationMap)
141+
if err != nil {
142+
return errors.Wrap(err, "could not marshal relocation map")
143+
}
144+
op.Files["/cnab/app/relocation-mapping.json"] = string(data)
145+
return nil
146+
}
147+
}

internal/commands/image/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, inst
8888
}
8989

9090
installation.SetParameter(internal.ParameterInspectFormatName, format)
91-
if err = a.Run(&installation.Claim, nil); err != nil {
91+
if err = a.Run(&installation.Claim, nil, cnab.WithRelocationMap(installation)); err != nil {
9292
return fmt.Errorf("inspect failed: %s\n%s", err, errBuf)
9393
}
9494
} else {

internal/commands/image/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions, instal
7070
}
7171
installation.Parameters[internal.ParameterRenderFormatName] = opts.formatDriver
7272

73-
if err := action.Run(&installation.Claim, nil, cfgFunc); err != nil {
73+
if err := action.Run(&installation.Claim, nil, cfgFunc, cnab.WithRelocationMap(installation)); err != nil {
7474
return fmt.Errorf("render failed: %s\n%s", err, errBuf)
7575
}
7676
return nil

internal/commands/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
7373
} else {
7474
return fmt.Errorf("inspect failed: status action is not supported by the App")
7575
}
76-
if err := a.Run(&installation.Claim, creds); err != nil {
76+
if err := a.Run(&installation.Claim, creds, cnab.WithRelocationMap(installation)); err != nil {
7777
return fmt.Errorf("inspect failed: %s\n%s", err, errBuf)
7878
}
7979

internal/commands/remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func runRemove(dockerCli command.Cli, installationName string, opts removeOption
8282
op.Out = dockerCli.Out()
8383
return nil
8484
}
85-
if err := uninst.Run(&installation.Claim, creds, cfgFunc); err != nil {
85+
if err := uninst.Run(&installation.Claim, creds, cfgFunc, cnab.WithRelocationMap(installation)); err != nil {
8686
if err2 := installationStore.Store(installation); err2 != nil {
8787
return fmt.Errorf("%s while %s", err2, errBuf)
8888
}

internal/commands/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func runBundle(dockerCli command.Cli, bndl *relocated.Bundle, opts runOptions, i
158158
op.Out = dockerCli.Out()
159159
return nil
160160
}
161-
err = inst.Run(&installation.Claim, creds, cfgFunc)
161+
err = inst.Run(&installation.Claim, creds, cfgFunc, cnab.WithRelocationMap(installation))
162162
}
163163
// Even if the installation failed, the installation is persisted with its failure status,
164164
// so any installation needs a clean uninstallation.

internal/commands/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func runUpdate(dockerCli command.Cli, installationName string, opts updateOption
8989
op.Out = dockerCli.Out()
9090
return nil
9191
}
92-
err = u.Run(&installation.Claim, creds, cfgFunc)
92+
err = u.Run(&installation.Claim, creds, cfgFunc, cnab.WithRelocationMap(installation))
9393
err2 := installationStore.Store(installation)
9494
if err != nil {
9595
return fmt.Errorf("Update failed: %s\n%s", err, errBuf)

internal/store/installation.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func NewInstallation(name string, reference string, bndl *relocated.Bundle) (*In
3939
Reference: reference,
4040
RelocationMap: bndl.RelocationMap,
4141
}
42-
i.applyRelocationMap()
4342

4443
return i, nil
4544
}
@@ -52,21 +51,6 @@ func (i Installation) SetParameter(name string, value string) {
5251
}
5352
}
5453

55-
func (i *Installation) applyRelocationMap() {
56-
for idx, def := range i.Bundle.InvocationImages {
57-
if img, ok := i.RelocationMap[def.Image]; ok {
58-
def.Image = img
59-
i.Bundle.InvocationImages[idx] = def
60-
}
61-
}
62-
for name, def := range i.Bundle.Images {
63-
if img, ok := i.RelocationMap[def.Image]; ok {
64-
def.Image = img
65-
i.Bundle.Images[name] = def
66-
}
67-
}
68-
}
69-
7054
var _ InstallationStore = &installationStore{}
7155

7256
type installationStore struct {

internal/store/installation_test.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import (
44
"os"
55
"testing"
66

7-
"github.com/docker/app/internal/relocated"
8-
9-
"github.com/deislabs/cnab-go/bundle"
10-
"github.com/docker/cnab-to-oci/relocation"
11-
127
"github.com/deislabs/cnab-go/claim"
138
"gotest.tools/assert"
149
"gotest.tools/fs"
@@ -43,68 +38,3 @@ func TestStoreAndReadInstallation(t *testing.T) {
4338
assert.NilError(t, err)
4439
assert.DeepEqual(t, expectedInstallation, actualInstallation)
4540
}
46-
47-
func TestApplyingRelocationMap(t *testing.T) {
48-
installation, _ := NewInstallation("name", "reference", &relocated.Bundle{
49-
Bundle: &bundle.Bundle{
50-
InvocationImages: []bundle.InvocationImage{
51-
{
52-
BaseImage: bundle.BaseImage{
53-
Image: "localimage:1.0-invoc",
54-
},
55-
},
56-
},
57-
Images: map[string]bundle.Image{
58-
"svc1": {
59-
BaseImage: bundle.BaseImage{
60-
Image: "svc-1:local",
61-
},
62-
},
63-
"redis": {
64-
BaseImage: bundle.BaseImage{
65-
Image: "redis:latest",
66-
},
67-
},
68-
"hello": {
69-
BaseImage: bundle.BaseImage{
70-
Image: "http-echo",
71-
},
72-
},
73-
},
74-
},
75-
RelocationMap: relocation.ImageRelocationMap{
76-
"localimage:1.0-invoc": "docker.io/repo/app:tag@sha256:9f9426498125d4017bdbdc861451bd447b9cb6d0c7a790093a65f508f45a1dd4",
77-
"svc-1:local": "docker.io/repo/app:tag@sha256:d14de6677360066fcb302892bf288b8a907fddb264f587189ea17e691284e58c",
78-
"redis:latest": "docker.io/repo/app:tag@sha256:e6e61849494c55a096cb48f7efb262271a50e2452b6a9e3553cf26f519f01d23",
79-
},
80-
})
81-
82-
expectedBundle := &bundle.Bundle{
83-
InvocationImages: []bundle.InvocationImage{
84-
{
85-
BaseImage: bundle.BaseImage{
86-
Image: "docker.io/repo/app:tag@sha256:9f9426498125d4017bdbdc861451bd447b9cb6d0c7a790093a65f508f45a1dd4",
87-
},
88-
},
89-
},
90-
Images: map[string]bundle.Image{
91-
"svc1": {
92-
BaseImage: bundle.BaseImage{
93-
Image: "docker.io/repo/app:tag@sha256:d14de6677360066fcb302892bf288b8a907fddb264f587189ea17e691284e58c",
94-
},
95-
},
96-
"redis": {
97-
BaseImage: bundle.BaseImage{
98-
Image: "docker.io/repo/app:tag@sha256:e6e61849494c55a096cb48f7efb262271a50e2452b6a9e3553cf26f519f01d23",
99-
},
100-
},
101-
"hello": {
102-
BaseImage: bundle.BaseImage{
103-
Image: "http-echo",
104-
},
105-
},
106-
},
107-
}
108-
109-
assert.DeepEqual(t, expectedBundle, installation.Bundle)
110-
}

0 commit comments

Comments
 (0)