From 9ad766749d826371fc236115c014005c8a344cda Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Mon, 25 Nov 2019 17:50:53 +0100 Subject: [PATCH] use relocation map to pull invocation image 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 --- internal/cnab/driver.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/cnab/driver.go b/internal/cnab/driver.go index 907a0faec..3505b6c6c 100644 --- a/internal/cnab/driver.go +++ b/internal/cnab/driver.go @@ -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 + } +}