@@ -2,20 +2,23 @@ package cnab
2
2
3
3
import (
4
4
"bytes"
5
+ "encoding/json"
5
6
"io"
6
7
"os"
7
8
"strings"
8
9
10
+ "github.com/pkg/errors"
11
+
9
12
"github.com/docker/app/internal/cliopts"
10
- store2 "github.com/docker/app/internal/store"
13
+ "github.com/docker/app/internal/store"
11
14
12
15
"github.com/deislabs/cnab-go/claim"
13
16
"github.com/deislabs/cnab-go/driver"
14
17
dockerDriver "github.com/deislabs/cnab-go/driver/docker"
15
18
"github.com/docker/app/internal"
16
19
"github.com/docker/cli/cli/command"
17
20
"github.com/docker/cli/cli/context/docker"
18
- "github.com/docker/cli/cli/context/store"
21
+ cliContext "github.com/docker/cli/cli/context/store"
19
22
"github.com/docker/docker/api/types/container"
20
23
"github.com/docker/docker/api/types/mount"
21
24
)
@@ -39,7 +42,7 @@ func RequiredClaimBindMount(c claim.Claim, dockerCli command.Cli) (BindMount, er
39
42
40
43
// RequiredBindMount Returns the path required to bind mount when running
41
44
// the invocation image.
42
- func RequiredBindMount (targetContextName string , targetOrchestrator string , s store .Store ) (BindMount , error ) {
45
+ func RequiredBindMount (targetContextName string , targetOrchestrator string , s cliContext .Store ) (BindMount , error ) {
43
46
if targetOrchestrator == "kubernetes" {
44
47
return BindMount {}, nil
45
48
}
@@ -119,7 +122,7 @@ func prepareDriver(dockerCli command.Cli, bindMount BindMount, stdout io.Writer)
119
122
return d , errBuf
120
123
}
121
124
122
- func SetupDriver (installation * store2 .Installation , dockerCli command.Cli , opts * cliopts.InstallerContextOptions , stdout io.Writer ) (driver.Driver , * bytes.Buffer , error ) {
125
+ func SetupDriver (installation * store .Installation , dockerCli command.Cli , opts * cliopts.InstallerContextOptions , stdout io.Writer ) (driver.Driver , * bytes.Buffer , error ) {
123
126
dockerCli , err := opts .SetInstallerContext (dockerCli )
124
127
if err != nil {
125
128
return nil , nil , err
@@ -131,3 +134,31 @@ func SetupDriver(installation *store2.Installation, dockerCli command.Cli, opts
131
134
driverImpl , errBuf := prepareDriver (dockerCli , bind , stdout )
132
135
return driverImpl , errBuf , nil
133
136
}
137
+
138
+ func WithRelocationMap (installation * store.Installation ) func (op * driver.Operation ) error {
139
+ return func (op * driver.Operation ) error {
140
+ if err := addRelocationMapToFiles (op , installation ); err != nil {
141
+ return err
142
+ }
143
+ relocateInvocationImage (op , installation )
144
+ return nil
145
+ }
146
+ }
147
+
148
+ func addRelocationMapToFiles (op * driver.Operation , installation * store.Installation ) error {
149
+ data , err := json .Marshal (installation .RelocationMap )
150
+ if err != nil {
151
+ return errors .Wrap (err , "could not marshal relocation map" )
152
+ }
153
+ op .Files ["/cnab/app/relocation-mapping.json" ] = string (data )
154
+
155
+ return nil
156
+ }
157
+
158
+ func relocateInvocationImage (op * driver.Operation , installation * store.Installation ) {
159
+ invocImage := op .Image
160
+ if relocatedImage , ok := installation .RelocationMap [invocImage .Image ]; ok {
161
+ invocImage .Image = relocatedImage
162
+ op .Image = invocImage
163
+ }
164
+ }
0 commit comments