Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto detect native image #258

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Most users should not use this component buildpack directly and should instead u
This buildpack will participate if one the following conditions are met:

* `$BP_NATIVE_IMAGE` is set.
* An upstream buildpack requests `native-image-application` in the build plan.
* An upstream buildpack requests `native-image-application` in the build plan.
* An upstream buildpack provides `native-processed` in the build plan.

The buildpack will do the following:

Expand Down
33 changes: 30 additions & 3 deletions native/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
BinaryCompressionMethod = "BP_BINARY_COMPRESSION_METHOD"

PlanEntryNativeImage = "native-image-application"
PlanEntryNativeProcessed = "native-processed"
PlanEntryNativeImageBuilder = "native-image-builder"
PlanEntryJVMApplication = "jvm-application"
PlanEntrySpringBoot = "spring-boot"
Expand Down Expand Up @@ -69,6 +70,24 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{
Name: PlanEntryNativeImage,
},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: PlanEntryNativeImageBuilder,
},
{
Name: PlanEntryNativeProcessed,
},
{
Name: PlanEntryNativeImage,
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{
Expand All @@ -93,9 +112,17 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
return libcnb.DetectResult{}, err
} else if ok {
for i := range result.Plans {
result.Plans[i].Requires = append(result.Plans[i].Requires, libcnb.BuildPlanRequire{
Name: PlanEntryNativeImage,
})
found := false
for _, r := range result.Plans[i].Requires {
if r.Name == PlanEntryNativeImage {
found = true
}
}
if !found {
result.Plans[i].Requires = append(result.Plans[i].Requires, libcnb.BuildPlanRequire{
Name: PlanEntryNativeImage,
})
}
}
}

Expand Down
131 changes: 131 additions & 0 deletions native/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -112,6 +128,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -165,6 +197,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -246,6 +294,25 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
{
Name: "upx",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -305,6 +372,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -361,6 +444,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -417,6 +516,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down Expand Up @@ -474,6 +589,22 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "native-processed",
},
{
Name: "native-image-application",
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
Expand Down