Skip to content

Commit

Permalink
WIP - trying to handle the environment manually
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed Sep 7, 2022
1 parent 009e016 commit 5f13ba2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
21 changes: 20 additions & 1 deletion pkg/cnb/env_vars.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cnb

import (
"fmt"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -33,5 +34,23 @@ type buildEnvVariable struct {
}

type envBuildVariable struct {
Env []envVariable `toml:"build"`
Env []envVariable
}

func (a *envBuildVariable) UnmarshalTOML(f interface{}) error {
if buildEnv, ok := f.(map[string]interface{}); ok {
if len(buildEnv) == 1 {
// case env.build
if envs, ok := buildEnv["build"].([]map[string]interface{}); ok {
fmt.Println(envs)
}
} else {
// return error
}
}
if envs, ok := f.([]map[string]interface{}); ok {
// case env
fmt.Println(envs)
}
return nil
}
3 changes: 2 additions & 1 deletion pkg/cnb/project_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func parseProjectDescriptor(file string, logger *log.Logger) (descriptorV2, erro
var d descriptorV2
if _, err := toml.DecodeFile(file, &d); err != nil {
var dV2NoSpec descriptorV2NoSpec
if _, err2 := toml.DecodeFile(file, &dV2NoSpec); err2 != nil {
data, err := os.ReadFile(file)
if err2 := toml.Unmarshal(data, &dV2NoSpec); err2 != nil {
logger.Println(fmt.Sprintf("warning: project descriptor '%s' could not be parsed, error '%v'", file, err))
return descriptorV2{}, err2
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cnb/project_descriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ value = "valueC"
# check that later keys override previous ones
[[io.buildpacks.env]]
name = "keyC"
value = "valueAnotherC"
`), 0644)
value = "valueAnotherC"`), 0644)
})
it("writes all env var files to the platform dir", func() {
assert.Nil(t, cnb.ProcessProjectDescriptor(appDir, descriptorPath, platformDir, logger))
Expand Down

0 comments on commit 5f13ba2

Please sign in to comment.