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

Maven dep #185

Merged
merged 8 commits into from
Sep 20, 2022
Merged

Maven dep #185

merged 8 commits into from
Sep 20, 2022

Conversation

dmikusa
Copy link
Contributor

@dmikusa dmikusa commented Sep 17, 2022

Summary

Changes to Detection:

  1. By default, we now pass
  2. By default, we provide three possible plans all of which only provide (one provides just maven, one provides just a built app, one provides maven and a built app)
  3. If a pom.xml file exists, then we add a requires (jdk, syft, maven).

Changes to Build:

Based on what is in the buildplan, the buildpack can now optionally install and optionally build.

If maven is in the buildplan, then the buildpack will attempt to install or validate that Maven is installed and generate a command to run Maven.

This can be done in four ways:

  1. Install Maven Daemon
  2. Install Maven
  3. Validate Maven Wrapper
  4. Validate Maven on $PATH

If jvm-application-package is in the buildplan, then the buildpack will attempt to perform a build with Maven. This uses the command from the previously installed or validated Maven.

Use Cases

This enables four scenarios:

  1. The buildpack installs & runs Maven (or Maven Daemon)
  2. The buildpack runs Maven w/Maven Wrapper
  3. The buildpack just installs Maven (or Maven Daemon)
  4. The buildpack doesn't install Maven or use Maven Wrapper, but just runs Maven (Maven is provided through other means)

For 1.) & 2.) are the classic cases we've been supporting.
For 3.) & 4.) are the new cases that have been requested.

Resolves #159
Resolves #184

1. By default, we now pass
2. By default, we provide three possible plans all of which only provide (one provides just maven, one provides just a built app, one provides maven and a built app)
3. If a pom.xml file exists, then we add a requires (jdk, syft, maven).

This enables more scenarios:

1. All we do is install Maven. In this case, the build plan will provide maven and some other build pack will need to require it.
2. All we do is build with Maven. In this case, something else needs to provide maven & jdk.
3. Both install and build with Maven. This the classic case that we've been supporting.

Signed-off-by: Daniel Mikusa <[email protected]>
Based on what is in the buildplan, the buildpack can now optionally install and optionally build.

If `maven` is in the buildplan, then the buildpack will attempt to install or validate that Maven is installed and generate a command to run Maven.

This comes in four forms:

1. Install Maven Daemon
2. Install Maven
3. Validate Maven Wrapper
4. Validate Maven on $PATH

If `jvm-application-package` is in the buildplan, then the buildpack will attempt to perform a build with Maven. This uses the command from the previously installed or validated Maven.

This enables four scenarios:

1. The buildpack installs & runs Maven (or Maven Daemon)
2. The buildpack runs Maven w/Maven Wrapper
2. The buildpack just installs Maven (or Maven Daemon)
3. The buildpack doesn't install Maven or use Maven Wrapper, but just runs Maven (Maven is provided through other means)

Signed-off-by: Daniel Mikusa <[email protected]>
@dmikusa dmikusa added semver:minor A change requiring a minor version bump type:enhancement A general enhancement labels Sep 17, 2022
@dmikusa dmikusa requested a review from a team September 17, 2022 03:58
@dmikusa
Copy link
Contributor Author

dmikusa commented Sep 17, 2022

@AidanDelaney - FYI

@AidanDelaney
Copy link

This looks really good. The maven_manager abstraction feels like the right separation of concerns.

@AidanDelaney AidanDelaney mentioned this pull request Sep 17, 2022
5 tasks
@pivotal-david-osullivan
Copy link
Contributor

By default, we provide three possible plans all of which only provide

Don't we always still require a JDK?

& 2. are the classic cases we've been supporting. -- & 4. are the new cases that have been requested.

I think auto numbering messed these points up, not a big deal but it's a very useful summary so good to have it correct if so

@dmikusa
Copy link
Contributor Author

dmikusa commented Sep 20, 2022

