diff --git a/vendor/github.com/deislabs/cnab-go/action/action.go b/vendor/github.com/deislabs/cnab-go/action/action.go index fd95a6ca..5faec05a 100644 --- a/vendor/github.com/deislabs/cnab-go/action/action.go +++ b/vendor/github.com/deislabs/cnab-go/action/action.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "io" "math" "strings" @@ -28,7 +27,7 @@ const stateful = false // - status type Action interface { // Run an action, and record the status in the given claim - Run(*claim.Claim, credentials.Set, io.Writer) error + Run(*claim.Claim, credentials.Set, ...OperationConfigFunc) error } func golangTypeToJSONType(value interface{}) (string, error) { @@ -188,7 +187,7 @@ func appliesToAction(action string, parameter bundle.Parameter) bool { return false } -func opFromClaim(action string, stateless bool, c *claim.Claim, ii bundle.InvocationImage, creds credentials.Set, w io.Writer) (*driver.Operation, error) { +func opFromClaim(action string, stateless bool, c *claim.Claim, ii bundle.InvocationImage, creds credentials.Set) (*driver.Operation, error) { env, files, err := creds.Expand(c.Bundle, stateless) if err != nil { return nil, err @@ -227,13 +226,11 @@ func opFromClaim(action string, stateless bool, c *claim.Claim, ii bundle.Invoca Action: action, Installation: c.Name, Parameters: c.Parameters, - Image: ii.Image, - ImageType: ii.ImageType, + Image: ii, Revision: c.Revision, Environment: env, Files: files, Outputs: outputs, - Out: w, }, nil } diff --git a/vendor/github.com/deislabs/cnab-go/action/install.go b/vendor/github.com/deislabs/cnab-go/action/install.go index ddee71fe..b89648a5 100644 --- a/vendor/github.com/deislabs/cnab-go/action/install.go +++ b/vendor/github.com/deislabs/cnab-go/action/install.go @@ -1,8 +1,6 @@ package action import ( - "io" - "github.com/deislabs/cnab-go/claim" "github.com/deislabs/cnab-go/credentials" "github.com/deislabs/cnab-go/driver" @@ -14,13 +12,18 @@ type Install struct { } // Run performs an installation and updates the Claim accordingly -func (i *Install) Run(c *claim.Claim, creds credentials.Set, w io.Writer) error { +func (i *Install) Run(c *claim.Claim, creds credentials.Set, opCfgs ...OperationConfigFunc) error { invocImage, err := selectInvocationImage(i.Driver, c) if err != nil { return err } - op, err := opFromClaim(claim.ActionInstall, stateful, c, invocImage, creds, w) + op, err := opFromClaim(claim.ActionInstall, stateful, c, invocImage, creds) + if err != nil { + return err + } + + err = OperationConfigs(opCfgs).ApplyConfig(op) if err != nil { return err } diff --git a/vendor/github.com/deislabs/cnab-go/action/operation_configs.go b/vendor/github.com/deislabs/cnab-go/action/operation_configs.go new file mode 100644 index 00000000..e4babcad --- /dev/null +++ b/vendor/github.com/deislabs/cnab-go/action/operation_configs.go @@ -0,0 +1,26 @@ +package action + +import ( + "github.com/deislabs/cnab-go/driver" +) + +// OperationConfigFunc is a configuration function that can be applied to an +// operation. +type OperationConfigFunc func(op *driver.Operation) error + +// OperationConfigs is a set of configuration functions that can be applied as a +// unit to an operation. +type OperationConfigs []OperationConfigFunc + +// ApplyConfig safely applies the configuration function to the operation, if +// defined, and stops immediately upon the first error. +func (cfgs OperationConfigs) ApplyConfig(op *driver.Operation) error { + var err error + for _, cfg := range cfgs { + err = cfg(op) + if err != nil { + return err + } + } + return nil +} diff --git a/vendor/github.com/deislabs/cnab-go/action/run_custom.go b/vendor/github.com/deislabs/cnab-go/action/run_custom.go index b55f7df0..ccd554f4 100644 --- a/vendor/github.com/deislabs/cnab-go/action/run_custom.go +++ b/vendor/github.com/deislabs/cnab-go/action/run_custom.go @@ -2,7 +2,6 @@ package action import ( "errors" - "io" "github.com/deislabs/cnab-go/claim" "github.com/deislabs/cnab-go/credentials" @@ -28,7 +27,7 @@ type RunCustom struct { var blockedActions = map[string]struct{}{"install": {}, "uninstall": {}, "upgrade": {}} // Run executes a status action in an image -func (i *RunCustom) Run(c *claim.Claim, creds credentials.Set, w io.Writer) error { +func (i *RunCustom) Run(c *claim.Claim, creds credentials.Set, opCfgs ...OperationConfigFunc) error { if _, ok := blockedActions[i.Action]; ok { return ErrBlockedAction } @@ -43,7 +42,12 @@ func (i *RunCustom) Run(c *claim.Claim, creds credentials.Set, w io.Writer) erro return err } - op, err := opFromClaim(i.Action, actionDef.Stateless, c, invocImage, creds, w) + op, err := opFromClaim(i.Action, actionDef.Stateless, c, invocImage, creds) + if err != nil { + return err + } + + err = OperationConfigs(opCfgs).ApplyConfig(op) if err != nil { return err } diff --git a/vendor/github.com/deislabs/cnab-go/action/status.go b/vendor/github.com/deislabs/cnab-go/action/status.go index ba420cc0..d05829f3 100644 --- a/vendor/github.com/deislabs/cnab-go/action/status.go +++ b/vendor/github.com/deislabs/cnab-go/action/status.go @@ -1,8 +1,6 @@ package action import ( - "io" - "github.com/deislabs/cnab-go/claim" "github.com/deislabs/cnab-go/credentials" "github.com/deislabs/cnab-go/driver" @@ -14,13 +12,18 @@ type Status struct { } // Run executes a status action in an image -func (i *Status) Run(c *claim.Claim, creds credentials.Set, w io.Writer) error { +func (i *Status) Run(c *claim.Claim, creds credentials.Set, opCfgs ...OperationConfigFunc) error { invocImage, err := selectInvocationImage(i.Driver, c) if err != nil { return err } - op, err := opFromClaim(claim.ActionStatus, stateful, c, invocImage, creds, w) + op, err := opFromClaim(claim.ActionStatus, stateful, c, invocImage, creds) + if err != nil { + return err + } + + err = OperationConfigs(opCfgs).ApplyConfig(op) if err != nil { return err } diff --git a/vendor/github.com/deislabs/cnab-go/action/uninstall.go b/vendor/github.com/deislabs/cnab-go/action/uninstall.go index db96d690..4744b623 100644 --- a/vendor/github.com/deislabs/cnab-go/action/uninstall.go +++ b/vendor/github.com/deislabs/cnab-go/action/uninstall.go @@ -1,8 +1,6 @@ package action import ( - "io" - "github.com/deislabs/cnab-go/claim" "github.com/deislabs/cnab-go/credentials" "github.com/deislabs/cnab-go/driver" @@ -14,13 +12,18 @@ type Uninstall struct { } // Run performs the uninstall steps and updates the Claim -func (u *Uninstall) Run(c *claim.Claim, creds credentials.Set, w io.Writer) error { +func (u *Uninstall) Run(c *claim.Claim, creds credentials.Set, opCfgs ...OperationConfigFunc) error { invocImage, err := selectInvocationImage(u.Driver, c) if err != nil { return err } - op, err := opFromClaim(claim.ActionUninstall, stateful, c, invocImage, creds, w) + op, err := opFromClaim(claim.ActionUninstall, stateful, c, invocImage, creds) + if err != nil { + return err + } + + err = OperationConfigs(opCfgs).ApplyConfig(op) if err != nil { return err } diff --git a/vendor/github.com/deislabs/cnab-go/action/upgrade.go b/vendor/github.com/deislabs/cnab-go/action/upgrade.go index 0655d4d9..c04d88ca 100644 --- a/vendor/github.com/deislabs/cnab-go/action/upgrade.go +++ b/vendor/github.com/deislabs/cnab-go/action/upgrade.go @@ -1,8 +1,6 @@ package action import ( - "io" - "github.com/deislabs/cnab-go/claim" "github.com/deislabs/cnab-go/credentials" "github.com/deislabs/cnab-go/driver" @@ -14,13 +12,18 @@ type Upgrade struct { } // Run performs the upgrade steps and updates the Claim -func (u *Upgrade) Run(c *claim.Claim, creds credentials.Set, w io.Writer) error { +func (u *Upgrade) Run(c *claim.Claim, creds credentials.Set, opCfgs ...OperationConfigFunc) error { invocImage, err := selectInvocationImage(u.Driver, c) if err != nil { return err } - op, err := opFromClaim(claim.ActionUpgrade, stateful, c, invocImage, creds, w) + op, err := opFromClaim(claim.ActionUpgrade, stateful, c, invocImage, creds) + if err != nil { + return err + } + + err = OperationConfigs(opCfgs).ApplyConfig(op) if err != nil { return err } diff --git a/vendor/github.com/deislabs/cnab-go/bundle/definition/schema.go b/vendor/github.com/deislabs/cnab-go/bundle/definition/schema.go index 6b3e7dfb..e756cc34 100644 --- a/vendor/github.com/deislabs/cnab-go/bundle/definition/schema.go +++ b/vendor/github.com/deislabs/cnab-go/bundle/definition/schema.go @@ -31,19 +31,19 @@ type Schema struct { Else *Schema `json:"else,omitempty" yaml:"else,omitempty"` Enum []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"` Examples []interface{} `json:"examples,omitempty" yaml:"examples,omitempty"` - ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"` - ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"` + ExclusiveMaximum *int `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"` + ExclusiveMinimum *int `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"` Format string `json:"format,omitempty" yaml:"format,omitempty"` If *Schema `json:"if,omitempty" yaml:"if,omitempty"` //Items can be a Schema or an Array of Schema :( Items interface{} `json:"items,omitempty" yaml:"items,omitempty"` - Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"` - MaxLength *float64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"` - MinItems *float64 `json:"minItems,omitempty" yaml:"minItems,omitempty"` - MinLength *float64 `json:"minLength,omitempty" yaml:"minLength,omitempty"` - MinProperties *float64 `json:"minProperties,omitempty" yaml:"minProperties,omitempty"` - Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"` - MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"` + Maximum *int `json:"maximum,omitempty" yaml:"maximum,omitempty"` + MaxLength *int `json:"maxLength,omitempty" yaml:"maxLength,omitempty"` + MinItems *int `json:"minItems,omitempty" yaml:"minItems,omitempty"` + MinLength *int `json:"minLength,omitempty" yaml:"minLength,omitempty"` + MinProperties *int `json:"minProperties,omitempty" yaml:"minProperties,omitempty"` + Minimum *int `json:"minimum,omitempty" yaml:"minimum,omitempty"` + MultipleOf *int `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"` Not *Schema `json:"not,omitempty" yaml:"not,omitempty"` OneOf *Schema `json:"oneOf,omitempty" yaml:"oneOf,omitempty"` @@ -121,12 +121,6 @@ func (s *Schema) ConvertValue(val string) (interface{}, error) { switch dataType { case "string": return val, nil - case "number": - num, err := strconv.ParseFloat(val, 64) - if err != nil { - return nil, errors.Wrapf(err, "unable to convert %s to number", val) - } - return num, nil case "integer": return strconv.Atoi(val) case "boolean": diff --git a/vendor/github.com/deislabs/cnab-go/driver/docker/docker.go b/vendor/github.com/deislabs/cnab-go/driver/docker/docker.go index 181c9851..0e8433bf 100644 --- a/vendor/github.com/deislabs/cnab-go/driver/docker/docker.go +++ b/vendor/github.com/deislabs/cnab-go/driver/docker/docker.go @@ -137,7 +137,7 @@ func (d *Driver) exec(op *driver.Operation) (driver.OperationResult, error) { return driver.OperationResult{}, nil } if d.config["PULL_ALWAYS"] == "1" { - if err := pullImage(ctx, cli, op.Image); err != nil { + if err := pullImage(ctx, cli, op.Image.Image); err != nil { return driver.OperationResult{}, err } } @@ -147,7 +147,7 @@ func (d *Driver) exec(op *driver.Operation) (driver.OperationResult, error) { } cfg := &container.Config{ - Image: op.Image, + Image: op.Image.Image, Env: env, Entrypoint: strslice.StrSlice{"/cnab/app/run"}, AttachStderr: true, @@ -164,8 +164,8 @@ func (d *Driver) exec(op *driver.Operation) (driver.OperationResult, error) { resp, err := cli.Client().ContainerCreate(ctx, cfg, hostCfg, nil, "") switch { case client.IsErrNotFound(err): - fmt.Fprintf(cli.Err(), "Unable to find image '%s' locally\n", op.Image) - if err := pullImage(ctx, cli, op.Image); err != nil { + fmt.Fprintf(cli.Err(), "Unable to find image '%s' locally\n", op.Image.Image) + if err := pullImage(ctx, cli, op.Image.Image); err != nil { return driver.OperationResult{}, err } if resp, err = cli.Client().ContainerCreate(ctx, cfg, hostCfg, nil, ""); err != nil { diff --git a/vendor/github.com/deislabs/cnab-go/driver/driver.go b/vendor/github.com/deislabs/cnab-go/driver/driver.go index 3039b416..d338ce25 100644 --- a/vendor/github.com/deislabs/cnab-go/driver/driver.go +++ b/vendor/github.com/deislabs/cnab-go/driver/driver.go @@ -4,6 +4,7 @@ import ( "fmt" "io" + "github.com/deislabs/cnab-go/bundle" "github.com/docker/go/canonical/json" ) @@ -26,9 +27,7 @@ type Operation struct { // Parameters are the parameters to be injected into the container Parameters map[string]interface{} `json:"parameters"` // Image is the invocation image - Image string `json:"image"` - // ImageType is the type of image. - ImageType string `json:"image_type"` + Image bundle.InvocationImage `json:"image"` // Environment contains environment variables that should be injected into the invocation image Environment map[string]string `json:"environment"` // Files contains files that should be injected into the invocation image. diff --git a/vendor/github.com/deislabs/cnab-go/driver/kubernetes/kubernetes.go b/vendor/github.com/deislabs/cnab-go/driver/kubernetes/kubernetes.go index ef18cd6c..b77aef12 100644 --- a/vendor/github.com/deislabs/cnab-go/driver/kubernetes/kubernetes.go +++ b/vendor/github.com/deislabs/cnab-go/driver/kubernetes/kubernetes.go @@ -12,6 +12,7 @@ import ( // Convert transitive deps to direct deps so that we can use constraints in our Gopkg.toml _ "github.com/Azure/go-autorest/autorest" + "github.com/deislabs/cnab-go/bundle" "github.com/deislabs/cnab-go/driver" batchv1 "k8s.io/api/batch/v1" v1 "k8s.io/api/core/v1" @@ -152,7 +153,7 @@ func (k *Driver) Run(op *driver.Operation) (driver.OperationResult, error) { } container := v1.Container{ Name: k8sContainerName, - Image: op.Image, + Image: imageWithDigest(op.Image), Command: []string{"/cnab/app/run"}, Resources: v1.ResourceRequirements{ Limits: v1.ResourceList{ @@ -378,3 +379,10 @@ func homeDir() string { } return os.Getenv("USERPROFILE") // windows } + +func imageWithDigest(img bundle.InvocationImage) string { + if img.Digest == "" { + return img.Image + } + return img.Image + "@" + img.Digest +}