You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
* Add pre and post buildpacks Co-authored-by: Johannes Dillmann <j.dillmann@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com> Co-authored-by: Pavel Busko <pavel.busko@sap.com> * fix integration tests Co-authored-by: Pavel Busko <pavel.busko@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com> * simplify if clauses Co-authored-by: Pavel Busko <pavel.busko@sap.com> --------- Co-authored-by: Johannes Dillmann <j.dillmann@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
// Source: https://github.com/buildpacks/pack/blob/main/pkg/project/v02/project.go
|
|
package v02
|
|
|
|
import (
|
|
"github.com/BurntSushi/toml"
|
|
"github.com/SAP/jenkins-library/pkg/cnbutils/project/types"
|
|
"github.com/buildpacks/lifecycle/api"
|
|
)
|
|
|
|
type Buildpacks struct {
|
|
Include []string `toml:"include"`
|
|
Exclude []string `toml:"exclude"`
|
|
Group []types.Buildpack `toml:"group"`
|
|
Env Env `toml:"env"`
|
|
Build Build `toml:"build"`
|
|
Builder string `toml:"builder"`
|
|
Pre types.GroupAddition `toml:"pre"`
|
|
Post types.GroupAddition `toml:"post"`
|
|
}
|
|
|
|
type Build struct {
|
|
Env []types.EnvVar `toml:"env"`
|
|
}
|
|
|
|
// Env is deprecated: use `[[io.buildpacks.build.env]]` instead. see https://github.com/buildpacks/pack/pull/1479
|
|
type Env struct {
|
|
Build []types.EnvVar `toml:"build"`
|
|
}
|
|
|
|
type Project struct {
|
|
ID string `toml:"id"`
|
|
Name string `toml:"name"`
|
|
Licenses []types.License `toml:"licenses"`
|
|
Metadata map[string]interface{} `toml:"metadata"`
|
|
SchemaVersion string `toml:"schema-version"`
|
|
}
|
|
|
|
type IO struct {
|
|
Buildpacks Buildpacks `toml:"buildpacks"`
|
|
}
|
|
|
|
type Descriptor struct {
|
|
Project Project `toml:"_"`
|
|
IO IO `toml:"io"`
|
|
}
|
|
|
|
func NewDescriptor(projectTomlContents string) (types.Descriptor, error) {
|
|
versionedDescriptor := &Descriptor{}
|
|
_, err := toml.Decode(projectTomlContents, &versionedDescriptor)
|
|
if err != nil {
|
|
return types.Descriptor{}, err
|
|
}
|
|
|
|
// backward compatibility for incorrect key
|
|
env := versionedDescriptor.IO.Buildpacks.Build.Env
|
|
if env == nil {
|
|
env = versionedDescriptor.IO.Buildpacks.Env.Build
|
|
}
|
|
|
|
return types.Descriptor{
|
|
Project: types.Project{
|
|
ID: versionedDescriptor.Project.ID,
|
|
Name: versionedDescriptor.Project.Name,
|
|
Licenses: versionedDescriptor.Project.Licenses,
|
|
},
|
|
Build: types.Build{
|
|
Include: versionedDescriptor.IO.Buildpacks.Include,
|
|
Exclude: versionedDescriptor.IO.Buildpacks.Exclude,
|
|
Buildpacks: versionedDescriptor.IO.Buildpacks.Group,
|
|
Env: env,
|
|
Builder: versionedDescriptor.IO.Buildpacks.Builder,
|
|
Pre: versionedDescriptor.IO.Buildpacks.Pre,
|
|
Post: versionedDescriptor.IO.Buildpacks.Post,
|
|
},
|
|
Metadata: versionedDescriptor.Project.Metadata,
|
|
SchemaVersion: api.MustParse("0.2"),
|
|
}, nil
|
|
}
|