By default, we provide three possible plans all of which only provide

Don't we always still require a JDK?

Right now, we contribute three plans always:

  1. Provides maven + Requires jdk
  2. Provides jvm-application-package
  3. Provides jvm-application-package + Provides maven.

The thought is that for the first option, some other buildpack would need to require Maven. Thus, we require jdk so the other buildpack doesn't need to do that.

For two and three, the thought is that you need a pom.xml file & when a pom.xml is found, we automatically require jdk, syft and maven for those build plans. My understanding is that with build plans, the first one that matches will be picked so if a builder extension requires jvm-application-package and also meets the jdk, syft and maven requirements then it would get picked first. If not, then the default buildack option would be pick (i.e. option three, install & build).

Does that sound good?

& 2. are the classic cases we've been supporting. -- & 4. are the new cases that have been requested.

I think auto numbering messed these points up, not a big deal but it's a very useful summary so good to have it correct if so

Fixed.

- Added a case for default pom.xml location as well as a custom location when the file does not exist
- Fixed descriptions & added context for additional grouping

Signed-off-by: Daniel Mikusa <[email protected]>
@pivotal-david-osullivan
Copy link
Contributor

Yes it makes sense 👍

My first point wasn't very clear, I just meant to clarify whether plan 1 makes this wording untrue: 'all of which only provide' since there is always a Requires for #1.

Looks good though and the extra tests make the scenarios easier to follow now 🎉

@dmikusa dmikusa merged commit db3476d into main Sep 20, 2022
@dmikusa dmikusa deleted the maven-dep branch September 20, 2022 16:43
@pbusko
Copy link

pbusko commented Sep 26, 2022

@dmikusa this change broke the pipelines on our end due to the fact that the maven buildpack now detects always, without requiring JDK to be installed. We're building images from a pre-compiled jar file, and now we get the following error with the lates version of java buildpack:

Note: the build succeeds when using gcr.io/paketo-buildpacks/java:7.3.0

$ pack build --builder paketobuildpacks/builder:base --buildpack gcr.io/paketo-buildpacks/java:latest --path target/demo-1.0.0.jar test-image
Previous image with name "test-image" not found
===> DETECTING
7 of 24 buildpacks participating
paketo-buildpacks/ca-certificates   3.4.0
paketo-buildpacks/bellsoft-liberica 9.7.0
paketo-buildpacks/syft              1.20.0
paketo-buildpacks/maven             6.9.0
paketo-buildpacks/executable-jar    6.5.0
paketo-buildpacks/dist-zip          5.4.0
paketo-buildpacks/spring-boot       5.19.0
===> RESTORING
===> BUILDING

Paketo Buildpack for CA Certificates 3.4.0
  https://github.com/paketo-buildpacks/ca-certificates
  Launch Helper: Contributing to layer
    Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper

Paketo Buildpack for BellSoft Liberica 9.7.0
  https://github.com/paketo-buildpacks/bellsoft-liberica
  Build Configuration:
    $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
    $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
    $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
    $BP_JVM_VERSION              11                                                           the Java version
  Launch Configuration:
    $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
    $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
    $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
    $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
    $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
    $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
    $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
    $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
    $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
    $BPL_JMX_PORT                5000                                                         configure the JMX port
    $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
    $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
    $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
    $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
    Using Java version 11 extracted from MANIFEST.MF
  BellSoft Liberica JRE 11.0.16: Contributing to layer
    Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16.1+1/bellsoft-jre11.0.16.1+1-linux-amd64.tar.gz
    Verifying checksum
    Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jre
    Adding 127 container CA certificates to JVM truststore
    Writing env.launch/BPI_APPLICATION_PATH.default
    Writing env.launch/BPI_JVM_CACERTS.default
    Writing env.launch/BPI_JVM_CLASS_COUNT.default
    Writing env.launch/BPI_JVM_SECURITY_PROVIDERS.default
    Writing env.launch/JAVA_HOME.default
    Writing env.launch/JAVA_TOOL_OPTIONS.append
    Writing env.launch/JAVA_TOOL_OPTIONS.delim
    Writing env.launch/MALLOC_ARENA_MAX.default
  Launch Helper: Contributing to layer
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/active-processor-count
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/java-opts
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jvm-heap
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/link-local-dns
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/memory-calculator
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-configurer
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jmx
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jfr
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-classpath-9
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/debug-9
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/nmt
    Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/openssl-certificate-loader
  Java Security Properties: Contributing to layer
    Writing env.launch/JAVA_SECURITY_PROPERTIES.default
    Writing env.launch/JAVA_TOOL_OPTIONS.append
    Writing env.launch/JAVA_TOOL_OPTIONS.delim

