Skip to content

Commit

Permalink
Do not enforce presence of CNB_STACK_ID
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Pannemans <[email protected]>
Signed-off-by: Johannes Dillmann <[email protected]>
  • Loading branch information
modulo11 and c0d1ngm0nk3y committed Apr 16, 2024
1 parent 46d41fa commit d857d71
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 48 deletions.
6 changes: 3 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ func Build(build BuildFunc, config Config) {
config.logger.Debugf("Buildpack Plan: %+v", ctx.Plan)

if ctx.StackID, ok = os.LookupEnv(EnvStackID); !ok {
config.exitHandler.Error(fmt.Errorf("CNB_STACK_ID not set"))
return
config.logger.Debug("CNB_STACK_ID not set")
} else {
config.logger.Debugf("Stack: %s", ctx.StackID)
}
config.logger.Debugf("Stack: %s", ctx.StackID)

result, err := build(ctx)
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,6 @@ version = "1.1.1"
}
})

it("doesn't receive CNB_STACK_ID", func() {
Expect(os.Unsetenv("CNB_STACK_ID")).To(Succeed())

libcnb.Build(buildFunc,
libcnb.NewConfig(
libcnb.WithArguments([]string{commandPath, layersPath, platformPath, buildpackPlanPath}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithLogger(log.NewDiscard())),
)

Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("CNB_STACK_ID not set"))
})

context("has a build environment", func() {
var ctx libcnb.BuildContext

Expand Down
6 changes: 3 additions & 3 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ func Detect(detect DetectFunc, config Config) {
config.logger.Debugf("Platform Environment: %s", ctx.Platform.Environment)

if ctx.StackID, ok = os.LookupEnv(EnvStackID); !ok {
config.exitHandler.Error(fmt.Errorf("CNB_STACK_ID not set"))
return
config.logger.Debug("CNB_STACK_ID not set")
} else {
config.logger.Debugf("Stack: %s", ctx.StackID)
}
config.logger.Debugf("Stack: %s", ctx.StackID)

result, err := detect(ctx)
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,6 @@ version = "1.1.1"
})
})

it("doesn't receive CNB_STACK_ID", func() {
Expect(os.Unsetenv("CNB_STACK_ID")).To(Succeed())

libcnb.Detect(detectFunc,
libcnb.NewConfig(
libcnb.WithArguments([]string{commandPath, platformPath, buildPlanPath}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithLogger(log.NewDiscard())),
)

Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("CNB_STACK_ID not set"))
})

context("errors if required env vars are not set", func() {
for _, e := range []string{"CNB_PLATFORM_DIR", "CNB_BUILD_PLAN_PATH"} {
// We need to do this assignment because of the way that spec binds variables
Expand Down
6 changes: 3 additions & 3 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func Generate(generate GenerateFunc, config Config) {
config.logger.Debugf("Buildpack Plan: %+v", ctx.Plan)

if ctx.StackID, ok = os.LookupEnv(EnvStackID); !ok {
config.exitHandler.Error(fmt.Errorf("CNB_STACK_ID not set"))
return
config.logger.Debug("CNB_STACK_ID not set")
} else {
config.logger.Debugf("Stack: %s", ctx.StackID)
}
config.logger.Debugf("Stack: %s", ctx.StackID)

result, err := generate(ctx)
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,6 @@ version = "1.1.1"
}
})

it("doesn't receive CNB_STACK_ID", func() {
Expect(os.Unsetenv("CNB_STACK_ID")).To(Succeed())

libcnb.Generate(generateFunc,
libcnb.NewConfig(
libcnb.WithArguments([]string{commandPath, outputPath, platformPath, buildpackPlanPath}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithLogger(log.NewDiscard())),
)

Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("CNB_STACK_ID not set"))
})

context("has a build environment", func() {
var ctx libcnb.GenerateContext

Expand Down

0 comments on commit d857d71

Please sign in to comment.