Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Apply relocation mapping to invocation image (#798)
Browse files Browse the repository at this point in the history
Apply relocation mapping to invocation image

Fixes #785
  • Loading branch information
glyn authored and silvin-lubecki committed Jul 18, 2019
1 parent 922b6e6 commit 85156ca
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion 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 @@ -130,17 +131,39 @@ type driverWithRelocationMapping struct {
}

func (d *driverWithRelocationMapping) Run(op *driver.Operation) error {
// if there is a relocation mapping, ensure it is mounted
// if there is a relocation mapping, ensure it is mounted and relocate the invocation image
if d.relMapping != "" {
op.Files["/cnab/app/relocation-mapping.json"] = d.relMapping

var err error
op.Image, err = d.relocateImage(op.Image)
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) relocateImage(im string) (string, error) {
relMap := make(map[string]string)
err := json.Unmarshal([]byte(d.relMapping), &relMap)
if err != nil {
return "", fmt.Errorf("failed to unmarshal relocation mapping: %v", err)
}

mapped, ok := relMap[im]
if !ok {
return "", fmt.Errorf("invocation image %s not present in relocation mapping %v", im, relMap)
}

return mapped, nil
}

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

0 comments on commit 85156ca

Please sign in to comment.