Paketo Buildpack for Syft 1.20.0
  https://github.com/paketo-buildpacks/syft
    Downloading from https://github.com/anchore/syft/releases/download/v0.57.0/syft_0.57.0_linux_amd64.tar.gz
    Verifying checksum
    Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default

Paketo Buildpack for Maven 6.9.0
  https://github.com/paketo-buildpacks/maven
  Build Configuration:
    $BP_MAVEN_BUILD_ARGUMENTS  -Dmaven.test.skip=true --no-transfer-progress package  the arguments to pass to Maven
    $BP_MAVEN_BUILT_ARTIFACT   target/*.[ejw]ar                                       the built application artifact explicitly.  Supersedes $BP_MAVEN_BUILT_MODULE
    $BP_MAVEN_BUILT_MODULE                                                            the module to find application artifact in
    $BP_MAVEN_DAEMON_ENABLED   false                                                  use maven daemon
    $BP_MAVEN_POM_FILE         pom.xml                                                the location of the main pom.xml file, relative to the application root
    $BP_MAVEN_SETTINGS_PATH                                                           the path to a Maven settings file

Paketo Buildpack for Maven 6.9.0
  unable to create application layer
  failed to generate expected metadata
  unable to determine java version
  error executing 'javac -version':
   Combined Output: :
  unable to start PTY
  exec: "javac": executable file not found in $PATH
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 51

@dmikusa
Copy link
Contributor Author

dmikusa commented Sep 26, 2022

Thanks for the report. I thought we'd accounted for that case, but clearly not. We're going to roll this back temporarily. We need to add a bit more logic to the detect.

dmikusa added a commit that referenced this pull request Sep 27, 2022
PR [#185](#185) had an issue which caused problems when building from a WAR/JAR file. This PR adjusts the detection logic so that it'll work with WAR/JAR files as well as building from source.

Signed-off-by: Daniel Mikusa <[email protected]>
@dmikusa
Copy link
Contributor Author

dmikusa commented Sep 27, 2022

@pbusko Sorry for the issue, I have PR #189 which should correct this.

If you have a minute to test & give us some feedback, I have a docker image up with this fix. pack build <app-image> --buildpack dmikusa/paketo-java. That'll pull from Docker Hub, it's a build of the standard Paketo Java buildpack but with an advanced build including PR #189.

If you're using Spring Boot:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layers>
                        <enabled>true</enabled>
                    </layers>
                    <image>
                        <name>apps/maven</name>
                        <buildpacks>
                            <buildpack>dmikusa/paketo-java</buildpack>
                        </buildpacks>
                    </image>
                </configuration>
            </plugin>

or the similar setting for Maven.

@pbusko
Copy link

pbusko commented Sep 29, 2022

@dmikusa sorry for late reply, I can confirm that when using dmikusa/paketo-java buildpack, the issue no longer occurs. Maven buildpack doesn't detect anymore.

@dmikusa
Copy link
Contributor Author

dmikusa commented Sep 29, 2022

Excellent! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:minor A change requiring a minor version bump type:enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document Include/Exclude files Support distribution of binaries
4 participants