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 19, 2024
1 parent 7f587a1 commit c0e4498
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 31 deletions.
6 changes: 3 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ func Build(builder Builder, options ...Option) {
logger.Debugf("Buildpack Plan: %+v", ctx.Plan)

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

result, err := builder.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 @@ -256,19 +256,6 @@ version = "1.1.1"
Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("expected 3 arguments and received 0"))
})

it("doesn't receive CNB_STACK_ID", func() {
Expect(os.Unsetenv("CNB_STACK_ID")).To(Succeed())
builder.On("Build", mock.Anything).Return(libcnb.NewBuildResult(), nil)

libcnb.Build(builder,
libcnb.WithBOMLabel(true),
libcnb.WithArguments([]string{commandPath, layersPath, platformPath, buildpackPlanPath}),
libcnb.WithExitHandler(exitHandler),
)

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

context("when BP API >= 0.8", func() {
it.Before(func() {
Expect(os.WriteFile(filepath.Join(buildpackPath, "buildpack.toml"),
Expand Down
6 changes: 3 additions & 3 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ func Detect(detector Detector, options ...Option) {
logger.Debugf("Platform Environment: %s", ctx.Platform.Environment)

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

result, err := detector.Detect(ctx)
if err != nil {
Expand Down
12 changes: 0 additions & 12 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ version = "1.1.1"
Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("expected 2 arguments and received 0"))
})

it("doesn't receive CNB_STACK_ID", func() {
Expect(os.Unsetenv("CNB_STACK_ID")).To(Succeed())
detector.On("Detect", mock.Anything).Return(libcnb.DetectResult{}, nil)

libcnb.Detect(detector,
libcnb.WithArguments([]string{commandPath, platformPath, buildPlanPath}),
libcnb.WithExitHandler(exitHandler),
)

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

context("errors if required env vars are not set for buildpack API >=0.8", 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

0 comments on commit c0e4498

Please sign in to comment.