Skip to content

Commit

Permalink
extracting the definition of the no spec project descriptor to a diff…
Browse files Browse the repository at this point in the history
…erent file

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed Sep 6, 2022
1 parent 381d506 commit e15e027
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
35 changes: 3 additions & 32 deletions pkg/cnb/project_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ func parseProjectDescriptor(file string, logger *log.Logger) (descriptorV2, erro
if _, err := toml.DecodeFile(file, &d); err != nil {
var dV2NoSpec descriptorV2NoSpec
if _, err2 := toml.DecodeFile(file, &dV2NoSpec); err2 != nil {
logger.Println(fmt.Sprintf("warning: project descriptor '%s' could not be parsed, error '%v'", file, err))
return descriptorV2{}, err2
}
d = v2NoSpecToV2(dV2NoSpec)
logger.Println(fmt.Sprintf("warning: using key io.buildpacks.env to set environment variables is " +
"not defined in the specification. We recommend switching to io.buildpacks.build.env instead"))
}

switch sv := d.Project.SchemaVersion; sv {
Expand Down Expand Up @@ -87,23 +90,6 @@ func v1ToV2(v1 descriptorV1) descriptorV2 {
}
}

func v2NoSpecToV2(v2 descriptorV2NoSpec) descriptorV2 {
return descriptorV2{
Project: v2.Project,
IO: ioTable{
Buildpacks: cnbTableV2{
build: v2.IO.Buildpacks.build,
Group: v2.IO.Buildpacks.Group,
buildEnvVariableV2: buildEnvVariableV2{
BuildEnv: buildEnvVariable{
Env: v2.IO.Buildpacks.Env,
},
},
},
},
}
}

func processFiles(appDir string, d build) error {
fileFilter, err := getFileFilter(d)
if err != nil {
Expand Down Expand Up @@ -209,18 +195,3 @@ type cnbTableV1 struct {
Env []envVariable `toml:"env"`
Buildpacks []buildpack `toml:"buildpacks"`
}

type descriptorV2NoSpec struct {
Project project `toml:"_"`
IO ioTableNoSpec `toml:"io"`
}

type ioTableNoSpec struct {
Buildpacks cnbTableV2NoSpec `toml:"buildpacks"`
}

type cnbTableV2NoSpec struct {
build `toml:",inline"`
Env []envVariable `toml:"env"`
Group []buildpack `toml:"group"`
}
36 changes: 36 additions & 0 deletions pkg/cnb/project_descriptor_nospec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cnb

// A descriptorV2NoSpec represents a project descriptor that uses the key io.buildpacks.env to set environment variables
// This key is not defined in the Project Descriptor V2, but was added by mistake in the PR https://github.com/pivotal/kpack/pull/810
// and this struct is created to guarantee compatibility
type descriptorV2NoSpec struct {
Project project `toml:"_"`
IO ioTableNoSpec `toml:"io"`
}

type ioTableNoSpec struct {
Buildpacks cnbTableV2NoSpec `toml:"buildpacks"`
}

type cnbTableV2NoSpec struct {
build `toml:",inline"`
Env []envVariable `toml:"env"`
Group []buildpack `toml:"group"`
}

func v2NoSpecToV2(v2 descriptorV2NoSpec) descriptorV2 {
return descriptorV2{
Project: v2.Project,
IO: ioTable{
Buildpacks: cnbTableV2{
build: v2.IO.Buildpacks.build,
Group: v2.IO.Buildpacks.Group,
buildEnvVariableV2: buildEnvVariableV2{
BuildEnv: buildEnvVariable{
Env: v2.IO.Buildpacks.Env,
},
},
},
},
}
}

0 comments on commit e15e027

Please sign in to comment.