From e15e02764ac53ef0749ebe17c6ca47a9f1635519 Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Tue, 6 Sep 2022 11:18:52 -0500 Subject: [PATCH] extracting the definition of the no spec project descriptor to a different file Signed-off-by: Juan Bustamante --- pkg/cnb/project_descriptor.go | 35 +++------------------------ pkg/cnb/project_descriptor_nospec.go | 36 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 pkg/cnb/project_descriptor_nospec.go diff --git a/pkg/cnb/project_descriptor.go b/pkg/cnb/project_descriptor.go index 17cfb6f70..953100331 100644 --- a/pkg/cnb/project_descriptor.go +++ b/pkg/cnb/project_descriptor.go @@ -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 { @@ -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 { @@ -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"` -} diff --git a/pkg/cnb/project_descriptor_nospec.go b/pkg/cnb/project_descriptor_nospec.go new file mode 100644 index 000000000..ad2589dca --- /dev/null +++ b/pkg/cnb/project_descriptor_nospec.go @@ -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, + }, + }, + }, + }, + } +}