Skip to content

Commit

Permalink
Merge pull request #42 from paketo-buildpacks/require-spring-native-dep
Browse files Browse the repository at this point in the history
Require users to provide spring-native or spring-graalvm-native dependency
  • Loading branch information
ekcasey authored Jan 11, 2021
2 parents 5dd88b2 + a7b3278 commit fcfb2e4
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 256 deletions.
8 changes: 0 additions & 8 deletions .github/pipeline-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,3 @@ docker_credentials:
- registry: gcr.io
username: _json_key
password: ${{ secrets.JAVA_GCLOUD_SERVICE_ACCOUNT_KEY }}

dependencies:
- id: spring-graalvm-native
uses: docker://ghcr.io/paketo-buildpacks/actions/maven-dependency:main
with:
uri: https://repo.spring.io/milestone
group_id: org.springframework.experimental
artifact_id: spring-graalvm-native
95 changes: 0 additions & 95 deletions .github/workflows/update-spring-graalvm-native.yml

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The buildpack will do the following:

* Creates a GraalVM native image and removes existing bytecode.

This buildpack requires that [Spring Native](https://github.com/spring-projects-experimental/spring-native) is included as an application dependency.

## Configuration
| Environment Variable | Description
| -------------------- | -----------
Expand All @@ -28,3 +30,4 @@ The buildpack optionally accepts the following bindings:
This buildpack is released under version 2.0 of the [Apache License][a].

[a]: http://www.apache.org/licenses/LICENSE-2.0
[s]: https://github.com/spring-projects-experimental/spring-native
12 changes: 0 additions & 12 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ name = "BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS"
description = "the arguments to pass to the native-image command"
build = true

[[metadata.dependencies]]
id = "spring-graalvm-native"
name = "Spring GraalVM Native Feature"
version = "0.8.5"
uri = "https://repo.spring.io/milestone/org/springframework/experimental/spring-graalvm-native/0.8.5/spring-graalvm-native-0.8.5.jar"
sha256 = "70a3a8d264506d1e0d6fe2e05649dbd729d96d7f88fb0fa922de7b824de20e13"
stacks = [ "io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "org.cloudfoundry.stacks.cflinuxfs3" ]

[[metadata.dependencies.licenses]]
type = "Apache-2.0"
uri = "https://github.com/spring-projects-experimental/spring-graal-native/blob/master/LICENSE.txt"

[metadata]
pre-package = "scripts/build.sh"
include-files = [
Expand Down
18 changes: 1 addition & 17 deletions native/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,9 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
return libcnb.BuildResult{}, fmt.Errorf("unable to create configuration resolver\n%w", err)
}

dr, err := libpak.NewDependencyResolver(context)
if err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable to create dependency resolver\n%w", err)
}

dc, err := libpak.NewDependencyCache(context)
if err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable to create dependency cache\n%w", err)
}
dc.Logger = b.Logger

args, _ := cr.Resolve("BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS")

dep, err := dr.Resolve("spring-graalvm-native", "")
if err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable to find dependency\n%w", err)
}

n, err := NewNativeImage(context.Application.Path, args, dep, dc, manifest, context.StackID, result.Plan)
n, err := NewNativeImage(context.Application.Path, args, manifest, context.StackID)
if err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable to create native image layer\n%w", err)
}
Expand Down
33 changes: 8 additions & 25 deletions native/native_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package native

import (
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -26,7 +27,6 @@ import (
"strings"

"github.com/buildpacks/libcnb"
"github.com/heroku/color"
"github.com/magiconair/properties"
"github.com/mattn/go-shellwords"
"github.com/paketo-buildpacks/libpak"
Expand All @@ -39,22 +39,17 @@ import (
type NativeImage struct {
ApplicationPath string
Arguments []string
Dependency libpak.BuildpackDependency
DependencyCache libpak.DependencyCache
Executor effect.Executor
LayerContributor libpak.LayerContributor
Logger bard.Logger
Manifest *properties.Properties
StackID string
}

func NewNativeImage(applicationPath string, arguments string, dependency libpak.BuildpackDependency,
cache libpak.DependencyCache, manifest *properties.Properties, stackID string,
plan *libcnb.BuildpackPlan) (NativeImage, error) {

func NewNativeImage(applicationPath string, arguments string, manifest *properties.Properties, stackID string) (NativeImage, error) {
var err error

expected := map[string]interface{}{"dependency": dependency}
expected := map[string]interface{}{}

expected["arguments"], err = shellwords.Parse(arguments)
if err != nil {
Expand All @@ -69,18 +64,12 @@ func NewNativeImage(applicationPath string, arguments string, dependency libpak.
n := NativeImage{
ApplicationPath: applicationPath,
Arguments: expected["arguments"].([]string),
Dependency: dependency,
DependencyCache: cache,
Executor: effect.NewExecutor(),
LayerContributor: libpak.NewLayerContributor("Native Image", expected),
Manifest: manifest,
StackID: stackID,
}

entry := dependency.AsBuildpackPlanEntry()
entry.Metadata["launch"] = n.Name()
plan.Entries = append(plan.Entries, entry)

return n, nil
}

Expand Down Expand Up @@ -127,15 +116,8 @@ func (n NativeImage) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
cp = append(cp, filepath.Join(n.ApplicationPath, s, l))
}

if !n.hasSpringGraalVMNative(libs) {
n.Logger.Header(color.BlueString("%s %s", n.Dependency.Name, n.Dependency.Version))

artifact, err := n.DependencyCache.Artifact(n.Dependency)
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to get dependency %s\n%w", n.Dependency.ID, err)
}
defer artifact.Close()
cp = append(cp, artifact.Name())
if !n.hasSpringNative(libs) {
return libcnb.Layer{}, errors.New("application is missing required 'spring-native' dependency")
}

arguments := n.Arguments
Expand Down Expand Up @@ -214,8 +196,9 @@ func (NativeImage) Name() string {
return "native-image"
}

func (NativeImage) hasSpringGraalVMNative(libs []string) bool {
re := regexp.MustCompile(`spring-graalvm-native-.+\.jar`)
func (NativeImage) hasSpringNative(libs []string) bool {
// matches either spring-native or legacy spring-graalvm-native
re := regexp.MustCompile(`spring-(?:graalvm-|)native-.+\.jar`)

for _, l := range libs {
if re.MatchString(l) {
Expand Down
Loading

0 comments on commit fcfb2e4

Please sign in to comment.