Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
use relocation map to pull invocation image
Browse files Browse the repository at this point in the history
Invocation image can be relocated. The relocation map about services is now applied
at runtime by `cnab-run`, when running inside the invocation image.

This change updates the invocation image definition in the `driver.Operation`
using the relocation map if exists. So that the image can be pulled and run.

Signed-off-by: Yves Brissaud <[email protected]>
  • Loading branch information
eunomie committed Nov 27, 2019
1 parent e386e9a commit 9ad7667
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions internal/cnab/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,28 @@ func SetupDriver(installation *store.Installation, dockerCli command.Cli, opts *

func WithRelocationMap(installation *store.Installation) func(op *driver.Operation) error {
return func(op *driver.Operation) error {
data, err := json.Marshal(installation.RelocationMap)
if err != nil {
return errors.Wrap(err, "could not marshal relocation map")
if err := addRelocationMapToFiles(op, installation); err != nil {
return err
}
op.Files["/cnab/app/relocation-mapping.json"] = string(data)
relocateInvocationImage(op, installation)
return nil
}
}

func addRelocationMapToFiles(op *driver.Operation, installation *store.Installation) error {
data, err := json.Marshal(installation.RelocationMap)
if err != nil {
return errors.Wrap(err, "could not marshal relocation map")
}
op.Files["/cnab/app/relocation-mapping.json"] = string(data)

return nil
}

func relocateInvocationImage(op *driver.Operation, installation *store.Installation) {
invocImage := op.Image
if relocatedImage, ok := installation.RelocationMap[invocImage.Image]; ok {
invocImage.Image = relocatedImage
op.Image = invocImage
}
}

0 comments on commit 9ad7667

Please sign in to comment.