github.com/jdolitsky/cnab-go@v0.7.1-beta1/action/install.go (about)

     1  package action
     2  
     3  import (
     4  	"github.com/deislabs/cnab-go/claim"
     5  	"github.com/deislabs/cnab-go/credentials"
     6  	"github.com/deislabs/cnab-go/driver"
     7  )
     8  
     9  // Install describes an installation action
    10  type Install struct {
    11  	Driver driver.Driver // Needs to be more than a string
    12  }
    13  
    14  // Run performs an installation and updates the Claim accordingly
    15  func (i *Install) Run(c *claim.Claim, creds credentials.Set, opCfgs ...OperationConfigFunc) error {
    16  	invocImage, err := selectInvocationImage(i.Driver, c)
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	op, err := opFromClaim(claim.ActionInstall, stateful, c, invocImage, creds)
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	err = OperationConfigs(opCfgs).ApplyConfig(op)
    27  	if err != nil {
    28  		return err
    29  	}
    30  
    31  	opResult, err := i.Driver.Run(op)
    32  
    33  	// update outputs in claim even if there were errors so users can see the output files.
    34  	outputErrors := setOutputsOnClaim(c, opResult.Outputs)
    35  
    36  	if err != nil {
    37  		c.Update(claim.ActionInstall, claim.StatusFailure)
    38  		c.Result.Message = err.Error()
    39  		return err
    40  	}
    41  	c.Update(claim.ActionInstall, claim.StatusSuccess)
    42  
    43  	return outputErrors
    44  }