Skip to content

Commit

Permalink
Apply relocation mapping to invocation image
Browse files Browse the repository at this point in the history
  • Loading branch information
glyn committed Jul 10, 2019
1 parent 465d589 commit 6369eeb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/duffle/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -133,14 +134,39 @@ func (d *driverWithRelocationMapping) Run(op *driver.Operation) error {
// if there is a relocation mapping, ensure it is mounted
if d.relMapping != "" {
op.Files["/cnab/app/relocation-mapping.json"] = d.relMapping

var err error
op, err = d.relocateInvocationImage(op)
if err != nil {
return err
}
}

return d.driver.Run(op)
}

func (d *driverWithRelocationMapping) Handles(it string) bool {
return d.driver.Handles(it)
}

func (d *driverWithRelocationMapping) relocateInvocationImage(op *driver.Operation) (*driver.Operation, error) {
relMap := make(map[string]string)
err := json.Unmarshal([]byte(d.relMapping), &relMap)
if err != nil {
return nil, err
}

// TODO: copy op before mutating it

var ok bool
op.Image, ok = relMap[op.Image]
if !ok {
return nil, fmt.Errorf("invocation image %s not present in relocation mapping %v", op.Image, relMap)
}

return op, nil
}

func loadRelMapping(relMap string) (string, error) {
if relMap != "" {
data, err := ioutil.ReadFile(relMap)
Expand Down

0 comments on commit 6369eeb

Please sign in to comment.